Building on the <thread above> but a slightly diff...
# general
a
Building on the thread above but a slightly different problem: I now have mypy 1.1.1 configured correctly. When I do
pants check my_file.py
mypy raises things that I expect - great! I now configured a pre-commit hook as such:
repos:
- repo: local
hooks:
- id: check
name: check
entry: pants check
language: system
files: ^.*.(py|pyi)$
When I now git add and git commit the same file mypy fails with this error:
.cache/pex_root/venvs/5cb0b2dcd2357da2bbde0d877bde9b817c555a3e/fde49d60105c0ef9833901ddf249f36d7deded9a/lib/python3.11/site-packages/numpy/__init__.pyi641 error: Positional-only parameters are only supported in Python 3.8 and greater
This problem comes from an old mypy version and should be already fixed (ref). I am puzzled where this discrepancy of different mypy version stems from and would be excited if someone could help me out here!
โœ… 1
r
So you have configured the lockfile etc? Are you able to run successfully without the hook?
Copy code
pants check ::
pants.toml should have
[mypy]
with custom version like this
Copy code
[mypy]
version = "mypy==1.1.1"
lockfile = "<your_custom_path">
a
[mypy]
version = "mypy==1.1.1"
args = ["--non-interactive", "--install-types"]
extra_type_stubs = ["types-requests==2.25.12"]
# Set this to a path, then run
pants generate-lockfiles --resolve=mypy-extra-type-stubs
.
extra_type_stubs_lockfile = "3rdparty/python/mypy_extra_type_stubs.lock"
lockfile = "3rdparty/mypy_lockfile.txt"
and I ran
pants generate-lockfiles ::
and
pants export::
.
pants check ::
runs successfully.
r
Do you have also python 3.7 as interpreter constraints somewhere in pants.toml?
a
Nope
[python]
tailor_pex_binary_targets = false
interpreter_constraints = ["CPython==3.11.2"]
enable_resolves = true
r
Ah ok! Nuke the cache? Yeah not ideal but I donโ€™t know what else could be wrong
๐Ÿ‘€ 1
a
Nuke the cache is deleting .pants.d, .pids, dist and the locks?
r
there is more as you can see in the log.
Copy code
.cache/pex_root/venvs/5cb0b2dcd2357da2bbde0d877bde9b817c555a3e/fde49d60105c0ef9833901ddf249f36d7deded9a/lib/python3.11/site-packages/numpy/__init__.pyi:641: error: Positional-only parameters are only supported in Python 3.8 and greater
a
ah thanks!
r
I will first try with just nuking
pex_root
but there are more https://www.pantsbuild.org/docs/using-pants-in-ci
Also use something like this for
entry
in the hook so that it only runs on the changed files not your whole repo whenever you commit
Copy code
pants \
  --changed-since=origin/main \
  --changed-dependees=transitive check
a
So deleting the cache for pants and pre-commit didn't do anything
r
Something wrong with your pre-commit set-up then. This is how it looks like for me. Ah you need to use
pass_filenames: false
Copy code
- repo: local
    hooks:
      - id: lint-check
        name: Checking source files formatting
        entry: "./pants --changed-since=main --changed-dependees=transitive lint"
        language: script
        types: [python]
        pass_filenames: false
        verbose: true
a
That did the trick! Wow, thank you so much Shantanu!
๐Ÿ™Œ 1