-
Notifications
You must be signed in to change notification settings - Fork 141
fix: noxfile.py & better align it against GitHub Actions CI #2358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,6 @@ | ||||||||||
from __future__ import annotations | ||||||||||
|
||||||||||
from tempfile import NamedTemporaryFile | ||||||||||
from typing import TYPE_CHECKING | ||||||||||
|
||||||||||
import nox | ||||||||||
|
@@ -8,80 +9,218 @@ | |||||||||
from nox.sessions import Session | ||||||||||
|
||||||||||
nox.options.default_venv_backend = "uv" | ||||||||||
nox.options.reuse_venv = "yes" | ||||||||||
nox.options.reuse_venv = "never" | ||||||||||
|
||||||||||
PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12"] | ||||||||||
PYTHON_VERSIONS = { | ||||||||||
"pytest": ["3.8", "3.10", "3.11", "3.12", "3.13"], | ||||||||||
"random": ["3.9"], | ||||||||||
"minimum": "3.8", | ||||||||||
"pretty_old": "3.8", | ||||||||||
"not_so_old": "3.10", | ||||||||||
"nightly": "3.13", | ||||||||||
} | ||||||||||
|
||||||||||
|
||||||||||
def run_common(session: Session, coverage_threshold: float) -> None: | ||||||||||
if session.python == "3.8": | ||||||||||
session.install("-e . --group dev-core") | ||||||||||
elif session.python == "3.12": | ||||||||||
session.install("-e .[dask,modin] --group dev-core --group extra") | ||||||||||
else: | ||||||||||
session.install("-e .[dask,modin,pyspark,ibis] --group dev-core --group extra") | ||||||||||
@nox.session(python=PYTHON_VERSIONS["pytest"]) | ||||||||||
def pytest_coverage(session: Session) -> None: | ||||||||||
pytest_cmd = [ | ||||||||||
"pytest", | ||||||||||
"tests", | ||||||||||
"--cov=narwhals", | ||||||||||
"--cov=tests", | ||||||||||
] | ||||||||||
|
||||||||||
if session.python == "3.8": | ||||||||||
session.install( | ||||||||||
"-e", ".[pandas,polars,pyarrow]", "backports.zoneinfo", "--group", "tests" | ||||||||||
) | ||||||||||
session.run( | ||||||||||
*pytest_cmd, | ||||||||||
"--cov-fail-under=80", | ||||||||||
"--constructors", | ||||||||||
"pandas,pyarrow,polars[eager],polars[lazy]", | ||||||||||
) | ||||||||||
|
||||||||||
elif session.python in {"3.10", "3.12"}: | ||||||||||
session.install( | ||||||||||
"-e", ".[dask,modin]", "--group", "core-tests", "--group", "extra" | ||||||||||
) | ||||||||||
session.run( | ||||||||||
*pytest_cmd, | ||||||||||
"--cov-fail-under=95", | ||||||||||
"--runslow", | ||||||||||
"--constructors", | ||||||||||
"pandas,pandas[nullable],pandas[pyarrow],pyarrow,modin[pyarrow],polars[eager],polars[lazy],dask,duckdb,sqlframe", | ||||||||||
) | ||||||||||
|
||||||||||
elif session.python in {"3.11", "3.13"}: | ||||||||||
session.install( | ||||||||||
"-e", ".[modin, dask]", "--group", "core-tests", "--group", "extra" | ||||||||||
) | ||||||||||
session.install("-U", "--pre", "duckdb") | ||||||||||
if session.python != "3.13": | ||||||||||
with NamedTemporaryFile() as f: | ||||||||||
f.write(b"setuptools<78\n") | ||||||||||
session.install("-b", f.name, "-e", ".[pyspark]") | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, why do we need to create a file for setuptools? Maybe we could add the reason in a comment too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was (naively) moved over from the current CI as I didn't think one could pipe to stdin within a subprocess like this. I also don't think narwhals/.github/workflows/pytest.yml Lines 89 to 92 in 4144497
Perhaps @MarcoGorelli remembers something here? |
||||||||||
|
||||||||||
if session.python == "3.11": | ||||||||||
session.install("-e", ".[ibis]") | ||||||||||
|
||||||||||
session.run( | ||||||||||
*pytest_cmd, | ||||||||||
"--cov-fail-under=100", | ||||||||||
"--runslow", | ||||||||||
"--all-cpu-constructors", | ||||||||||
env={ | ||||||||||
"NARWHALS_POLARS_NEW_STREAMING": str(session.python == "3.11"), | ||||||||||
}, | ||||||||||
) | ||||||||||
|
||||||||||
if session.python == PYTHON_VERSIONS["pytest"][-1]: | ||||||||||
session.run("pytest", "narwhals/", "--doctest-modules") | ||||||||||
|
||||||||||
|
||||||||||
@nox.session(python=PYTHON_VERSIONS["minimum"]) | ||||||||||
def minimum(session: Session) -> None: | ||||||||||
session.install( | ||||||||||
"pandas==0.25.3", | ||||||||||
"polars==0.20.3", | ||||||||||
"numpy==1.17.5", | ||||||||||
"pyarrow==11.0.0", | ||||||||||
"pyarrow-stubs<17", | ||||||||||
"scipy==1.5.0", | ||||||||||
"scikit-learn==1.1.0", | ||||||||||
"duckdb==1.0", | ||||||||||
"tzdata", | ||||||||||
"backports.zoneinfo", | ||||||||||
) | ||||||||||
session.install("-e", ".", "--group", "tests") | ||||||||||
session.run( | ||||||||||
"pytest", | ||||||||||
"tests", | ||||||||||
"--cov=narwhals", | ||||||||||
"--cov=tests", | ||||||||||
f"--cov-fail-under={coverage_threshold}", | ||||||||||
"--cov-fail-under=50", | ||||||||||
"--runslow", | ||||||||||
"--constructors=pandas,pyarrow,polars[eager],polars[lazy]", | ||||||||||
) | ||||||||||
|
||||||||||
if session.python == "3.12": | ||||||||||
session.run("pytest", "narwhals", "--doctest-modules") | ||||||||||
|
||||||||||
|
||||||||||
@nox.session(python=PYTHON_VERSIONS) # type: ignore[misc] | ||||||||||
def pytest_coverage(session: Session) -> None: | ||||||||||
coverage_threshold = 85 if session.python == "3.8" else 100 | ||||||||||
|
||||||||||
run_common(session, coverage_threshold) | ||||||||||
|
||||||||||
|
||||||||||
@nox.session(python=PYTHON_VERSIONS[0]) # type: ignore[misc] | ||||||||||
@nox.parametrize("pandas_version", ["0.25.3", "1.1.5"]) # type: ignore[misc] | ||||||||||
def min_and_old_versions(session: Session, pandas_version: str) -> None: | ||||||||||
@nox.session(python=PYTHON_VERSIONS["pretty_old"]) | ||||||||||
def pretty_old(session: Session) -> None: | ||||||||||
session.install( | ||||||||||
f"pandas=={pandas_version}", | ||||||||||
"pandas==1.1.5", | ||||||||||
"polars==0.20.3", | ||||||||||
"numpy==1.17.5", | ||||||||||
"pyarrow==11.0.0", | ||||||||||
"pyarrow-stubs<17", | ||||||||||
"scipy==1.5.0", | ||||||||||
"scikit-learn==1.1.0", | ||||||||||
"duckdb==1.0", | ||||||||||
"tzdata", | ||||||||||
"backports.zoneinfo", | ||||||||||
) | ||||||||||
session.install("-e", ".", "--group", "tests") | ||||||||||
session.run( | ||||||||||
"pytest", | ||||||||||
"tests", | ||||||||||
"--cov=narwhals", | ||||||||||
"--cov=tests", | ||||||||||
"--cov-fail-under=50", | ||||||||||
"--runslow", | ||||||||||
"--constructors=pandas,pyarrow,polars[eager],polars[lazy]", | ||||||||||
) | ||||||||||
|
||||||||||
|
||||||||||
@nox.session(python=PYTHON_VERSIONS["not_so_old"]) | ||||||||||
def not_so_old(session: Session) -> None: | ||||||||||
session.install( | ||||||||||
"pandas==2.0.3", | ||||||||||
"polars==0.20.8", | ||||||||||
"numpy==1.24.4", | ||||||||||
"pyarrow==15.0.0", | ||||||||||
"pyarrow-stubs<17", | ||||||||||
"scipy==1.8.0", | ||||||||||
"scikit-learn==1.3.0", | ||||||||||
"duckdb==1.0", | ||||||||||
"dask[dataframe]==2024.10 ", | ||||||||||
"tzdata", | ||||||||||
) | ||||||||||
if pandas_version == "1.1.5": | ||||||||||
session.install("pyspark==3.3.0") | ||||||||||
run_common(session, coverage_threshold=50) | ||||||||||
session.install("-e", ".", "--group", "tests") | ||||||||||
session.run( | ||||||||||
"pytest", | ||||||||||
"tests", | ||||||||||
"--cov=narwhals", | ||||||||||
"--cov=tests", | ||||||||||
"--cov-fail-under=50", | ||||||||||
"--runslow", | ||||||||||
"--constructors=pandas,pyarrow,polars[eager],polars[lazy]", | ||||||||||
) | ||||||||||
|
||||||||||
|
||||||||||
@nox.session(python=PYTHON_VERSIONS[-1]) # type: ignore[misc] | ||||||||||
@nox.session(python=PYTHON_VERSIONS["nightly"]) | ||||||||||
def nightly_versions(session: Session) -> None: | ||||||||||
session.install("polars") | ||||||||||
session.install("-e", ".", "--group", "tests") | ||||||||||
|
||||||||||
session.install("--pre", "polars") | ||||||||||
|
||||||||||
session.run("pip", "uninstall", "pandas", "--yes") | ||||||||||
session.install( # pandas nightly | ||||||||||
"--pre", | ||||||||||
"--extra-index-url", | ||||||||||
"https://pypi.anaconda.org/scientific-python-nightly-wheels/simple", | ||||||||||
"pandas", | ||||||||||
) | ||||||||||
|
||||||||||
session.run("pip", "uninstall", "pyarrow", "--yes") | ||||||||||
session.install( # pyarrow nightly | ||||||||||
"--extra-index-url", "https://pypi.fury.io/arrow-nightlies/", "--pre", "pyarrow" | ||||||||||
) | ||||||||||
|
||||||||||
session.run("pip", "uninstall", "numpy", "--yes") | ||||||||||
session.install( # numpy nightly | ||||||||||
"--pre", | ||||||||||
"--extra-index-url", | ||||||||||
"https://pypi.anaconda.org/scientific-python-nightly-wheels/simple", | ||||||||||
"numpy", | ||||||||||
) | ||||||||||
|
||||||||||
session.run("uv", "pip", "install", "pip") | ||||||||||
session.run( # dask nightly | ||||||||||
"pip", | ||||||||||
"install", | ||||||||||
"git+https://github.com/dask/distributed", | ||||||||||
"git+https://github.com/dask/dask", | ||||||||||
"git+https://github.com/dask/dask-expr", | ||||||||||
) | ||||||||||
run_common(session, coverage_threshold=50) | ||||||||||
|
||||||||||
session.install("-U", "--pre", "duckdb") # duckdb nightly | ||||||||||
|
||||||||||
session.run( | ||||||||||
"pytest", | ||||||||||
"tests", | ||||||||||
"--cov=narwhals", | ||||||||||
"--cov=tests", | ||||||||||
"--cov-fail-under=50", | ||||||||||
"--runslow", | ||||||||||
"--constructors=pandas,pandas[nullable],pandas[pyarrow],pyarrow,polars[eager],polars[lazy],dask,duckdb", | ||||||||||
) | ||||||||||
|
||||||||||
|
||||||||||
@nox.session(python=PYTHON_VERSIONS["random"]) | ||||||||||
def random(session: Session) -> None: | ||||||||||
from utils.generate_random_versions import requirements | ||||||||||
|
||||||||||
with NamedTemporaryFile("w", suffix=".txt") as fd: | ||||||||||
fd.write(requirements) | ||||||||||
fd.flush() | ||||||||||
|
||||||||||
session.install("-r", fd.name) | ||||||||||
session.install("-e", ".", "--group", "tests") | ||||||||||
|
||||||||||
session.run( | ||||||||||
"pytest", | ||||||||||
"tests", | ||||||||||
"--cov=narwhals", | ||||||||||
"--cov=tests", | ||||||||||
"--cov-fail-under=80", | ||||||||||
"--constructors=pandas,pyarrow,polars[eager],polars[lazy]", | ||||||||||
) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
from __future__ import annotations | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
import random | ||||||||||||||||||||||||||||||||||||||||||||||||||
from textwrap import dedent | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
PANDAS_AND_NUMPY_VERSION = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||
# ("1.0.5", "1.18.5"), # fails to build in CI # noqa: ERA001 | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -57,16 +58,13 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
pandas_version, numpy_version = random.choice(PANDAS_AND_NUMPY_VERSION) | ||||||||||||||||||||||||||||||||||||||||||||||||||
polars_version = random.choice(POLARS_VERSION) | ||||||||||||||||||||||||||||||||||||||||||||||||||
pyarrow_version = random.choice(PYARROW_VERSION) | ||||||||||||||||||||||||||||||||||||||||||||||||||
requirements = dedent(f""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
pandas=={pandas_version} | ||||||||||||||||||||||||||||||||||||||||||||||||||
numpy=={numpy_version} | ||||||||||||||||||||||||||||||||||||||||||||||||||
polars=={polars_version} | ||||||||||||||||||||||||||||||||||||||||||||||||||
pyarrow=={pyarrow_version} | ||||||||||||||||||||||||||||||||||||||||||||||||||
""").lstrip() | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
content = f"pandas=={pandas_version}\nnumpy=={numpy_version}\npolars=={polars_version}\npyarrow=={pyarrow_version}\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
with open("random-requirements.txt", "w") as fd: | ||||||||||||||||||||||||||||||||||||||||||||||||||
fd.write(content) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
with open("pyproject.toml") as fd: | ||||||||||||||||||||||||||||||||||||||||||||||||||
content = fd.read() | ||||||||||||||||||||||||||||||||||||||||||||||||||
content = content.replace( | ||||||||||||||||||||||||||||||||||||||||||||||||||
'filterwarnings = [\n "error",\n]', | ||||||||||||||||||||||||||||||||||||||||||||||||||
"filterwarnings = [\n \"error\",\n 'ignore:distutils Version classes are deprecated:DeprecationWarning',\n]", | ||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
-67
to
-70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this not needed anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah thank you! I was going to leave a comment for @MarcoGorelli about this. The matching string doesn't exist in the Lines 204 to 227 in 4144497
|
||||||||||||||||||||||||||||||||||||||||||||||||||
with open("pyproject.toml", "w") as fd: | ||||||||||||||||||||||||||||||||||||||||||||||||||
fd.write(content) | ||||||||||||||||||||||||||||||||||||||||||||||||||
if __name__ == "__main__": | ||||||||||||||||||||||||||||||||||||||||||||||||||
with open("random-requirements.txt", "w") as fd: | ||||||||||||||||||||||||||||||||||||||||||||||||||
fd.write(requirements) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this too. In CI we test on python
3.9
only in therandom
test.Is it something deliberate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracked back to this commit: e718d1f
My guess is that it mainly reduces the time it takes for tests to run without sacrificing too much validity.
Though I'll kick this one to @MarcoGorelli as well if he remembers.