Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to guarantee consistent versions for (transitive) dependencies between tools (particularly mypy) and runtime resolves #16044

Closed
huonw opened this issue Jul 4, 2022 · 1 comment
Labels
backend: Python Python backend-related issues bug

Comments

@huonw
Copy link
Contributor

huonw commented Jul 4, 2022

Describe the bug

We've got a codebase that uses mypy extensively, and various plugins, and we'd prefer if we had good methods for having the versions of our mypy plugin libraries match the ones used at runtime.

For instance:

# pyproject.toml
[tool.mypy]
plugins = ["pydantic.mypy", "sqlmypy", "strawberry.ext.mypy_plugin"]
...

Two of these come from libraries also used at runtime (pydantic and strawberry-graphql) and thus it'd be good to be using a consistent version globally: if we have mypy using plugins for different versions of our runtime libraries who knows if type checking passing is meaningful.

There's a few options:

  • write extra_requirements = ["pydantic==...", ...] etc. but that duplicates the version configuration, and doesn't guarantee identical versions of transitive dependencies without listing them all out by hand.
  • use source_plugins pointing to the relevant python_requirement target (which isn't what it's documented to be used for), which at least deduplicates version configuration for those direct requirements, but also doesn't guarantee identical versions of transitive dependencies.

The second is slightly better than the first, so that's what we've tried so far despite it seemingly being not a proper use of source_plugins. For instance:

[GLOBAL]
pants_version = "2.12.0"

backend_packages = [
  "pants.backend.python",
  "pants.backend.python.typecheck.mypy",
]

[python]
interpreter_constraints = ["CPython==3.9.*"]
enable_resolves = true

[mypy]
lockfile = "3rdparty/python/mypy.lock"
source_plugins = [
  "//:pydantic",
]

[anonymous-telemetry]
enabled = false

With top-level BUILD that simulates a transitive dependency typing-extensions that's stuck on an older version:

python_requirement(name="pydantic", requirements=["pydantic==1.9.0"])
python_requirement(name="typing-extensions", requirements=["typing-extensions==4.0.0"])

This mostly works, after running ./pants generate-lockfiles, we have mypy.lock containing:

...
          "project_name": "pydantic",
          "version": "1.9"
...
          "project_name": "typing-extensions",
          "version": "4.3"
...
  "requirements": [
    "mypy==0.910",
    "pydantic==1.9.0"
  ],
...

However, note that typing-extensions is missing from the requirements, and indeed the pinned version of the transitive dependency of pydantic is different to the one in the runtime default resolve (which is just "version": "4").

Notes:

As always, thanks for pants!

Pants version
2.12.0

OS
macOS

Additional info

Reproducing example: https://github.com/huonw/pants-tool-pinning

@huonw huonw added the bug label Jul 4, 2022
@thejcannon thejcannon added the backend: Python Python backend-related issues label Aug 19, 2022
@benjyw
Copy link
Contributor

benjyw commented Mar 17, 2023

This is addressed in a different way by #18481, which allows a tool to be installed from a user resolve. In fact, the version/extra_requirements options are now deprecated, and we want there to just be one kind of lockfile, that can be reused for tools as well as user code.

@benjyw benjyw closed this as completed Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Python Python backend-related issues bug
Projects
None yet
Development

No branches or pull requests

3 participants