From b833caa33bc24c2ccf6eebae6bc51f068167add6 Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Mon, 24 Feb 2025 14:47:43 +0800 Subject: [PATCH 1/5] chore: upgrade deps, improve type hints and check style in ci --- .github/workflows/ci.yml | 4 + .gitignore | 1 + .pre-commit-config.yaml | 4 +- Makefile | 55 +++++++ pdm.lock | 185 ++++++++++++++++------ pyproject.toml | 18 ++- src/findpython/__init__.py | 9 +- src/findpython/pep514tools/__init__.py | 2 +- src/findpython/pep514tools/_registry.py | 7 +- src/findpython/pep514tools/environment.py | 2 +- src/findpython/providers/__init__.py | 1 + src/findpython/providers/asdf.py | 15 +- src/findpython/providers/base.py | 19 ++- src/findpython/providers/macos.py | 15 +- src/findpython/providers/path.py | 15 +- src/findpython/providers/pyenv.py | 15 +- src/findpython/providers/rye.py | 15 +- src/findpython/providers/winreg.py | 15 +- tests/conftest.py | 2 + 19 files changed, 311 insertions(+), 88 deletions(-) create mode 100644 Makefile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac28dd7..43dd9e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,10 @@ jobs: - name: Install packages run: pdm install + - name: Check Style + run: | + pdm run pip install pre-commit + pdm run pre-commit run --all-files - name: Run Integration run: pdm run findpython --all -v - name: Run Tests diff --git a/.gitignore b/.gitignore index 46e9919..7b2b977 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.py[cod] __pycache__/ venv/ +.venv/ .tox/ .vscode/ /build/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bc25118..3382065 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,13 +14,13 @@ exclude: > repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.0.276' + rev: 'v0.9.7' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix, --show-fixes] - repo: https://github.com/ambv/black - rev: 23.3.0 + rev: 24.8.0 hooks: - id: black diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e214208 --- /dev/null +++ b/Makefile @@ -0,0 +1,55 @@ +checkfiles = src/ tests/ + +help: + @echo "FindPython development makefile" + @echo + @echo "Usage: make " + @echo "Targets:" + @echo " up Updates dev/test dependencies" + @echo " deps Ensure dev/test dependencies are installed" + @echo " check Checks that build is sane" + @echo " test Runs all tests" + @echo " style Auto-formats the code" + @echo " lint Auto-formats the code and check type hints" + +up: + pdm update --verbose + +deps: +ifeq ($(wildcard .venv),) + pdm install --verbose +else + pdm install +endif + +_check: + pdm run ruff format --check $(checkfiles) + pdm run ruff check $(checkfiles) + pdm run mypy $(checkfiles) +check: deps _build _check + +_style: + pdm run ruff format $(checkfiles) + pdm run ruff check --fix $(checkfiles) +style: deps _style + +_lint: + pdm run ruff format $(checkfiles) + pdm run ruff check --fix $(checkfiles) + pdm run mypy $(checkfiles) +lint: deps _build _lint + +_test: + pdm run pytest -s tests +test: deps _test + +_build: + rm -fR dist/ + pdm build +build: deps _build + +# Usage:: +# make venv version=3.12 +venv: + pdm venv create $(version) + pdm run pip install --upgrade pip diff --git a/pdm.lock b/pdm.lock index 37e0aca..6cd5e57 100644 --- a/pdm.lock +++ b/pdm.lock @@ -2,113 +2,202 @@ # It is not intended for manual editing. [metadata] -groups = ["default", "tests"] +groups = ["default", "dev", "tests"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:a279fe9d01b3a467d5cc6a13d1b17b2d163850cbce221ddb750028acaaef90cf" +content_hash = "sha256:f6123e36c730e63eacef3a447cd119c44562eb380535a7648fcfa4cd14656c85" [[metadata.targets]] requires_python = ">=3.8" -[[package]] -name = "attrs" -version = "22.1.0" -requires_python = ">=3.5" -summary = "Classes Without Boilerplate" -groups = ["tests"] -files = [ - {file = "attrs-22.1.0-py2.py3-none-any.whl", hash = "sha256:86efa402f67bf2df34f51a335487cf46b1ec130d02b8d39fd248abfd30da551c"}, - {file = "attrs-22.1.0.tar.gz", hash = "sha256:29adc2665447e5191d0e7c568fde78b21f9672d344281d0c6e1ab085429b22b6"}, -] - [[package]] name = "colorama" -version = "0.4.5" -requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +version = "0.4.6" +requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" summary = "Cross-platform colored terminal text." groups = ["tests"] marker = "sys_platform == \"win32\"" files = [ - {file = "colorama-0.4.5-py2.py3-none-any.whl", hash = "sha256:854bf444933e37f5824ae7bfc1e98d5bce2ebe4160d46b5edf346a89358e99da"}, - {file = "colorama-0.4.5.tar.gz", hash = "sha256:e6c6b4334fc50988a639d9b98aa429a0b57da6e17b9a44f0451f930b6967b7a4"}, + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] [[package]] name = "exceptiongroup" -version = "1.1.0" +version = "1.2.2" requires_python = ">=3.7" summary = "Backport of PEP 654 (exception groups)" groups = ["tests"] marker = "python_version < \"3.11\"" files = [ - {file = "exceptiongroup-1.1.0-py3-none-any.whl", hash = "sha256:327cbda3da756e2de031a3107b81ab7b3770a602c4d16ca618298c526f4bec1e"}, - {file = "exceptiongroup-1.1.0.tar.gz", hash = "sha256:bcb67d800a4497e1b404c2dd44fca47d3b7a5e5433dbab67f96c1a685cdfdf23"}, + {file = "exceptiongroup-1.2.2-py3-none-any.whl", hash = "sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b"}, + {file = "exceptiongroup-1.2.2.tar.gz", hash = "sha256:47c2edf7c6738fafb49fd34290706d1a1a2f4d1c6df275526b62cbb4aa5393cc"}, ] [[package]] name = "iniconfig" -version = "1.1.1" -summary = "iniconfig: brain-dead simple config-ini parsing" +version = "2.0.0" +requires_python = ">=3.7" +summary = "brain-dead simple config-ini parsing" groups = ["tests"] files = [ - {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, - {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, +] + +[[package]] +name = "mypy" +version = "1.14.1" +requires_python = ">=3.8" +summary = "Optional static typing for Python" +groups = ["dev"] +dependencies = [ + "mypy-extensions>=1.0.0", + "tomli>=1.1.0; python_version < \"3.11\"", + "typing-extensions>=4.6.0", +] +files = [ + {file = "mypy-1.14.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:52686e37cf13d559f668aa398dd7ddf1f92c5d613e4f8cb262be2fb4fedb0fcb"}, + {file = "mypy-1.14.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:1fb545ca340537d4b45d3eecdb3def05e913299ca72c290326be19b3804b39c0"}, + {file = "mypy-1.14.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:90716d8b2d1f4cd503309788e51366f07c56635a3309b0f6a32547eaaa36a64d"}, + {file = "mypy-1.14.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2ae753f5c9fef278bcf12e1a564351764f2a6da579d4a81347e1d5a15819997b"}, + {file = "mypy-1.14.1-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:e0fe0f5feaafcb04505bcf439e991c6d8f1bf8b15f12b05feeed96e9e7bf1427"}, + {file = "mypy-1.14.1-cp310-cp310-win_amd64.whl", hash = "sha256:7d54bd85b925e501c555a3227f3ec0cfc54ee8b6930bd6141ec872d1c572f81f"}, + {file = "mypy-1.14.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:f995e511de847791c3b11ed90084a7a0aafdc074ab88c5a9711622fe4751138c"}, + {file = "mypy-1.14.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:d64169ec3b8461311f8ce2fd2eb5d33e2d0f2c7b49116259c51d0d96edee48d1"}, + {file = "mypy-1.14.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ba24549de7b89b6381b91fbc068d798192b1b5201987070319889e93038967a8"}, + {file = "mypy-1.14.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:183cf0a45457d28ff9d758730cd0210419ac27d4d3f285beda038c9083363b1f"}, + {file = "mypy-1.14.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:f2a0ecc86378f45347f586e4163d1769dd81c5a223d577fe351f26b179e148b1"}, + {file = "mypy-1.14.1-cp311-cp311-win_amd64.whl", hash = "sha256:ad3301ebebec9e8ee7135d8e3109ca76c23752bac1e717bc84cd3836b4bf3eae"}, + {file = "mypy-1.14.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:30ff5ef8519bbc2e18b3b54521ec319513a26f1bba19a7582e7b1f58a6e69f14"}, + {file = "mypy-1.14.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:cb9f255c18052343c70234907e2e532bc7e55a62565d64536dbc7706a20b78b9"}, + {file = "mypy-1.14.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:8b4e3413e0bddea671012b063e27591b953d653209e7a4fa5e48759cda77ca11"}, + {file = "mypy-1.14.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:553c293b1fbdebb6c3c4030589dab9fafb6dfa768995a453d8a5d3b23784af2e"}, + {file = "mypy-1.14.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:fad79bfe3b65fe6a1efaed97b445c3d37f7be9fdc348bdb2d7cac75579607c89"}, + {file = "mypy-1.14.1-cp312-cp312-win_amd64.whl", hash = "sha256:8fa2220e54d2946e94ab6dbb3ba0a992795bd68b16dc852db33028df2b00191b"}, + {file = "mypy-1.14.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:92c3ed5afb06c3a8e188cb5da4984cab9ec9a77ba956ee419c68a388b4595255"}, + {file = "mypy-1.14.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:dbec574648b3e25f43d23577309b16534431db4ddc09fda50841f1e34e64ed34"}, + {file = "mypy-1.14.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:8c6d94b16d62eb3e947281aa7347d78236688e21081f11de976376cf010eb31a"}, + {file = "mypy-1.14.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d4b19b03fdf54f3c5b2fa474c56b4c13c9dbfb9a2db4370ede7ec11a2c5927d9"}, + {file = "mypy-1.14.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:0c911fde686394753fff899c409fd4e16e9b294c24bfd5e1ea4675deae1ac6fd"}, + {file = "mypy-1.14.1-cp313-cp313-win_amd64.whl", hash = "sha256:8b21525cb51671219f5307be85f7e646a153e5acc656e5cebf64bfa076c50107"}, + {file = "mypy-1.14.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:7084fb8f1128c76cd9cf68fe5971b37072598e7c31b2f9f95586b65c741a9d31"}, + {file = "mypy-1.14.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:8f845a00b4f420f693f870eaee5f3e2692fa84cc8514496114649cfa8fd5e2c6"}, + {file = "mypy-1.14.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:44bf464499f0e3a2d14d58b54674dee25c031703b2ffc35064bd0df2e0fac319"}, + {file = "mypy-1.14.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c99f27732c0b7dc847adb21c9d47ce57eb48fa33a17bc6d7d5c5e9f9e7ae5bac"}, + {file = "mypy-1.14.1-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:bce23c7377b43602baa0bd22ea3265c49b9ff0b76eb315d6c34721af4cdf1d9b"}, + {file = "mypy-1.14.1-cp38-cp38-win_amd64.whl", hash = "sha256:8edc07eeade7ebc771ff9cf6b211b9a7d93687ff892150cb5692e4f4272b0837"}, + {file = "mypy-1.14.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:3888a1816d69f7ab92092f785a462944b3ca16d7c470d564165fe703b0970c35"}, + {file = "mypy-1.14.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:46c756a444117c43ee984bd055db99e498bc613a70bbbc120272bd13ca579fbc"}, + {file = "mypy-1.14.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:27fc248022907e72abfd8e22ab1f10e903915ff69961174784a3900a8cba9ad9"}, + {file = "mypy-1.14.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:499d6a72fb7e5de92218db961f1a66d5f11783f9ae549d214617edab5d4dbdbb"}, + {file = "mypy-1.14.1-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:57961db9795eb566dc1d1b4e9139ebc4c6b0cb6e7254ecde69d1552bf7613f60"}, + {file = "mypy-1.14.1-cp39-cp39-win_amd64.whl", hash = "sha256:07ba89fdcc9451f2ebb02853deb6aaaa3d2239a236669a63ab3801bbf923ef5c"}, + {file = "mypy-1.14.1-py3-none-any.whl", hash = "sha256:b66a60cc4073aeb8ae00057f9c1f64d49e90f918fbcef9a977eb121da8b8f1d1"}, + {file = "mypy-1.14.1.tar.gz", hash = "sha256:7ec88144fe9b510e8475ec2f5f251992690fcf89ccb4500b214b4226abcd32d6"}, +] + +[[package]] +name = "mypy-extensions" +version = "1.0.0" +requires_python = ">=3.5" +summary = "Type system extensions for programs checked with the mypy type checker." +groups = ["dev"] +files = [ + {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"}, + {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, ] [[package]] name = "packaging" -version = "23.0" -requires_python = ">=3.7" +version = "24.2" +requires_python = ">=3.8" summary = "Core utilities for Python packages" groups = ["default", "tests"] files = [ - {file = "packaging-23.0-py3-none-any.whl", hash = "sha256:714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2"}, - {file = "packaging-23.0.tar.gz", hash = "sha256:b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97"}, + {file = "packaging-24.2-py3-none-any.whl", hash = "sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759"}, + {file = "packaging-24.2.tar.gz", hash = "sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f"}, ] [[package]] name = "pluggy" -version = "1.0.0" -requires_python = ">=3.6" +version = "1.5.0" +requires_python = ">=3.8" summary = "plugin and hook calling mechanisms for python" groups = ["tests"] -dependencies = [ - "importlib-metadata>=0.12; python_version < \"3.8\"", -] files = [ - {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, - {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, + {file = "pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669"}, + {file = "pluggy-1.5.0.tar.gz", hash = "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1"}, ] [[package]] name = "pytest" -version = "7.2.1" -requires_python = ">=3.7" +version = "8.3.4" +requires_python = ">=3.8" summary = "pytest: simple powerful testing with Python" groups = ["tests"] dependencies = [ - "attrs>=19.2.0", "colorama; sys_platform == \"win32\"", "exceptiongroup>=1.0.0rc8; python_version < \"3.11\"", - "importlib-metadata>=0.12; python_version < \"3.8\"", "iniconfig", "packaging", - "pluggy<2.0,>=0.12", - "tomli>=1.0.0; python_version < \"3.11\"", + "pluggy<2,>=1.5", + "tomli>=1; python_version < \"3.11\"", ] files = [ - {file = "pytest-7.2.1-py3-none-any.whl", hash = "sha256:c7c6ca206e93355074ae32f7403e8ea12163b1163c976fee7d4d84027c162be5"}, - {file = "pytest-7.2.1.tar.gz", hash = "sha256:d45e0952f3727241918b8fd0f376f5ff6b301cc0777c6f9a556935c92d8a7d42"}, + {file = "pytest-8.3.4-py3-none-any.whl", hash = "sha256:50e16d954148559c9a74109af1eaf0c945ba2d8f30f0a3d3335edde19788b6f6"}, + {file = "pytest-8.3.4.tar.gz", hash = "sha256:965370d062bce11e73868e0335abac31b4d3de0e82f4007408d242b4f8610761"}, ] [[package]] name = "tomli" -version = "2.0.1" -requires_python = ">=3.7" +version = "2.2.1" +requires_python = ">=3.8" summary = "A lil' TOML parser" -groups = ["tests"] +groups = ["dev", "tests"] marker = "python_version < \"3.11\"" files = [ - {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, - {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, + {file = "tomli-2.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:678e4fa69e4575eb77d103de3df8a895e1591b48e740211bd1067378c69e8249"}, + {file = "tomli-2.2.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:023aa114dd824ade0100497eb2318602af309e5a55595f76b626d6d9f3b7b0a6"}, + {file = "tomli-2.2.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ece47d672db52ac607a3d9599a9d48dcb2f2f735c6c2d1f34130085bb12b112a"}, + {file = "tomli-2.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6972ca9c9cc9f0acaa56a8ca1ff51e7af152a9f87fb64623e31d5c83700080ee"}, + {file = "tomli-2.2.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c954d2250168d28797dd4e3ac5cf812a406cd5a92674ee4c8f123c889786aa8e"}, + {file = "tomli-2.2.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:8dd28b3e155b80f4d54beb40a441d366adcfe740969820caf156c019fb5c7ec4"}, + {file = "tomli-2.2.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:e59e304978767a54663af13c07b3d1af22ddee3bb2fb0618ca1593e4f593a106"}, + {file = "tomli-2.2.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:33580bccab0338d00994d7f16f4c4ec25b776af3ffaac1ed74e0b3fc95e885a8"}, + {file = "tomli-2.2.1-cp311-cp311-win32.whl", hash = "sha256:465af0e0875402f1d226519c9904f37254b3045fc5084697cefb9bdde1ff99ff"}, + {file = "tomli-2.2.1-cp311-cp311-win_amd64.whl", hash = "sha256:2d0f2fdd22b02c6d81637a3c95f8cd77f995846af7414c5c4b8d0545afa1bc4b"}, + {file = "tomli-2.2.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:4a8f6e44de52d5e6c657c9fe83b562f5f4256d8ebbfe4ff922c495620a7f6cea"}, + {file = "tomli-2.2.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:8d57ca8095a641b8237d5b079147646153d22552f1c637fd3ba7f4b0b29167a8"}, + {file = "tomli-2.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4e340144ad7ae1533cb897d406382b4b6fede8890a03738ff1683af800d54192"}, + {file = "tomli-2.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:db2b95f9de79181805df90bedc5a5ab4c165e6ec3fe99f970d0e302f384ad222"}, + {file = "tomli-2.2.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:40741994320b232529c802f8bc86da4e1aa9f413db394617b9a256ae0f9a7f77"}, + {file = "tomli-2.2.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:400e720fe168c0f8521520190686ef8ef033fb19fc493da09779e592861b78c6"}, + {file = "tomli-2.2.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:02abe224de6ae62c19f090f68da4e27b10af2b93213d36cf44e6e1c5abd19fdd"}, + {file = "tomli-2.2.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:b82ebccc8c8a36f2094e969560a1b836758481f3dc360ce9a3277c65f374285e"}, + {file = "tomli-2.2.1-cp312-cp312-win32.whl", hash = "sha256:889f80ef92701b9dbb224e49ec87c645ce5df3fa2cc548664eb8a25e03127a98"}, + {file = "tomli-2.2.1-cp312-cp312-win_amd64.whl", hash = "sha256:7fc04e92e1d624a4a63c76474610238576942d6b8950a2d7f908a340494e67e4"}, + {file = "tomli-2.2.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:f4039b9cbc3048b2416cc57ab3bda989a6fcf9b36cf8937f01a6e731b64f80d7"}, + {file = "tomli-2.2.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:286f0ca2ffeeb5b9bd4fcc8d6c330534323ec51b2f52da063b11c502da16f30c"}, + {file = "tomli-2.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a92ef1a44547e894e2a17d24e7557a5e85a9e1d0048b0b5e7541f76c5032cb13"}, + {file = "tomli-2.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9316dc65bed1684c9a98ee68759ceaed29d229e985297003e494aa825ebb0281"}, + {file = "tomli-2.2.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e85e99945e688e32d5a35c1ff38ed0b3f41f43fad8df0bdf79f72b2ba7bc5272"}, + {file = "tomli-2.2.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:ac065718db92ca818f8d6141b5f66369833d4a80a9d74435a268c52bdfa73140"}, + {file = "tomli-2.2.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:d920f33822747519673ee656a4b6ac33e382eca9d331c87770faa3eef562aeb2"}, + {file = "tomli-2.2.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:a198f10c4d1b1375d7687bc25294306e551bf1abfa4eace6650070a5c1ae2744"}, + {file = "tomli-2.2.1-cp313-cp313-win32.whl", hash = "sha256:d3f5614314d758649ab2ab3a62d4f2004c825922f9e370b29416484086b264ec"}, + {file = "tomli-2.2.1-cp313-cp313-win_amd64.whl", hash = "sha256:a38aa0308e754b0e3c67e344754dff64999ff9b513e691d0e786265c93583c69"}, + {file = "tomli-2.2.1-py3-none-any.whl", hash = "sha256:cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc"}, + {file = "tomli-2.2.1.tar.gz", hash = "sha256:cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff"}, +] + +[[package]] +name = "typing-extensions" +version = "4.12.2" +requires_python = ">=3.8" +summary = "Backported and Experimental Type Hints for Python 3.8+" +groups = ["dev"] +files = [ + {file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"}, + {file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"}, ] diff --git a/pyproject.toml b/pyproject.toml index 0e2c938..9fbcff7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,6 +19,7 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", ] [project.urls] @@ -37,6 +38,7 @@ package-dir = "src" [tool.pdm.dev-dependencies] tests = ["pytest"] +dev = ["mypy"] [build-system] requires = ["pdm-backend"] @@ -61,6 +63,11 @@ exclude = ''' [tool.ruff] line-length = 90 +src = ["src"] +exclude = ["tests/fixtures"] +target-version = "py38" + +[tool.ruff.lint] select = [ "B", # flake8-bugbear "C4", # flake8-comprehensions @@ -72,14 +79,13 @@ select = [ "YTT", # flake8-2020 ] extend-ignore = ["B018", "B019"] -src = ["src"] -exclude = ["tests/fixtures"] -target-version = "py37" -[tool.ruff.mccabe] +[tool.ruff.lint.mccabe] max-complexity = 10 -[tool.ruff.isort] +[tool.ruff.lint.isort] known-first-party = ["findpython"] - +[[tool.mypy.overrides]] +module = "_winreg" +ignore_missing_imports = true diff --git a/src/findpython/__init__.py b/src/findpython/__init__.py index 5b22100..b35028c 100644 --- a/src/findpython/__init__.py +++ b/src/findpython/__init__.py @@ -1,8 +1,9 @@ """ - FindPython - ~~~~~~~~~~ - A utility to find python versions on your system +FindPython +~~~~~~~~~~ +A utility to find python versions on your system """ + from __future__ import annotations from typing import TYPE_CHECKING, TypeVar @@ -59,4 +60,4 @@ def register_provider(provider: P) -> P: return provider -__all__ = ["Finder", "find", "find_all", "PythonVersion", "register_provider"] +__all__ = ["Finder", "PythonVersion", "find", "find_all", "register_provider"] diff --git a/src/findpython/pep514tools/__init__.py b/src/findpython/pep514tools/__init__.py index a712a28..5fd1561 100644 --- a/src/findpython/pep514tools/__init__.py +++ b/src/findpython/pep514tools/__init__.py @@ -10,4 +10,4 @@ from findpython.pep514tools.environment import find, findall, findone -__all__ = ["findall", "find", "findone"] +__all__ = ["find", "findall", "findone"] diff --git a/src/findpython/pep514tools/_registry.py b/src/findpython/pep514tools/_registry.py index 16cd93a..3699119 100644 --- a/src/findpython/pep514tools/_registry.py +++ b/src/findpython/pep514tools/_registry.py @@ -1,3 +1,4 @@ +# mypy: disable-error-code="attr-defined" # ------------------------------------------------------------------------- # Copyright (c) Steve Dower # All rights reserved. @@ -6,10 +7,10 @@ # ------------------------------------------------------------------------- __all__ = [ - "open_source", + "REGISTRY_SOURCE_CU", "REGISTRY_SOURCE_LM", "REGISTRY_SOURCE_LM_WOW6432", - "REGISTRY_SOURCE_CU", + "open_source", ] import re @@ -18,7 +19,7 @@ try: import winreg except ImportError: - import _winreg as winreg + import _winreg as winreg # type:ignore[no-redef] REGISTRY_SOURCE_LM = 1 REGISTRY_SOURCE_LM_WOW6432 = 2 diff --git a/src/findpython/pep514tools/environment.py b/src/findpython/pep514tools/environment.py index 9d9e1b2..8d53286 100644 --- a/src/findpython/pep514tools/environment.py +++ b/src/findpython/pep514tools/environment.py @@ -5,7 +5,7 @@ # Distributed under the terms of the MIT License # ------------------------------------------------------------------------- -__all__ = ["Environment", "findall", "find", "findone"] +__all__ = ["Environment", "find", "findall", "findone"] import sys diff --git a/src/findpython/providers/__init__.py b/src/findpython/providers/__init__.py index 448d7d1..036ae10 100644 --- a/src/findpython/providers/__init__.py +++ b/src/findpython/providers/__init__.py @@ -1,6 +1,7 @@ """ This package contains all the providers for the pythonfinder module. """ + from __future__ import annotations from findpython.providers.asdf import AsdfProvider diff --git a/src/findpython/providers/asdf.py b/src/findpython/providers/asdf.py index 347ba8b..ad64b68 100644 --- a/src/findpython/providers/asdf.py +++ b/src/findpython/providers/asdf.py @@ -1,12 +1,21 @@ from __future__ import annotations import os -import typing as t from pathlib import Path +import sys +from typing import TYPE_CHECKING from findpython.providers.base import BaseProvider from findpython.python import PythonVersion +if TYPE_CHECKING: + from typing import Iterable + + if sys.version_info >= (3, 11): + from typing import Self + else: + from typing_extensions import Self + class AsdfProvider(BaseProvider): """A provider that finds python installed with asdf""" @@ -15,7 +24,7 @@ def __init__(self, root: Path) -> None: self.root = root @classmethod - def create(cls) -> t.Self | None: + def create(cls) -> Self | None: asdf_root = os.path.expanduser( os.path.expandvars(os.getenv("ASDF_DATA_DIR", "~/.asdf")) ) @@ -23,7 +32,7 @@ def create(cls) -> t.Self | None: return None return cls(Path(asdf_root)) - def find_pythons(self) -> t.Iterable[PythonVersion]: + def find_pythons(self) -> Iterable[PythonVersion]: python_dir = self.root / "installs/python" if not python_dir.exists(): return diff --git a/src/findpython/providers/base.py b/src/findpython/providers/base.py index 51b6339..c765ead 100644 --- a/src/findpython/providers/base.py +++ b/src/findpython/providers/base.py @@ -1,20 +1,29 @@ from __future__ import annotations import abc +import sys import logging -import typing as t from pathlib import Path +from typing import TYPE_CHECKING from findpython.python import PythonVersion from findpython.utils import path_is_python, safe_iter_dir +if TYPE_CHECKING: + from typing import Callable, Iterable + + if sys.version_info >= (3, 11): + from typing import Self + else: + from typing_extensions import Self + logger = logging.getLogger("findpython") class BaseProvider(metaclass=abc.ABCMeta): """The base class for python providers""" - version_maker: t.Callable[..., PythonVersion] = PythonVersion + version_maker: Callable[..., PythonVersion] = PythonVersion @classmethod def name(cls) -> str: @@ -29,19 +38,19 @@ def name(cls) -> str: @classmethod @abc.abstractmethod - def create(cls) -> t.Self | None: + def create(cls) -> Self | None: """Return an instance of the provider or None if it is not available""" pass @abc.abstractmethod - def find_pythons(self) -> t.Iterable[PythonVersion]: + def find_pythons(self) -> Iterable[PythonVersion]: """Return the python versions found by the provider""" pass @classmethod def find_pythons_from_path( cls, path: Path, as_interpreter: bool = False - ) -> t.Iterable[PythonVersion]: + ) -> Iterable[PythonVersion]: """A general helper method to return pythons under a given path. :param path: The path to search for pythons diff --git a/src/findpython/providers/macos.py b/src/findpython/providers/macos.py index 952b08c..be7aafc 100644 --- a/src/findpython/providers/macos.py +++ b/src/findpython/providers/macos.py @@ -1,11 +1,20 @@ from __future__ import annotations -import typing as t from pathlib import Path +import sys +from typing import TYPE_CHECKING from findpython.providers.base import BaseProvider from findpython.python import PythonVersion +if TYPE_CHECKING: + from typing import Iterable + + if sys.version_info >= (3, 11): + from typing import Self + else: + from typing_extensions import Self + class MacOSProvider(BaseProvider): """A provider that finds python from macos typical install base @@ -15,12 +24,12 @@ class MacOSProvider(BaseProvider): INSTALL_BASE = Path("/Library/Frameworks/Python.framework/Versions/") @classmethod - def create(cls) -> t.Self | None: + def create(cls) -> Self | None: if not cls.INSTALL_BASE.exists(): return None return cls() - def find_pythons(self) -> t.Iterable[PythonVersion]: + def find_pythons(self) -> Iterable[PythonVersion]: for version in self.INSTALL_BASE.iterdir(): if version.is_dir(): yield from self.find_pythons_from_path(version / "bin", True) diff --git a/src/findpython/providers/path.py b/src/findpython/providers/path.py index 8b9ba62..cb4644f 100644 --- a/src/findpython/providers/path.py +++ b/src/findpython/providers/path.py @@ -1,13 +1,22 @@ from __future__ import annotations import os -import typing as t from dataclasses import dataclass from pathlib import Path +import sys +from typing import TYPE_CHECKING from findpython.providers.base import BaseProvider from findpython.python import PythonVersion +if TYPE_CHECKING: + from typing import Iterable + + if sys.version_info >= (3, 11): + from typing import Self + else: + from typing_extensions import Self + @dataclass class PathProvider(BaseProvider): @@ -16,10 +25,10 @@ class PathProvider(BaseProvider): paths: list[Path] @classmethod - def create(cls) -> t.Self | None: + def create(cls) -> Self | None: paths = [Path(path) for path in os.getenv("PATH", "").split(os.pathsep) if path] return cls(paths) - def find_pythons(self) -> t.Iterable[PythonVersion]: + def find_pythons(self) -> Iterable[PythonVersion]: for path in self.paths: yield from self.find_pythons_from_path(path) diff --git a/src/findpython/providers/pyenv.py b/src/findpython/providers/pyenv.py index 5735dd0..a571289 100644 --- a/src/findpython/providers/pyenv.py +++ b/src/findpython/providers/pyenv.py @@ -1,12 +1,21 @@ from __future__ import annotations import os -import typing as t from pathlib import Path +import sys +from typing import TYPE_CHECKING from findpython.providers.base import BaseProvider from findpython.python import PythonVersion +if TYPE_CHECKING: + from typing import Iterable + + if sys.version_info >= (3, 11): + from typing import Self + else: + from typing_extensions import Self + class PyenvProvider(BaseProvider): """A provider that finds python installed with pyenv""" @@ -15,7 +24,7 @@ def __init__(self, root: Path) -> None: self.root = root @classmethod - def create(cls) -> t.Self | None: + def create(cls) -> Self | None: pyenv_root = os.path.expanduser( os.path.expandvars(os.getenv("PYENV_ROOT", "~/.pyenv")) ) @@ -23,7 +32,7 @@ def create(cls) -> t.Self | None: return None return cls(Path(pyenv_root)) - def find_pythons(self) -> t.Iterable[PythonVersion]: + def find_pythons(self) -> Iterable[PythonVersion]: versions_path = self.root.joinpath("versions") if versions_path.exists(): for version in versions_path.iterdir(): diff --git a/src/findpython/providers/rye.py b/src/findpython/providers/rye.py index da29a6e..23a32ae 100644 --- a/src/findpython/providers/rye.py +++ b/src/findpython/providers/rye.py @@ -1,24 +1,33 @@ from __future__ import annotations import os -import typing as t +import sys from pathlib import Path +from typing import TYPE_CHECKING from findpython.providers.base import BaseProvider from findpython.python import PythonVersion from findpython.utils import WINDOWS, safe_iter_dir +if TYPE_CHECKING: + from typing import Iterable + + if sys.version_info >= (3, 11): + from typing import Self + else: + from typing_extensions import Self + class RyeProvider(BaseProvider): def __init__(self, root: Path) -> None: self.root = root @classmethod - def create(cls) -> t.Self | None: + def create(cls) -> Self | None: root = Path(os.getenv("RYE_PY_ROOT", "~/.rye/py")).expanduser() return cls(root) - def find_pythons(self) -> t.Iterable[PythonVersion]: + def find_pythons(self) -> Iterable[PythonVersion]: if not self.root.exists(): return for child in safe_iter_dir(self.root): diff --git a/src/findpython/providers/winreg.py b/src/findpython/providers/winreg.py index dd13a51..e5ef590 100644 --- a/src/findpython/providers/winreg.py +++ b/src/findpython/providers/winreg.py @@ -1,8 +1,9 @@ from __future__ import annotations import platform -import typing as t +import sys from pathlib import Path +from typing import TYPE_CHECKING from packaging.version import Version @@ -10,6 +11,14 @@ from findpython.python import PythonVersion from findpython.utils import WINDOWS +if TYPE_CHECKING: + from typing import Iterable + + if sys.version_info >= (3, 11): + from typing import Self + else: + from typing_extensions import Self + SYS_ARCHITECTURE = platform.architecture()[0] @@ -17,12 +26,12 @@ class WinregProvider(BaseProvider): """A provider that finds Python from the winreg.""" @classmethod - def create(cls) -> t.Self | None: + def create(cls) -> Self | None: if not WINDOWS: return None return cls() - def find_pythons(self) -> t.Iterable[PythonVersion]: + def find_pythons(self) -> Iterable[PythonVersion]: from findpython.pep514tools import findall as pep514_findall env_versions = pep514_findall() diff --git a/tests/conftest.py b/tests/conftest.py index b2bb1bc..4f37ec9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from pathlib import Path from unittest.mock import PropertyMock From 3c2598684f9049e5b8957b63c85fd43eba11c331 Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Mon, 24 Feb 2025 14:58:50 +0800 Subject: [PATCH 2/5] chore: improve type hints --- tests/conftest.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 4f37ec9..bb7bbdc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -21,7 +21,7 @@ def add_python( architecture="64bit", interpreter=None, keep_symlink=False, - ): + ) -> PythonVersion: if version is not None: version = parse(version) executable = Path(executable) @@ -34,16 +34,16 @@ def add_python( executable, version, architecture, interpreter, keep_symlink ) if version is not None: - py_ver._get_version = lambda: version + py_ver._get_version = lambda: version # type:ignore[method-assign] self.versions[executable] = py_ver return py_ver - def version_maker(self, executable, *args, **kwargs): + def version_maker(self, executable, *args, **kwargs) -> PythonVersion: return self.versions[executable] @pytest.fixture() -def mocked_python(tmp_path, monkeypatch): +def mocked_python(tmp_path, monkeypatch) -> _MockRegistry: mocked = _MockRegistry() for python in [ (tmp_path / "python3.7", "3.7.0"), @@ -65,5 +65,5 @@ def mocked_python(tmp_path, monkeypatch): @pytest.fixture(params=[False, True]) -def switch(request): +def switch(request) -> bool: return request.param From fdf0337d4604c442373e13ed090aa70d37ccce55 Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Mon, 24 Feb 2025 15:07:44 +0800 Subject: [PATCH 3/5] chore: remove mypy from dev deps --- pdm.lock | 80 ++------------------------------------------------ pyproject.toml | 1 - 2 files changed, 3 insertions(+), 78 deletions(-) diff --git a/pdm.lock b/pdm.lock index 6cd5e57..d794d59 100644 --- a/pdm.lock +++ b/pdm.lock @@ -2,10 +2,10 @@ # It is not intended for manual editing. [metadata] -groups = ["default", "dev", "tests"] +groups = ["default", "tests"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:f6123e36c730e63eacef3a447cd119c44562eb380535a7648fcfa4cd14656c85" +content_hash = "sha256:a279fe9d01b3a467d5cc6a13d1b17b2d163850cbce221ddb750028acaaef90cf" [[metadata.targets]] requires_python = ">=3.8" @@ -45,69 +45,6 @@ files = [ {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, ] -[[package]] -name = "mypy" -version = "1.14.1" -requires_python = ">=3.8" -summary = "Optional static typing for Python" -groups = ["dev"] -dependencies = [ - "mypy-extensions>=1.0.0", - "tomli>=1.1.0; python_version < \"3.11\"", - "typing-extensions>=4.6.0", -] -files = [ - {file = "mypy-1.14.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:52686e37cf13d559f668aa398dd7ddf1f92c5d613e4f8cb262be2fb4fedb0fcb"}, - {file = "mypy-1.14.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:1fb545ca340537d4b45d3eecdb3def05e913299ca72c290326be19b3804b39c0"}, - {file = "mypy-1.14.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:90716d8b2d1f4cd503309788e51366f07c56635a3309b0f6a32547eaaa36a64d"}, - {file = "mypy-1.14.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2ae753f5c9fef278bcf12e1a564351764f2a6da579d4a81347e1d5a15819997b"}, - {file = "mypy-1.14.1-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:e0fe0f5feaafcb04505bcf439e991c6d8f1bf8b15f12b05feeed96e9e7bf1427"}, - {file = "mypy-1.14.1-cp310-cp310-win_amd64.whl", hash = "sha256:7d54bd85b925e501c555a3227f3ec0cfc54ee8b6930bd6141ec872d1c572f81f"}, - {file = "mypy-1.14.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:f995e511de847791c3b11ed90084a7a0aafdc074ab88c5a9711622fe4751138c"}, - {file = "mypy-1.14.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:d64169ec3b8461311f8ce2fd2eb5d33e2d0f2c7b49116259c51d0d96edee48d1"}, - {file = "mypy-1.14.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ba24549de7b89b6381b91fbc068d798192b1b5201987070319889e93038967a8"}, - {file = "mypy-1.14.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:183cf0a45457d28ff9d758730cd0210419ac27d4d3f285beda038c9083363b1f"}, - {file = "mypy-1.14.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:f2a0ecc86378f45347f586e4163d1769dd81c5a223d577fe351f26b179e148b1"}, - {file = "mypy-1.14.1-cp311-cp311-win_amd64.whl", hash = "sha256:ad3301ebebec9e8ee7135d8e3109ca76c23752bac1e717bc84cd3836b4bf3eae"}, - {file = "mypy-1.14.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:30ff5ef8519bbc2e18b3b54521ec319513a26f1bba19a7582e7b1f58a6e69f14"}, - {file = "mypy-1.14.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:cb9f255c18052343c70234907e2e532bc7e55a62565d64536dbc7706a20b78b9"}, - {file = "mypy-1.14.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:8b4e3413e0bddea671012b063e27591b953d653209e7a4fa5e48759cda77ca11"}, - {file = "mypy-1.14.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:553c293b1fbdebb6c3c4030589dab9fafb6dfa768995a453d8a5d3b23784af2e"}, - {file = "mypy-1.14.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:fad79bfe3b65fe6a1efaed97b445c3d37f7be9fdc348bdb2d7cac75579607c89"}, - {file = "mypy-1.14.1-cp312-cp312-win_amd64.whl", hash = "sha256:8fa2220e54d2946e94ab6dbb3ba0a992795bd68b16dc852db33028df2b00191b"}, - {file = "mypy-1.14.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:92c3ed5afb06c3a8e188cb5da4984cab9ec9a77ba956ee419c68a388b4595255"}, - {file = "mypy-1.14.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:dbec574648b3e25f43d23577309b16534431db4ddc09fda50841f1e34e64ed34"}, - {file = "mypy-1.14.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:8c6d94b16d62eb3e947281aa7347d78236688e21081f11de976376cf010eb31a"}, - {file = "mypy-1.14.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d4b19b03fdf54f3c5b2fa474c56b4c13c9dbfb9a2db4370ede7ec11a2c5927d9"}, - {file = "mypy-1.14.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:0c911fde686394753fff899c409fd4e16e9b294c24bfd5e1ea4675deae1ac6fd"}, - {file = "mypy-1.14.1-cp313-cp313-win_amd64.whl", hash = "sha256:8b21525cb51671219f5307be85f7e646a153e5acc656e5cebf64bfa076c50107"}, - {file = "mypy-1.14.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:7084fb8f1128c76cd9cf68fe5971b37072598e7c31b2f9f95586b65c741a9d31"}, - {file = "mypy-1.14.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:8f845a00b4f420f693f870eaee5f3e2692fa84cc8514496114649cfa8fd5e2c6"}, - {file = "mypy-1.14.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:44bf464499f0e3a2d14d58b54674dee25c031703b2ffc35064bd0df2e0fac319"}, - {file = "mypy-1.14.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c99f27732c0b7dc847adb21c9d47ce57eb48fa33a17bc6d7d5c5e9f9e7ae5bac"}, - {file = "mypy-1.14.1-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:bce23c7377b43602baa0bd22ea3265c49b9ff0b76eb315d6c34721af4cdf1d9b"}, - {file = "mypy-1.14.1-cp38-cp38-win_amd64.whl", hash = "sha256:8edc07eeade7ebc771ff9cf6b211b9a7d93687ff892150cb5692e4f4272b0837"}, - {file = "mypy-1.14.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:3888a1816d69f7ab92092f785a462944b3ca16d7c470d564165fe703b0970c35"}, - {file = "mypy-1.14.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:46c756a444117c43ee984bd055db99e498bc613a70bbbc120272bd13ca579fbc"}, - {file = "mypy-1.14.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:27fc248022907e72abfd8e22ab1f10e903915ff69961174784a3900a8cba9ad9"}, - {file = "mypy-1.14.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:499d6a72fb7e5de92218db961f1a66d5f11783f9ae549d214617edab5d4dbdbb"}, - {file = "mypy-1.14.1-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:57961db9795eb566dc1d1b4e9139ebc4c6b0cb6e7254ecde69d1552bf7613f60"}, - {file = "mypy-1.14.1-cp39-cp39-win_amd64.whl", hash = "sha256:07ba89fdcc9451f2ebb02853deb6aaaa3d2239a236669a63ab3801bbf923ef5c"}, - {file = "mypy-1.14.1-py3-none-any.whl", hash = "sha256:b66a60cc4073aeb8ae00057f9c1f64d49e90f918fbcef9a977eb121da8b8f1d1"}, - {file = "mypy-1.14.1.tar.gz", hash = "sha256:7ec88144fe9b510e8475ec2f5f251992690fcf89ccb4500b214b4226abcd32d6"}, -] - -[[package]] -name = "mypy-extensions" -version = "1.0.0" -requires_python = ">=3.5" -summary = "Type system extensions for programs checked with the mypy type checker." -groups = ["dev"] -files = [ - {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"}, - {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, -] - [[package]] name = "packaging" version = "24.2" @@ -154,7 +91,7 @@ name = "tomli" version = "2.2.1" requires_python = ">=3.8" summary = "A lil' TOML parser" -groups = ["dev", "tests"] +groups = ["tests"] marker = "python_version < \"3.11\"" files = [ {file = "tomli-2.2.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:678e4fa69e4575eb77d103de3df8a895e1591b48e740211bd1067378c69e8249"}, @@ -190,14 +127,3 @@ files = [ {file = "tomli-2.2.1-py3-none-any.whl", hash = "sha256:cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc"}, {file = "tomli-2.2.1.tar.gz", hash = "sha256:cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff"}, ] - -[[package]] -name = "typing-extensions" -version = "4.12.2" -requires_python = ">=3.8" -summary = "Backported and Experimental Type Hints for Python 3.8+" -groups = ["dev"] -files = [ - {file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"}, - {file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"}, -] diff --git a/pyproject.toml b/pyproject.toml index 9fbcff7..b8c2e30 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,6 @@ package-dir = "src" [tool.pdm.dev-dependencies] tests = ["pytest"] -dev = ["mypy"] [build-system] requires = ["pdm-backend"] From b6927db2838e4eb93cd3ebf9c24e59f07eae083c Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Mon, 10 Mar 2025 21:40:15 +0800 Subject: [PATCH 4/5] ci: remove style check --- .github/workflows/ci.yml | 4 ---- src/findpython/providers/winreg.py | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43dd9e4..ac28dd7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,10 +52,6 @@ jobs: - name: Install packages run: pdm install - - name: Check Style - run: | - pdm run pip install pre-commit - pdm run pre-commit run --all-files - name: Run Integration run: pdm run findpython --all -v - name: Run Tests diff --git a/src/findpython/providers/winreg.py b/src/findpython/providers/winreg.py index e5ef590..dd6c9c4 100644 --- a/src/findpython/providers/winreg.py +++ b/src/findpython/providers/winreg.py @@ -1,7 +1,6 @@ from __future__ import annotations import platform -import sys from pathlib import Path from typing import TYPE_CHECKING @@ -12,6 +11,7 @@ from findpython.utils import WINDOWS if TYPE_CHECKING: + import sys from typing import Iterable if sys.version_info >= (3, 11): From 97e57a815111dadb305f4489ef1e274c6bbde434 Mon Sep 17 00:00:00 2001 From: Waket Zheng Date: Mon, 10 Mar 2025 21:48:02 +0800 Subject: [PATCH 5/5] chore: only imports sys when type checking --- src/findpython/providers/asdf.py | 2 +- src/findpython/providers/base.py | 2 +- src/findpython/providers/macos.py | 2 +- src/findpython/providers/path.py | 2 +- src/findpython/providers/pyenv.py | 2 +- src/findpython/providers/rye.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/findpython/providers/asdf.py b/src/findpython/providers/asdf.py index ad64b68..77a0836 100644 --- a/src/findpython/providers/asdf.py +++ b/src/findpython/providers/asdf.py @@ -2,13 +2,13 @@ import os from pathlib import Path -import sys from typing import TYPE_CHECKING from findpython.providers.base import BaseProvider from findpython.python import PythonVersion if TYPE_CHECKING: + import sys from typing import Iterable if sys.version_info >= (3, 11): diff --git a/src/findpython/providers/base.py b/src/findpython/providers/base.py index c765ead..1e34891 100644 --- a/src/findpython/providers/base.py +++ b/src/findpython/providers/base.py @@ -1,7 +1,6 @@ from __future__ import annotations import abc -import sys import logging from pathlib import Path from typing import TYPE_CHECKING @@ -10,6 +9,7 @@ from findpython.utils import path_is_python, safe_iter_dir if TYPE_CHECKING: + import sys from typing import Callable, Iterable if sys.version_info >= (3, 11): diff --git a/src/findpython/providers/macos.py b/src/findpython/providers/macos.py index be7aafc..eca0b23 100644 --- a/src/findpython/providers/macos.py +++ b/src/findpython/providers/macos.py @@ -1,13 +1,13 @@ from __future__ import annotations from pathlib import Path -import sys from typing import TYPE_CHECKING from findpython.providers.base import BaseProvider from findpython.python import PythonVersion if TYPE_CHECKING: + import sys from typing import Iterable if sys.version_info >= (3, 11): diff --git a/src/findpython/providers/path.py b/src/findpython/providers/path.py index cb4644f..9c9be6c 100644 --- a/src/findpython/providers/path.py +++ b/src/findpython/providers/path.py @@ -3,13 +3,13 @@ import os from dataclasses import dataclass from pathlib import Path -import sys from typing import TYPE_CHECKING from findpython.providers.base import BaseProvider from findpython.python import PythonVersion if TYPE_CHECKING: + import sys from typing import Iterable if sys.version_info >= (3, 11): diff --git a/src/findpython/providers/pyenv.py b/src/findpython/providers/pyenv.py index a571289..91b8f65 100644 --- a/src/findpython/providers/pyenv.py +++ b/src/findpython/providers/pyenv.py @@ -2,13 +2,13 @@ import os from pathlib import Path -import sys from typing import TYPE_CHECKING from findpython.providers.base import BaseProvider from findpython.python import PythonVersion if TYPE_CHECKING: + import sys from typing import Iterable if sys.version_info >= (3, 11): diff --git a/src/findpython/providers/rye.py b/src/findpython/providers/rye.py index 23a32ae..412ee0e 100644 --- a/src/findpython/providers/rye.py +++ b/src/findpython/providers/rye.py @@ -1,7 +1,6 @@ from __future__ import annotations import os -import sys from pathlib import Path from typing import TYPE_CHECKING @@ -10,6 +9,7 @@ from findpython.utils import WINDOWS, safe_iter_dir if TYPE_CHECKING: + import sys from typing import Iterable if sys.version_info >= (3, 11):