22
33import glob
44import os
5+ import sys
56
67import nox
78
89nox .options .reuse_existing_virtualenvs = True
910nox .options .error_on_external_run = True
1011
11- nox .needs_version = ">=2024.3.2 "
12- nox .options .default_venv_backend = "uv|virtualenv "
12+ nox .needs_version = ">=2024.04.15 "
13+ nox .options .default_venv_backend = "uv"
1314
14- nox .options .sessions = "lint" , "tests"
15+ nox .options .sessions = "lint" , "tests" , "type-checking" , "type-safety"
1516locations = ("upath" ,)
1617running_in_ci = os .environ .get ("CI" , "" ) != ""
1718
19+ SUPPORTED_PYTHONS = ["3.9" , "3.10" , "3.11" , "3.12" , "3.13" , "3.14" ]
20+ BASE_PYTHON = SUPPORTED_PYTHONS [- 3 ]
21+ MIN_PYTHON = SUPPORTED_PYTHONS [0 ]
22+
23+
24+ @(lambda f : f ())
25+ def FSSPEC_MIN_VERSION () -> str :
26+ """Get the minimum fsspec version boundary from pyproject.toml."""
27+ try :
28+ from packaging .requirements import Requirement
29+
30+ if sys .version_info >= (3 , 11 ):
31+ from tomllib import load as toml_load
32+ else :
33+ from tomli import load as toml_load
34+ except ImportError :
35+ raise RuntimeError (
36+ "We rely on nox>=2024.04.15 depending on `packaging` and `tomli/tomllib`."
37+ " Please report if you see this error."
38+ )
39+
40+ with open ("pyproject.toml" , "rb" ) as f :
41+ pyproject_data = toml_load (f )
42+
43+ for requirement in pyproject_data ["project" ]["dependencies" ]:
44+ req = Requirement (requirement )
45+ if req .name == "fsspec" :
46+ for specifier in req .specifier :
47+ if specifier .operator == ">=" :
48+ return str (specifier .version )
49+ raise RuntimeError ("Could not find fsspec minimum version in pyproject.toml" )
50+
1851
19- @nox .session (python = [ "3.9" , "3.10" , "3.11" , "3.12" , "3.13" , "3.14" ] )
52+ @nox .session (python = SUPPORTED_PYTHONS )
2053def tests (session : nox .Session ) -> None :
54+ """Run the test suite."""
2155 # workaround in case no aiohttp binary wheels are available
2256 if session .python == "3.14" :
2357 session .env ["AIOHTTP_NO_EXTENSIONS" ] = "1"
@@ -36,9 +70,9 @@ def tests(session: nox.Session) -> None:
3670 )
3771
3872
39- @nox .session (python = "3.9" , name = "tests-minversion" )
73+ @nox .session (python = MIN_PYTHON , name = "tests-minversion" )
4074def tests_minversion (session : nox .Session ) -> None :
41- session .install ("fsspec==2024.5.0 " , ".[tests,dev]" )
75+ session .install (f "fsspec=={ FSSPEC_MIN_VERSION } " , ".[tests,dev]" )
4276 session .run ("uv" , "pip" , "freeze" , silent = not running_in_ci )
4377 session .run (
4478 "pytest" ,
@@ -51,8 +85,12 @@ def tests_minversion(session: nox.Session) -> None:
5185 )
5286
5387
88+ tests_minversion .__doc__ = f"Run the test suite with fsspec=={ FSSPEC_MIN_VERSION } ."
89+
90+
5491@nox .session
5592def lint (session : nox .Session ) -> None :
93+ """Run pre-commit hooks."""
5694 session .install ("pre-commit" )
5795 session .install ("-e" , ".[tests]" )
5896
@@ -70,6 +108,7 @@ def safety(session: nox.Session) -> None:
70108
71109@nox .session
72110def build (session : nox .Session ) -> None :
111+ """Build sdists and wheels."""
73112 session .install ("build" , "setuptools" , "twine" )
74113 session .run ("python" , "-m" , "build" )
75114 dists = glob .glob ("dist/*" )
@@ -79,31 +118,19 @@ def build(session: nox.Session) -> None:
79118@nox .session
80119def develop (session : nox .Session ) -> None :
81120 """Sets up a python development environment for the project."""
82- args = session .posargs or ("venv" ,)
83- venv_dir = os .fsdecode (os .path .abspath (args [0 ]))
84-
85- session .log (f"Setting up virtual environment in { venv_dir } " )
86- session .install ("virtualenv" )
87- session .run ("virtualenv" , venv_dir , silent = True )
121+ session .run ("uv" , "venv" , external = True )
88122
89- python = os .path .join (venv_dir , "bin/python" )
90- session .run (python , "-m" , "pip" , "install" , "-e" , ".[tests,dev]" , external = True )
91123
92-
93- @nox .session
94- def black (session ):
95- print ("please run `nox -s lint` instead" )
96- raise SystemExit (1 )
97-
98-
99- @nox .session
124+ @nox .session (name = "type-checking" , python = BASE_PYTHON )
100125def type_checking (session ):
126+ """Run mypy checks."""
101127 session .install ("-e" , ".[typechecking]" )
102128 session .run ("python" , "-m" , "mypy" )
103129
104130
105- @nox .session (python = ["3.9" , "3.10" , "3.11" , "3.12" , "3.13" , "3.14" ])
106- def typesafety (session ):
131+ @nox .session (name = "type-safety" , python = SUPPORTED_PYTHONS )
132+ def type_safety (session ):
133+ """Run typesafety tests."""
107134 session .install ("-e" , ".[typechecking]" )
108135 session .run (
109136 "python" ,
@@ -119,7 +146,12 @@ def typesafety(session):
119146 )
120147
121148
122- @nox .session (python = "3.12" )
149+ @nox .session (name = "flavours-upgrade-deps" , python = BASE_PYTHON )
150+ def upgrade_flavours (session ):
151+ session .run ("uvx" , "pur" , "-r" , "dev/requirements.txt" )
152+
153+
154+ @nox .session (name = "flavours-codegen" , python = BASE_PYTHON )
123155def generate_flavours (session ):
124156 session .install ("-r" , "dev/requirements.txt" )
125157 with open ("upath/_flavour_sources.py" , "w" ) as target :
0 commit comments