https://pantsbuild.org/ logo
#general
Title
# general
a

average-father-89924

03/17/2023, 12:27 PM
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

refined-addition-53644

03/17/2023, 1:08 PM
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

average-father-89924

03/17/2023, 1:15 PM
[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

refined-addition-53644

03/17/2023, 1:16 PM
Do you have also python 3.7 as interpreter constraints somewhere in pants.toml?
a

average-father-89924

03/17/2023, 1:17 PM
Nope
[python]
tailor_pex_binary_targets = false
interpreter_constraints = ["CPython==3.11.2"]
enable_resolves = true
r

refined-addition-53644

03/17/2023, 1:18 PM
Ah ok! Nuke the cache? Yeah not ideal but I don’t know what else could be wrong
πŸ‘€ 1
a

average-father-89924

03/17/2023, 1:18 PM
Nuke the cache is deleting .pants.d, .pids, dist and the locks?
r

refined-addition-53644

03/17/2023, 1:20 PM
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

average-father-89924

03/17/2023, 1:20 PM
ah thanks!
r

refined-addition-53644

03/17/2023, 1:22 PM
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

average-father-89924

03/17/2023, 1:36 PM
So deleting the cache for pants and pre-commit didn't do anything
r

refined-addition-53644

03/17/2023, 1:37 PM
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

average-father-89924

03/17/2023, 1:38 PM
That did the trick! Wow, thank you so much Shantanu!
πŸ™Œ 1
2 Views