Newer
Older
from pathlib import Path
import nox
DIR = Path(__file__).parent.resolve()
@nox.session(venv_backend="none")
def pre_commit(session: nox.Session) -> None:
"""
Run pre-commit
"""
if "pre_commit" in sys.argv:
session.run("pre-commit", "run", "--all-files")
@nox.session(venv_backend="none")
def dev(session: nox.Session) -> None:
"""
Prepare a .venv folder.
"""
session.run(sys.executable, "-m", "venv", ".venv")
session.run(
".venv/bin/pip",
"install",
"scikit-build-core[pyproject]",
"pybind11",
"pip>=23",
)
session.run(
".venv/bin/pip",
"install",
"--no-build-isolation",
"--check-build-dependencies",
"-ve.",
"-C",
"cmake.define.CMAKE_EXPORT_COMPILE_COMMANDS=1",
"-C",
"build-dir=build",
)
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@nox.session(reuse_venv=True)
def rr_run(session: nox.Session) -> None:
"""
Run sp-repo-review.
"""
session.install("sp-repo-review[cli]")
session.run("repo-review", ".")
# @nox.session
# def rr_lint(session: nox.Session) -> None:
# """
# Run the linter.
# """
# session.install("pre-commit")
# session.run("pre-commit", "run", "--all-files", *session.posargs)
@nox.session
def rr_pylint(session: nox.Session) -> None:
"""
Run PyLint.
"""
# This needs to be installed into the package environment, and is slower
# than a pre-commit check
session.install("-e.")
session.install("pylint>=3.2")
session.run("pylint", "myproj.simulation", *session.posargs)
# @nox.session
# def rr_tests(session: nox.Session) -> None:
# """
# Run the unit and regular tests for sp-repo-review.
# """
# session.install("-e.[test,cli]")
# session.run("pytest", *session.posargs, env={"PYTHONWARNDEFAULTENCODING": "1"})
# @nox.session(reuse_venv=True)
# def rr_build(session: nox.Session) -> None:
# """
# Build an SDist and wheel for sp-repo-review.
# """
# build_p = DIR.joinpath("build")
# if build_p.exists():
# shutil.rmtree(build_p)
# session.install("build")
# session.run("python", "-m", "build")
@nox.session
def build_extension(session: nox.Session) -> None:
# Install build dependencies
session.install(
"pybind11", "scikit-build", "setuptools", "wheel", "pybind11-stubgen"
)
# Build the extension module using scikit-build
session.run("python", "-m", "pip", "install", ".", "--no-build-isolation")
# Generate the .pyi file using pybind11-stubgen
# Replace 'your_package._hello' with the actual module name
session.run("pybind11-stubgen", "your_package._hello")
# Move the generated .pyi file to the source directory
# By default, pybind11-stubgen outputs to 'stubs/your_package/_hello/__init__.pyi'
stub_src = (
Path("stubs") / "myproj" / "simulation" / "_csrc" / "_hello" / "__init__.pyi"
)
stub_dest = Path("myproj") / "simulation" / "_csrc" / "_hello.pyi"
session.run("mv", stub_src, stub_dest, external=True)
# Clean up the stubs directory
session.run("rm", "-r", "stubs", external=True)