From 71e18043fe7723a390f33b02a5d713e3b87dd943 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 15 Mar 2025 12:33:59 -0400 Subject: [PATCH 1/2] Move requirements to dev dependency group and consistent dep version in tests --- .github/workflows/test.yml | 12 ++++-------- pyproject.toml | 27 +++++++++++++++++++++++++++ stubs/vispy/util/fonts/__init__.pyi | 4 ++-- tests/requirements.txt | 21 --------------------- tests/run_hygiene.py | 25 ++++++++++++------------- tests/run_tests.py | 13 +++++-------- 6 files changed, 50 insertions(+), 52 deletions(-) delete mode 100644 tests/requirements.txt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 991328db..112f0928 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: 'Test' +name: "Test" on: [push, pull_request, workflow_dispatch] @@ -20,13 +20,12 @@ jobs: uses: actions/cache@v4 with: path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} restore-keys: | ${{ runner.os }}-pip- - name: Install dependencies - run: - python -m pip install -r tests/requirements.txt + run: python -m pip install --group tests - name: Run pyright tests uses: jakebailey/pyright-action@v2 @@ -34,8 +33,7 @@ jobs: pylance-version: latest-prerelease - name: Run mypy tests - run: - python -m mypy . + run: python -m mypy . hygiene: runs-on: ubuntu-latest @@ -47,6 +45,4 @@ jobs: - name: Run Ruff Linter uses: astral-sh/ruff-action@v3 - with: - version: "0.9.*" - run: ruff format --check diff --git a/pyproject.toml b/pyproject.toml index 42e32ed6..2c0d9f81 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,33 @@ build-backend = "setuptools.build_meta" name = "microsoft-python-type-stubs" dynamic = ["version"] +[dependency-groups] +hygiene = ["ruff ==0.11.*"] +tests = [ + # Tools used for testing + "docopt-ng", + "mypy ==1.13.*", + "pyright", + + # Typed libraries and stubs + "matplotlib >=3.8", + "pandas-stubs", + "pytest", + "scipy-stubs", + "typing_extensions", + + # Untyped libraries, used to prevent "reportMissingImports" and get inferred typing + "joblib", + "networkx", + "PyOpenGL", + "scikit-learn", + "sympy", + "traitlets", + "transformers", +] +dev = [{ include-group = "hygiene" }, { include-group = "tests" }] + + # Allow these stubs to be installed from GitHub # We need an explicit mapping instead of just # [tool.setuptools] diff --git a/stubs/vispy/util/fonts/__init__.pyi b/stubs/vispy/util/fonts/__init__.pyi index e44a52c9..79bac94b 100644 --- a/stubs/vispy/util/fonts/__init__.pyi +++ b/stubs/vispy/util/fonts/__init__.pyi @@ -6,5 +6,5 @@ __all__ = ["list_fonts"] -from ._triage import list_fonts as list_fonts # noqa, analysis:ignore -from ._vispy_fonts import _vispy_fonts as _vispy_fonts # noqa, analysis:ignore +from ._triage import list_fonts as list_fonts # analysis:ignore +from ._vispy_fonts import _vispy_fonts as _vispy_fonts # analysis:ignore diff --git a/tests/requirements.txt b/tests/requirements.txt deleted file mode 100644 index 40f437c9..00000000 --- a/tests/requirements.txt +++ /dev/null @@ -1,21 +0,0 @@ -# Tools used for testing -docopt-ng -mypy==1.13.* -pyright - -# Typed libraries and stubs -matplotlib>=3.8 -pandas-stubs -pytest -scipy-stubs -typing_extensions - -# Untyped libraries, used to prevent "reportMissingImports" and get inferred typing -joblib -networkx -PyOpenGL -scikit-learn -sympy -traitlets -transformers -transformers diff --git a/tests/run_hygiene.py b/tests/run_hygiene.py index b8c64010..97770ee6 100644 --- a/tests/run_hygiene.py +++ b/tests/run_hygiene.py @@ -6,28 +6,27 @@ def install_requirements(): print("\nInstalling requirements...") - return subprocess.run((sys.executable, "-m", "pip", "install", "--upgrade", "isort", "black")) + subprocess.check_call((sys.executable, "-m", "pip", "install", "pip>=25.1")) + subprocess.check_call((sys.executable, "-m", "pip", "install", "--upgrade", "--group", "hygiene")) -def run_isort(): - print("\nRunning isort...") - return subprocess.run((sys.executable, "-m", "isort", ".")) +def run_ruff_fix(): + print("\nRunning Ruff check --fix...") + return subprocess.run((sys.executable, "-m", "ruff", "check", "--fix")) -def run_black(): - print("\nRunning Black...") - return subprocess.run((sys.executable, "-m", "black", ".")) +def run_ruff_format(): + print("\nRunning Ruff format...") + return subprocess.run((sys.executable, "-m", "ruff", "format")) def main(): - test_folder = Path(__file__).parent - root = test_folder.parent - os.chdir(root) + os.chdir(Path(__file__).parent.parent) - install_requirements().check_returncode() + install_requirements() results = ( - run_isort(), - run_black(), + run_ruff_fix(), + run_ruff_format(), ) if sum([result.returncode for result in results]) > 0: print("\nOne or more tests failed. See above for details.") diff --git a/tests/run_tests.py b/tests/run_tests.py index 2695f798..b551b8ed 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -4,11 +4,10 @@ from pathlib import Path -def install_requirements(test_folder: Path): +def install_requirements(): print("\nInstalling requirements...") - return subprocess.run( - (sys.executable, "-m", "pip", "install", "--upgrade", "-r", os.path.join(test_folder, "requirements.txt")) - ) + subprocess.check_call((sys.executable, "-m", "pip", "install", "pip>=25.1")) + subprocess.check_call((sys.executable, "-m", "pip", "install", "--upgrade", "--group", "tests")) def run_pyright(): @@ -25,11 +24,9 @@ def run_mypy(): def main(): - test_folder = Path(__file__).parent - root = test_folder.parent - os.chdir(root) + os.chdir(Path(__file__).parent.parent) - install_requirements(test_folder).check_returncode() + install_requirements() results = ( run_mypy(), run_pyright(), From d30d93dc72269b58e62020c3176c595818b2367f Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 5 May 2025 16:00:09 -0400 Subject: [PATCH 2/2] version is not actually dynamic --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2c0d9f81..dcf942b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "microsoft-python-type-stubs" -dynamic = ["version"] +version = "0" [dependency-groups] hygiene = ["ruff ==0.11.*"]