-
Notifications
You must be signed in to change notification settings - Fork 543
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
patch a pip_install
#553
Comments
Hey @knzivid Have you considered writing a small shim library which consumes the pip requirement you need and depending on that in your repository instead? |
The python file I intend to patch is not a part of the public interface. By a shim, do you mean a wrapper that calls this python module, but with my customizations? |
Yes, I think Henry means basically that. I think wouldn't work well though if you wish that all packages in your target's transitive closer see the customization, as they of course wouldn't import the wrapper. |
I've been able to modify the edit: |
@UebelAndre , do you have a PR for your wheel patches via annotations? If not, I have an internal patch that I can clean up and put up a PR. My internal patch also works with annotations post build. I don't know how one would implement pre-build patches because it would require intercepting |
I prefer a user-space solution, similar to this in the JVM ecosystem: I believe it's entirely reasonable to want to patch wheels (and possibly sdist), but Im not really a massive fan of the present "annotation" approach. Is there a way to create this functionality without using the annotations? |
Can you expand on what you don't like about the "annotation" approach and what "bazel_jar_jar" does that you prefer? |
I do not, I was able to use the new |
@philsc - That would be very helpful for me. I am also interested in patching python packages after they are built. |
@creste , apologies for the delay. Here are the "non-cleaned-up" patches: https://github.com/frc971/971-Robot-Code/tree/master/third_party/rules_python It's not ideal, but this works for us at the moment. I ended up abandoning the annotations approach because @groodt convinced me to avoid adding more annotations features. Instead, I am working on a proposal for a different approach. I am finding less time for that proposal than I was hoping so I don't have anything to show you, unfortunately. |
@philsc - Thank you! That is extremely helpful! |
The patches above are for python_rules v0.16.1. There's been significant changes to the wheel installer since then. I think there's an easier way to go about this, especially if the source for the package is open on GitHub.
You're probably going to do the first 2 steps anyways to submit a PR to the source. |
For anyone interested, I adapted @philsc's patch to the latest rules_python release, v0.24.0. Which allows you to do this: http_archive(
name = "rules_python",
patch_args = ["-p1"],
patches = ["//path/to:patch_wheels.patch"],
sha256 = "0a8003b044294d7840ac7d9d73eef05d6ceb682d7516781a4ec62eeb34702578",
strip_prefix = "rules_python-0.24.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.24.0/rules_python-0.24.0.tar.gz",
)
pip_parse(
...
# Assumes `-p1` for all patch files.
patches = {
"foo-pkg": [
"//path/to/some:patch",
"//path/to/some/other:patch",
],
},
) |
forward ported patch: patch_wheels_0.26.0.patch |
Support of wheel patching should work on |
FYI, for legacy WORKSPACE users it is technically possible to pass whl_patches argument to install_deps() call in your WORKSPACE. The API is not something we want to make a promise to maintain backwards compatibility for, hence the documentation that it is internal use only. As we evolve the APIs to better support patching and cross-platform dependency resolution, this may change, so please be warned, but at least this can give a stop-gap solution without requiring users to patch rules_python itself. The source code documenting on what you would need to pass is https://github.com/bazelbuild/rules_python/blob/main/python/pip_install/pip_repository.bzl#L847. |
Since |
@aignas I am not a bazel pro and I am struggling to setup a patch in the legacy WORKSPACE structure. Could you provide an example? Last I tried, I remember |
Whilst some bzlmod APIs may still change nearing 1.0, it has greatly matured, so feel free to give it a try. If you are having issues, please create new issues. |
That's good to hear, I will give it a try as soon as I can, but transition will definitely take non-trivial time and I am in a big rush to get some other things done, so an example would be really helpful so I can do a quick fix and move on. Thanks! |
🚀 feature request
Relevant Rules
pip_install
Description
I want to patch a python package after it is installed.
Describe the solution you'd like
Similar to
patches
argument inhttp_archive
, I would like an extra argument inpip_install
.Describe alternatives you've considered
extra_pip_args
argument - I did not find a way to requestpip
to patch a packagePotential problems
pyc
files will be invalidatedThe text was updated successfully, but these errors were encountered: