Skip to content

Commit cea1502

Browse files
committed
Add setup session for convenience
1 parent b8f02ba commit cea1502

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ See [hexdoc-hexcasting-template](https://github.com/hexdoc-dev/hexdoc-hexcasting
3030

3131
### Setup
3232

33+
Automatically set up a development environment with Nox:
34+
35+
```sh
36+
pipx install nox # pipx (recommended)
37+
python3 -m pip install nox # pip
38+
39+
nox -s setup
40+
# next, run the venv activation command printed by uv
41+
```
42+
43+
Manual setup:
44+
3345
```sh
3446
git submodule update --init
3547

noxfile.py

+38-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
from contextlib import contextmanager
88
from pathlib import Path
9-
from typing import Any, Mapping
9+
from typing import Any, Callable, Mapping
1010

1111
import nox
1212

@@ -104,7 +104,7 @@ def test_copier(session: nox.Session):
104104
template_repo = Path("submodules/hexdoc-hexcasting-template")
105105
rendered_template = template_repo / ".ctt" / "test_copier"
106106

107-
shutil.rmtree(rendered_template, ignore_errors=True)
107+
rmtree(session, rendered_template, ignore_errors=True)
108108
session.run("ctt", "--base-dir", str(template_repo))
109109
session.run("git", "init", str(rendered_template), external=True)
110110

@@ -197,6 +197,29 @@ def tag(session: nox.Session):
197197
# development helpers
198198

199199

200+
@nox.session
201+
def setup(session: nox.Session):
202+
session.install("uv", "pre-commit")
203+
204+
if not Path("submodules/HexMod/pyproject.toml").exists():
205+
session.run("git", "submodule", "update", "--init")
206+
207+
rmtree(session, "venv", onerror=on_rm_error)
208+
session.run("uv", "venv", "venv", "--seed")
209+
210+
session.run(
211+
*("uv", "pip", "install"),
212+
"--quiet",
213+
"-e=.[dev]",
214+
"-e=./submodules/HexMod",
215+
env={
216+
"VIRTUAL_ENV": str(Path.cwd() / "venv"),
217+
},
218+
)
219+
220+
session.run("pre-commit", "install")
221+
222+
200223
@nox.session
201224
def hexdoc(session: nox.Session):
202225
session.install("-e", ".")
@@ -516,9 +539,7 @@ def dummy_serve(session: nox.Session):
516539

517540
@nox.session(python=False)
518541
def dummy_clean(session: nox.Session):
519-
if DUMMY_PATH.is_dir():
520-
session.log(f"Removing directory: {DUMMY_PATH}")
521-
shutil.rmtree(DUMMY_PATH, onerror=on_rm_error)
542+
rmtree(session, DUMMY_PATH)
522543

523544

524545
# utils (not sessions)
@@ -567,13 +588,24 @@ def update_git_tag(session: nox.Session, *, tag: str, message: str):
567588
)
568589

569590

570-
def on_rm_error(func: Any, path: str, exc_info: Any):
591+
def on_rm_error(func: Callable[..., Any], path: str, exc_info: Any):
571592
# from: https://stackoverflow.com/questions/4829043/how-to-remove-read-only-attrib-directory-with-python-in-windows
572593
path_ = Path(path)
573594
path_.chmod(stat.S_IWRITE)
574595
path_.unlink()
575596

576597

598+
def rmtree(
599+
session: nox.Session,
600+
path: str | Path,
601+
ignore_errors: bool = False,
602+
onerror: Callable[[Callable[..., Any], str, Any], object] | None = on_rm_error,
603+
):
604+
if Path(path).is_dir():
605+
session.log(f"Removing directory: {path}")
606+
shutil.rmtree(path, ignore_errors, onerror)
607+
608+
577609
def get_hexdoc_version():
578610
with prepend_sys_path("src"):
579611
from hexdoc.__version__ import VERSION

0 commit comments

Comments
 (0)