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

refactor!(bzlmod): introduce pypi.install extension #2278

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

aignas
Copy link
Collaborator

@aignas aignas commented Oct 8, 2024

With this PR we are introducing a new extension for managing PyPI dependencies
and it seems that we would fix #2268 in doing so. The code has been sitting
around for long enough so that we have ironed out most of the bigger bugs
already and the maintainers have agreed for long enough that pip.parse is
not the best named, so I have chosen pypi.install.

This should not actively break the code and will make some of the experimental
parameters noop. This could yield to weird failures in cases where people are
building docker containers, so I am thinking that we should potentially add
a helpful error message prompting the users to migrate. However I am not
sure how that works out when multiple module versions are at play in the same
module graph.

Work towards #260

With this PR we are introducing a new extension for managing PyPI dependencies
and it seems that we would fix bazelbuild#2268 in doing so. The code has been sitting
around for long enough so that we have ironed out most of the bigger bugs
already and the maintainers have agreed for long enough that pip.parse is
not the best named, so I have chosen pypi.install.

This should not actively break the code and will make some of the experimental
parameters noop. This could yield to weird failures in cases where people are
building docker containers, so I am thinking that we should potentially add
a helpful error message prompting the users to migrate. However I am not
sure how that works out when multiple module versions are at play in the same
module graph.
@aignas aignas marked this pull request as ready for review October 9, 2024 09:10
@aignas
Copy link
Collaborator Author

aignas commented Oct 9, 2024

I don't know if I am super happy about the breaking change here, but I do think fixing the bug here takes the priority. Let me know what you think. I think we have discussed enough times and agree on the new better name here.

Copy link
Contributor

@rickeylev rickeylev left a comment

Choose a reason for hiding this comment

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

re: new extension and backwards compatibility:

The main thing I have in mind is how we transition from pip.parse to pypi.install. Some specific questions:

  1. If pypi.install is a drop-in replacement, why does it need to be a separate extension?
  2. Why can't we transition pip.parse to the new semantics under-the-hood? I know the pip.parse name isn't as nice as pypi.install, but that's just aesthetics.
  3. Is there something pip.parse can do that pypi.install can't do, or vice versa?

@@ -27,6 +27,10 @@ A brief description of the categories of changes:
### Changed
* (toolchains) `py_runtime.implementation_name` now defaults to `cpython`
(previously it defaulted to None).
* (bzlmod) **BREAKING** The `experimental_index_url` feature has been removed
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: move the breaking entries to the top of the changed section

incompatible ways if major design flaws are found.
:::

`pypi.install` provides almost a drop-in replacement for the `pip.parse` extension:
Copy link
Contributor

Choose a reason for hiding this comment

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

Have this link to the api doc

to set an environment variable `RULES_PYTHON_OS_ARCH_LOCK_FILE=0` which will
become default in the next release.

Fetching the distribution information from the PyPI allows `rules_python` to
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Fetching the distribution information from the PyPI allows `rules_python` to
Fetching the distribution information from PyPI allows `rules_python` to


Fetching the distribution information from the PyPI allows `rules_python` to
know which `whl` should be used on which target platform and it will determine
that by parsing the `whl` filename based on [PEP600], [PEP656] standards. This
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
that by parsing the `whl` filename based on [PEP600], [PEP656] standards. This
that by parsing the `whl` filename based on [PEP600] and [PEP656] standards. This

docs/pypi-dependencies.md Show resolved Hide resolved
@@ -461,7 +464,7 @@ def _pip_impl(module_ctx):
is_extension_reproducible = True

for mod in module_ctx.modules:
for pip_attr in mod.tags.parse:
for pip_attr in (getattr(mod.tags, "parse", None) or getattr(mod.tags, "install")):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for pip_attr in (getattr(mod.tags, "parse", None) or getattr(mod.tags, "install")):
for pip_attr in (getattr(mod.tags, "parse", None) or mod.tags.install):

@aignas
Copy link
Collaborator Author

aignas commented Oct 10, 2024

Taking a step back a little as I am not sure that this should necessarily be merged like this.

  1. To fix the bug, we could instead only allow root modules to enable experimental_index_url for now.
  2. The missing pieces that the new code does not support yet:
    1. Pull dependencies when hashes are not specified. I've seen many people in the wild using pip freeze to generate the requirements files and I think we should just get all of the wheels that we can find if the hashes are not present in the requirements files. This can be done as a separate PR.
    2. Direct URL dependency handling - right now we assume that we always should contact the SimpleAPI. If the URL is in the requirements file, we should just use it.

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.

experimental_index_url in dependency tree breaks other pip.parse includes
2 participants