|
6 | 6 | import sys
|
7 | 7 | from contextlib import contextmanager
|
8 | 8 | from pathlib import Path
|
9 |
| -from typing import Any, Mapping |
| 9 | +from typing import Any, Callable, Mapping |
10 | 10 |
|
11 | 11 | import nox
|
12 | 12 |
|
@@ -104,7 +104,7 @@ def test_copier(session: nox.Session):
|
104 | 104 | template_repo = Path("submodules/hexdoc-hexcasting-template")
|
105 | 105 | rendered_template = template_repo / ".ctt" / "test_copier"
|
106 | 106 |
|
107 |
| - shutil.rmtree(rendered_template, ignore_errors=True) |
| 107 | + rmtree(session, rendered_template, ignore_errors=True) |
108 | 108 | session.run("ctt", "--base-dir", str(template_repo))
|
109 | 109 | session.run("git", "init", str(rendered_template), external=True)
|
110 | 110 |
|
@@ -197,6 +197,29 @@ def tag(session: nox.Session):
|
197 | 197 | # development helpers
|
198 | 198 |
|
199 | 199 |
|
| 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 | + |
200 | 223 | @nox.session
|
201 | 224 | def hexdoc(session: nox.Session):
|
202 | 225 | session.install("-e", ".")
|
@@ -516,9 +539,7 @@ def dummy_serve(session: nox.Session):
|
516 | 539 |
|
517 | 540 | @nox.session(python=False)
|
518 | 541 | 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) |
522 | 543 |
|
523 | 544 |
|
524 | 545 | # utils (not sessions)
|
@@ -567,13 +588,24 @@ def update_git_tag(session: nox.Session, *, tag: str, message: str):
|
567 | 588 | )
|
568 | 589 |
|
569 | 590 |
|
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): |
571 | 592 | # from: https://stackoverflow.com/questions/4829043/how-to-remove-read-only-attrib-directory-with-python-in-windows
|
572 | 593 | path_ = Path(path)
|
573 | 594 | path_.chmod(stat.S_IWRITE)
|
574 | 595 | path_.unlink()
|
575 | 596 |
|
576 | 597 |
|
| 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 | + |
577 | 609 | def get_hexdoc_version():
|
578 | 610 | with prepend_sys_path("src"):
|
579 | 611 | from hexdoc.__version__ import VERSION
|
|
0 commit comments