-
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
Allow users to inject extra deps
into pip packages
#853
Conversation
94e8324
to
e63fb4b
Compare
def test_generate_entry_point_contents(self): | ||
got = generate_entry_point_contents("sphinx.cmd.build:main") | ||
got = generate_entry_point_contents("sphinx.cmd.build", "main") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this file was missing the dunder main check to invoke unittest.main()
, I had to fix these tests up too.
cd23521
to
85a7cbb
Compare
@groodt , any thoughts? |
@rickeylev , would you mind taking a look? |
I'm not sure this is true? It looks like importlib metadata is an optional dependency via extras. hypothesis setup.py. So -- if I correctly understand how pip_parse and friends work -- you should able to put something like |
Ah dang. Apologies! The internal system we have (that I'm trying to migrate away from) doesn't support extras. So the extra The most common issue that we run into is that a package doesn't declare a dependency on The less common issue we run into is that we need to patch a wheel to make hermeticity fixes. This is usually fixed by a combination of:
I will change the Summary and the commit message to a different example. The |
Turns out that the toolchains that rules_python exposes come with I'm not sure if we'll be switching toolchains internally. So we won't have With that in mind, I'll rephrase the Summary and commit about the aspect for patching wheels. Which is a topic I need to file a separate ticket for to generate some discussion. |
There is currently no way to inject a dependency into a pip package. Our primary use case at Aurora for this is to inject `setuptools` dependencies to packages that don't declare them. The majority of packages assume that it's installed by default. In fact, the default toolchain that rules_python sets up provides it for that very reason: https://github.com/indygreg/python-build-standalone/blob/adff2af8605b6d64946d480651d20bc0df3582a1/cpython-unix/build-cpython.sh#L700-L710 The secondary use case is to help fix non-hermetic behaviour in wheels. Additional dependencies cannot by themselves fix non-hermetic behaviour. But together with the ability to patch the wheel, we can start making these fixes. At the robotics team, we currently use relative paths in our patches for fixing non-hermetic behaviour. For example: * https://github.com/frc971/971-Robot-Code/blob/f094a81f316a619ee887f694836e6050dad4efc8/debian/python_gi_init.patch#L7 * https://github.com/frc971/971-Robot-Code/blob/f094a81f316a619ee887f694836e6050dad4efc8/debian/matplotlib_init.patch#L7 This approach works, but I would like to migrate to using the Python runfiles library to find these files instead. For that to work, I need to inject the runfiles library as an extra dependency. The act of patching code in a wheel is out of scope for this patch. I will open a separate discussion for how to accomplish that.
85a7cbb
to
de72462
Compare
Actually, looks like #553 already has some discussion on patching wheels. |
Another example of The |
This all sounds pretty reasonable. The analogy I have in my mind is, if you have regular @groodt (or another more familiar with this code) want to take a look at the impl? |
Do you mean like so? py_library(
# "the other target" from your example.
name = "a",
# a.py uses 'b', but doesn't declare the dependency.
srcs = ["a.py"],
)
py_library(
name = "b",
# b.py has no dependencies.
srcs = ["b.py"],
)
py_library(
# "regular py_library" from your example.
name = "c",
# c.py only depends on a. But since 'a' is missing a dep on 'b', we have to declare it here.
srcs = ["c.py"],
deps = [":a", ":b"],
) If that's the scenario you're thinking of, that's not what I'm trying to convey/implement here. The feature I'm proposing here is to let users inject a |
I'll take a look. My hesitation for this sort of thing is because I have a bias for not doing work in repository rules. I personally would prefer to push resolution of wheels all the way to I prefer a use-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? |
I can see patching being done in, say, a @groodt , do you happen to know the exact point in |
You need some way to convey a user configuration (.bzl file?) to rules_python on a per-package basis. The annotations are exactly that. We can find another way to do it, but it would roughly end up looking similar to annotations. |
To clarify, I'm happy to submit PRs to re-architect the annotations/http_archive/patch code, but it's not immediately obvious to me what you're looking for. I'll have to think about it. Would it help for me to write up a design doc? |
Oh, I think thats probably not necessary (unless you want to). I think the reality is probably that with the present setup where the rules are implemented using repository rules (instead of regular rules/actions) that there probably isn't a better way. |
1 similar comment
Oh, I think thats probably not necessary (unless you want to). I think the reality is probably that with the present setup where the rules are implemented using repository rules (instead of regular rules/actions) that there probably isn't a better way. |
Fair enough! In that case, WDYT about the current proposed changes? |
After talking with @groodt offline, I decided not to move forward with this. Instead, I will try to come up with a design that doesn't require adding more stuff to repository rules. |
Thanks @philsc And to be clear, if we end up coming back to this, that's cool too. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
There is currently no way to inject a dependency into a pip package.
Our primary use case at Aurora for this is to inject
setuptools
dependencies to packages that don't declare them. The majority of
packages assume that it's installed by default. In fact, the default
toolchain that rules_python sets up provides it for that very reason:
https://github.com/indygreg/python-build-standalone/blob/adff2af8605b6d64946d480651d20bc0df3582a1/cpython-unix/build-cpython.sh#L700-L710
The secondary use case is to help fix non-hermetic behaviour in
wheels. Additional dependencies cannot by themselves fix non-hermetic
behaviour. But together with the ability to patch the wheel, we can
start making these fixes.
At the robotics team, we currently use relative paths in our patches
for fixing non-hermetic behaviour. For example:
This approach works, but I would like to migrate to using the Python
runfiles library to find these files instead. For that to work, I need
to inject the runfiles library as an extra dependency.
The act of patching code in a wheel is out of scope for this patch. I
will open a separate discussion for how to accomplish that.
Issue Number: N/A
What is the new behavior?
The new behaviour is that you can add a
deps
annotation for a package. This new annotation injects extra entries into the finalpy_library
'sdeps
list.Does this PR introduce a breaking change?
Other information