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

Use modern rules_python and expect users to provide the mypy library themselves #98

Merged
merged 10 commits into from
Feb 13, 2024

Conversation

martis42
Copy link
Contributor

@martis42 martis42 commented Feb 4, 2024

New version of #82

As requested, rules_python is now the latest version still supporting Bazel 5.

There is still no default version for mypy, as the discussion about this is still ongoing.
I still believe there should be no default version.

We don't use `maybe` for py_repositories.bzl as maybe can't be invoked
recursively and the functions provided by rules_python already use it
internally
While using a variable to construct the URLs is the approach with
lower maintenance, using plain strings is required to allow Renovate to
understand them.
This is a recent version supporting Bazel 6 and the forward path for
managing external dependencies based on `pip_parse`. We don't use the
latest version as rules_python >= 0.19.0 is no longer compatible to
Bazel 4.x and it might still be too early for some users of this project
for this step.

Noteworthy changes:
- Use `pip_parse` instead of deprecated `pip_install`. Consequently, users
  now have to provide a fully resolved requirements file for mypy. This means,
  there is no more default mypy shipped with this project. Users always
  have to provide their own mypy. The mypy tracked in third_party is used
  solely for testing.
- We use a hermetic Python 3.8 toolchain from rules_python. Strictly speaking
  a resolved requirements file is only valid for the Python interpreter and
  the platform it was created for. As far as we now mypy has no platform
  specific dependencies. And even if this changes, rules_python offers
  a feature for registering platform specific requirement files. However,
  some mypy versions have dependencies which are only valid for specific
  Python versions (e.g. `typed-ast`). To ensure the project behaves the same
  for each developer, we use a hermetic Python toolchain fixing the Python
  version independent from the Python interpreter on the developer host.
Users are expected to provide mypy as this project cannot provide a version
which matches all possible user use cases.
Until now users had to provide a resolved requirements file. This is
however an unnecessarily complex model. It exposes to the user that this
projects uses rules_python to manage its dependencies in a specific way.
The more natural solution is that we expect the user to provide a mypy
library matching the users Python toolchain and expectations.
On top this eases integrating this project into other workspaces as less
interaction via macros is required.
Using the internal testing mypy as default for the mypy label_flag forces
users to resolve `mypy_integration_pip_deps` which is not supposed to be
relevant for them. To prevent this we set an empty library as default for
the mypy label_flag to ensure users provide their own mypy and to
decouple them from `mypy_integration_pip_deps`.
Copy link
Collaborator

@adzenith adzenith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you!

README.md Outdated
this file to the `deps()` function in `@mypy_integration//repositories:deps.bzl`, which below is named
`mypy_integration_deps(...)`:
`mypy_integration` expects the user to provide the `mypy` dependency.
Given not every mypy version is compatible to all Python versions and mypy's transitive dependencies can differ based on the Python version `mypy_integration` cannot offer a `mypy` which satisfies all potential users.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Given not every mypy version is compatible to all Python versions and mypy's transitive dependencies can differ based on the Python version `mypy_integration` cannot offer a `mypy` which satisfies all potential users.
Given not every mypy version is compatible to all Python versions and mypy's transitive dependencies can differ based on the Python version, `mypy_integration` cannot offer a `mypy` which satisfies all potential users.

Copy link
Contributor Author

@martis42 martis42 Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix this in another PR so this large PR can be merged without a new review.
I misinterpreted the green status as merge ready. Will fix this asap.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right sorry, at work when I approve a PR the author hits merge when they're ready, so here out of habit I approved and then didn't hit merge. I'm happy to merge whenever you're ready.

@adzenith adzenith merged commit 4f56eb2 into bazel-contrib:main Feb 13, 2024
1 check passed
@adzenith
Copy link
Collaborator

thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants