abravalheri / validate-pyproject

Validation library for simple check on `pyproject.toml`
https://validate-pyproject.readthedocs.io/
Mozilla Public License 2.0
130 stars 12 forks source link

Apply assorted repo-review rules #191

Closed DimitriPapadopoulos closed 3 months ago

DimitriPapadopoulos commented 3 months ago

Follow-up of https://github.com/abravalheri/validate-pyproject/pull/187#issuecomment-2273640670.

DimitriPapadopoulos commented 3 months ago

I don't understand the MyPy errors in CI:

MyPy 1.11.1 errors in CI ``` typecheck: commands[0]> python -m mypy --pretty --show-error-context src src/validate_pyproject/_tomllib.py:10: error: Unused "type: ignore" comment [unused-ignore] from toml import TomlDecodeError as TOMLDecodeError # type: i... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~... src/validate_pyproject/_tomllib.py:10: error: Library stubs not installed for "toml" [import-untyped] from toml import TomlDecodeError as TOMLDecodeError # type: i... ^ src/validate_pyproject/_tomllib.py:10: note: Error code "import-untyped" not covered by "type: ignore" comment src/validate_pyproject/_tomllib.py:10: note: Hint: "python3 -m pip install types-toml" src/validate_pyproject/_tomllib.py:10: note: (or run "mypy --install-types" to install all missing stub packages) src/validate_pyproject/_tomllib.py:10: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports src/validate_pyproject/_tomllib.py:10: error: Name "TOMLDecodeError" already defined (possibly by an import) [no-redef] from toml import TomlDecodeError as TOMLDecodeError # type: i... ^ src/validate_pyproject/_tomllib.py:10: note: Error code "no-redef" not covered by "type: ignore" comment src/validate_pyproject/_tomllib.py:11: error: Unused "type: ignore" comment [unused-ignore] from toml import loads # type: ignore[assignment] ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/validate_pyproject/_tomllib.py:11: error: Name "loads" already defined (possibly by an import) [no-redef] from toml import loads # type: ignore[assignment] ^ src/validate_pyproject/_tomllib.py:11: note: Error code "no-redef" not covered by "type: ignore" comment src/validate_pyproject/formats.py:86: error: Unused "type: ignore[import-untyped]" comment [unused-ignore] from setuptools._vendor.packaging import ( # type: ignore[imp... ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~... src/validate_pyproject/formats.py:209: error: Unused "type: ignore" comment [unused-ignore] from trove_classifiers import ( # type: ignore[import-not-found] ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ```

I cannot reproduce them locally:

$ python -m mypy --pretty --show-error-context src
Success: no issues found in 21 source files
$ 
$ mypy --version
mypy 1.11.1 (compiled: yes)
$ 

Perhaps related to pinned-down versions of dependencies?

typecheck: fastjsonschema==2.20.0,importlib_resources==6.4.0,mypy==1.11.1,mypy-extensions==1.0.0,packaging==24.1,pip==24.1,setuptools==70.1.0,tomli==2.0.1,trove-classifiers==2024.7.2,typing_extensions==4.12.2,validate-pyproject @ file:///tmp/cirrus-ci-build/dist/validate_pyproject-0.18.post1.dev14%2Bgc585ce5-py3-none-any.whl#sha256=6c3d97a42127e4c1af7f88fcf3b52101a7b3a433b7c32c04ef81f74588857fec,wheel==0.43.0
abravalheri commented 3 months ago

Thank you very much!

So with this pre-commit will autofix unused type: ignore annotations, right?

henryiii commented 3 months ago

except prettier, no plans to use nodejs in the CI for a Python project

If you know a good markdown linter or formatter alternative, happy to add it in the list of known list.

So with this pre-commit will autofix unused type: ignore annotations, right?

No, you need something that reads python files for that. There are several options, but I'm personally waiting to see what the Ruff team produces. They are working on a type checker; last I heard it was going to be part of Ruff (and the prototype is part of Ruff), though I'm curious to see if they stick with that - Ruff famously doesn't require or use any dependencies, but a type checker does need dependencies and stub files.

abravalheri commented 3 months ago

If you know a good markdown linter or formatter alternative, happy to add it in the list of known list.

I haven't tested mdformat yet so I cannot voucher for it, but it comes from the executable books folk, which usually do nice stuff.

DimitriPapadopoulos commented 3 months ago

So with this pre-commit will autofix unused type: ignore annotations, right?

No, you need something that reads python files for that. There are several options, but I'm personally waiting to see what the Ruff team produces. They are working on a type checker; last I heard it was going to be part of Ruff (and the prototype is part of Ruff), though I'm curious to see if they stick with that - Ruff famously doesn't require or use any dependencies, but a type checker does need dependencies and stub files.

This PR modifies the MyPy options so that MyPy catches unused type: ignore annotations when run. However, I don't see pre-commit running MyPy; it would probably involve adding this hook: https://github.com/pre-commit/mirrors-mypy. On the other hand, one of the GitHub CI jobs does run MyPy — maybe through tox, I don't know how it's done.

henryiii commented 2 months ago

I'm a bit worried about mdformat. It's not been touched in months. It seems to be worked on by the author of tomli, who's not make a public commit since April. It does have plugins for lots of things, but the plugin system isn't configurable; this is particularly bad when some plugins change the target (what happens if mdformat-gfm and mdformat-rtd are both installed?). Happy to add it to the list of supported formatters, but I'm probably not going to propose it as an alternative just yet.

I know people at executable books, so might ask around.