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

pip_parse: lockfile for build dependencies in repository rule #1325

Open
keith opened this issue Jul 17, 2023 · 9 comments
Open

pip_parse: lockfile for build dependencies in repository rule #1325

keith opened this issue Jul 17, 2023 · 9 comments

Comments

@keith
Copy link
Member

keith commented Jul 17, 2023

Since PEP 518 projects can specify their build system requirements in their pyproject.toml file. Currently this is not included in the pip-compile and therefore can lead to non-reproducible issues. This happened in the wild today because pyyaml depends on cython but didn't pin its major version, so when cython pushed an incompatible version this broke if you were including it in bazel. One of the potential workarounds is to install the compatible cython version in the venv before installing your requirements, which I also don't believe is possible. I believe supporting this would require pip-tools to also support this option, which is potentially implemented by jazzband/pip-tools#1681

@keith
Copy link
Member Author

keith commented Jul 18, 2023

Another potentially option is multiple requirements files. I believe 1 method that would work is if there was a tooling requirements file that was installed first, and then the normal requirements file which was installed inside the venv used with the first requirements file.

@groodt
Copy link
Collaborator

groodt commented Jul 18, 2023

There are a number of conflated issues here. One thing to note is that pip does not support pinning build dependencies. See: https://discuss.python.org/t/no-way-to-pin-build-dependencies/29833

Generally, the pip_parse rule is always going to be non-hermetic since it runs inside repository rules. If your dependency closure includes an sdist, pip will generally build with "build-isolation", where the build dependencies are installed into a temporary virtual environment. This happens on your machine and isn't managed by bazel. Typically, this is what you would normally want. However, sometimes there are missed dependencies specified in a dependency, or, as you've encountered, you wish to prepare the build environment ahead of time. For this, pip provides --no-build-isolation. You are able to provide this to the bazel repository rule, and you are able to prepare a build environment ahead of time on your build host. This isn't managed by bazel however.

I suspect the above is not what you want to hear, but the flexibility and impurity of the full Python ecosystem that is comprised of Turing complete and non-declarative build specs does not fit very well with the pure and declarative / hermetic world of bazel.

Some possible options that you may wish to consider:

  • Try rules_pycross which will run builds outside of a repository rule context
  • Make use of a private package registry / wheel-house / cheese-shop. If you only make use of pre-built wheels in your dependency closure, then bazel will not invoke the build+unpack behaviour of pip and you'll be able to use --only-binary :all: in your requirements.txt. In this configuration, bazel will simply download and unpack wheels and you will not need to be concerned with unmanaged build dependencies.

@groodt groodt changed the title Support PEP 518 pip_parse: lockfile for build dependencies in repository rule Jul 18, 2023
@keith
Copy link
Member Author

keith commented Jul 18, 2023

In the linked thread the solution of using PIP_CONSTRAINT=foo.txt might actually be a good path forward for this. I verified that does work for this case.

@groodt
Copy link
Collaborator

groodt commented Jul 19, 2023

Great! Yes, if that works for you, we may just consider that the recommended workaround and eventually close this issue.

@keith
Copy link
Member Author

keith commented Jul 19, 2023

I'm not sure that's possible to integrate with rules_python today though

Copy link

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days.
Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_python!

@github-actions github-actions bot added the Can Close? Will close in 30 days if there is no new activity label Jan 15, 2024
Copy link

This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"

@aignas aignas reopened this Feb 16, 2024
@aignas
Copy link
Collaborator

aignas commented Feb 16, 2024

Reopening as the feature for including build deps in pip-tools got merged so the definition of done here could be to ensure that it is available in rules_python.

@aignas aignas added help wanted type: pip and removed Can Close? Will close in 30 days if there is no new activity labels Feb 16, 2024
Copy link

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days.
Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_python!

@github-actions github-actions bot added the Can Close? Will close in 30 days if there is no new activity label Aug 14, 2024
@aignas aignas removed the Can Close? Will close in 30 days if there is no new activity label Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants