1111MODULE_NAME = "module_name"
1212TESTS_PATH = "tests"
1313COVERAGE_FAIL_UNDER = 50
14- DEFAULT_PYTHON_VERSION = "3.12"
14+ DEFAULT_PYTHON = "3.12"
1515PYTHON_MATRIX = ["3.9" , "3.10" , "3.11" , "3.12" , "3.13" ]
1616VENV_BACKEND = "venv"
1717VENV_PATH = ".venv"
18- REQUIREMENT_IN_FILES = [
19- pathlib .Path ("requirements/requirements.in" ),
20- ]
18+ REQUIREMENTS_PATH = "./requirements"
2119
2220# What we allowed to clean (delete)
2321CLEANABLE_TARGETS = [
4341]
4442
4543
44+ @nox .session (python = False )
45+ def dev (session : nox .Session ) -> None :
46+ """Setup a development environment by creating the venv and installs dependencies."""
47+ # Use the active environement if it exists, otherwise create a new one
48+ venv_path = os .environ .get ("VIRTUAL_ENV" , VENV_PATH )
49+
50+ if sys .platform == "win32" :
51+ py_command = "py"
52+ venv_path = f"{ venv_path } /Scripts"
53+ activate_command = f"{ venv_path } /activate"
54+ else :
55+ py_command = f"python{ DEFAULT_PYTHON } "
56+ venv_path = f"{ venv_path } /bin"
57+ activate_command = f"source { venv_path } /activate"
58+
59+ if not os .path .exists (VENV_PATH ):
60+ session .run (py_command , "-m" , "venv" , VENV_PATH , "--upgrade-deps" )
61+
62+ python = f"{ venv_path } /python"
63+ requirement_files = get_requirement_files ()
64+
65+ session .run (python , "-m" , "pip" , "install" , "-e" , "." )
66+ for requirement_file in requirement_files :
67+ session .run (python , "-m" , "pip" , "install" , "-r" , requirement_file )
68+
69+ session .run (python , "-m" , "pip" , "install" , "pre-commit" )
70+ session .run (f"{ venv_path } /pre-commit" , "install" )
71+
72+ if not os .environ .get ("VIRTUAL_ENV" ):
73+ session .log (f"\n \n Run '{ activate_command } ' to enter the virtual environment.\n " )
74+
75+
4676@nox .session (python = PYTHON_MATRIX , venv_backend = VENV_BACKEND )
4777def version_coverage (session : nox .Session ) -> None :
4878 """Run unit tests with coverage saved to partial file."""
@@ -52,7 +82,7 @@ def version_coverage(session: nox.Session) -> None:
5282 session .run ("coverage" , "run" , "-p" , "-m" , "pytest" , TESTS_PATH )
5383
5484
55- @nox .session (python = DEFAULT_PYTHON_VERSION , venv_backend = VENV_BACKEND )
85+ @nox .session (python = DEFAULT_PYTHON , venv_backend = VENV_BACKEND )
5686def coverage_combine (session : nox .Session ) -> None :
5787 """Combine all coverage partial files and generate JSON report."""
5888 print_standard_logs (session )
@@ -65,7 +95,7 @@ def coverage_combine(session: nox.Session) -> None:
6595 session .run ("python" , "-m" , "coverage" , "json" )
6696
6797
68- @nox .session (python = DEFAULT_PYTHON_VERSION , venv_backend = VENV_BACKEND )
98+ @nox .session (python = DEFAULT_PYTHON , venv_backend = VENV_BACKEND )
6999def mypy (session : nox .Session ) -> None :
70100 """Run mypy against package and all required dependencies."""
71101 print_standard_logs (session )
@@ -83,7 +113,7 @@ def coverage(session: nox.Session) -> None:
83113 session .run ("coverage" , "report" , "-m" )
84114
85115
86- @nox .session (python = DEFAULT_PYTHON_VERSION , venv_backend = VENV_BACKEND )
116+ @nox .session (python = DEFAULT_PYTHON , venv_backend = VENV_BACKEND )
87117def build (session : nox .Session ) -> None :
88118 """Build distribution files."""
89119 print_standard_logs (session )
@@ -92,49 +122,41 @@ def build(session: nox.Session) -> None:
92122 session .run ("python" , "-m" , "build" )
93123
94124
95- @nox .session (python = False , venv_backend = VENV_BACKEND )
96- def install (session : nox .Session ) -> None :
97- """Setup a development environment. Uses active venv if available, builds one if not."""
98- # Use the active environement if it exists, otherwise create a new one
99- venv_path = os .environ .get ("VIRTUAL_ENV" , VENV_PATH )
100-
101- if sys .platform == "win32" :
102- py_command = "py"
103- venv_path = f"{ venv_path } /Scripts"
104- activate_command = f"{ venv_path } /activate"
105- else :
106- py_command = f"python{ DEFAULT_PYTHON_VERSION } "
107- venv_path = f"{ venv_path } /bin"
108- activate_command = f"source { venv_path } /activate"
109-
110- if not os .path .exists (VENV_PATH ):
111- session .run (py_command , "-m" , "venv" , VENV_PATH , "--upgrade-deps" )
112-
113- session .run (f"{ venv_path } /python" , "-m" , "pip" , "install" , "-e" , ".[dev,test]" )
114- session .run (f"{ venv_path } /pre-commit" , "install" )
115-
116- if not venv_path :
117- session .log (f"\n \n Run '{ activate_command } ' to enter the virtual environment.\n " )
118-
119-
120- @nox .session (python = DEFAULT_PYTHON_VERSION , venv_backend = VENV_BACKEND )
121- def update (session : nox .Session ) -> None :
122- """Process requirement*.in files, updating only additions/removals."""
125+ @nox .session (python = DEFAULT_PYTHON , venv_backend = VENV_BACKEND , name = "update-deps" )
126+ def update_deps (session : nox .Session ) -> None :
127+ """Process requirement*.txt files, updating only additions/removals."""
123128 print_standard_logs (session )
124129
125- session .install ("pip-tools" )
126- for filename in REQUIREMENT_IN_FILES :
127- session .run ("pip-compile" , "--no-emit-index-url" , str (filename ))
128-
130+ requirement_files = get_requirement_files ()
129131
130- @nox .session (python = DEFAULT_PYTHON_VERSION , venv_backend = VENV_BACKEND )
131- def upgrade (session : nox .Session ) -> None :
132- """Process requirement*.in files and upgrade all libraries as possible."""
132+ session .install ("pip-tools" )
133+ session .run (
134+ "pip-compile" ,
135+ "--no-annotate" ,
136+ "--no-emit-index-url" ,
137+ "--output-file" ,
138+ f"{ REQUIREMENTS_PATH } /constraints.txt" ,
139+ * requirement_files ,
140+ )
141+
142+
143+ @nox .session (python = DEFAULT_PYTHON , venv_backend = VENV_BACKEND , name = "upgrade-deps" )
144+ def upgrade_deps (session : nox .Session ) -> None :
145+ """Process requirement*.txt files and upgrade all libraries as possible."""
133146 print_standard_logs (session )
134147
148+ requirement_files = get_requirement_files ()
149+
135150 session .install ("pip-tools" )
136- for filename in REQUIREMENT_IN_FILES :
137- session .run ("pip-compile" , "--no-emit-index-url" , "--upgrade" , str (filename ))
151+ session .run (
152+ "pip-compile" ,
153+ "--no-annotate" ,
154+ "--no-emit-index-url" ,
155+ "--upgrade" ,
156+ "--output-file" ,
157+ f"{ REQUIREMENTS_PATH } /constraints.txt" ,
158+ * requirement_files ,
159+ )
138160
139161
140162@nox .session (python = False , venv_backend = VENV_BACKEND )
@@ -157,3 +179,9 @@ def print_standard_logs(session: nox.Session) -> None:
157179 version = session .run ("python" , "--version" , silent = True )
158180 session .log (f"Running from: { session .bin } " )
159181 session .log (f"Running with: { version } " )
182+
183+
184+ def get_requirement_files () -> list [pathlib .Path ]:
185+ """Get a list of requirement files matching "requirements*.txt"."""
186+ glob = pathlib .Path (REQUIREMENTS_PATH ).glob ("requirements*.txt" )
187+ return [path for path in glob ]
0 commit comments