-
Notifications
You must be signed in to change notification settings - Fork 36
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
py_library imports ignored when linking into pex_binary #36
Comments
Turns out this is currently impossible due to bazelbuild/bazel#2617 ; Bazel does not expose the |
Aye, it's true. Sorry I forgot to say as much when you opened this issue, because I spent a while figuring it out last fall. Let's keep this issue open because I'm pretty sure bazelbuild/bazel#2791 will be merged eventually, and then it can actually work :-) |
#35 should fix this when bazel's support is ready |
In the meantime, since this still hasn't landed, I've implemented a |
Yes, it is very similar, although my version adds a As far as using Bazel entirely: The jury is still out, but so far: we've been able to get most of our stuff working. It definitely is reliable: if you can get it to work on your machine, it seems to work on everyone's machine, which is really the issue we wanted to solve. It also allows us to easily express complex dependencies between parts of the code base (which we also wanted to enable). The one caveat: if you consume very large third-party libraries (e.g. pandas, which depends on scipy and numpy), rebuilding any pex rules is really slow. I'm testing a hack to make this slightly better. My take: Bazel's Python support is pretty bad at the moment, but I see a heck of a lot more "momentum" behind Bazel (eg. Dropbox, Stripe, others) so we are giving it a shot. |
@evanj would you be able to share your patch? |
@c4urself Sorry for the delay. See the branch at https://github.com/evanj/bazel_rules_pex/tree/pythonroot . I did not send a pull request for this, since it isn't totally clear to me if this is the "right" design for this. |
TL;DR: If I have a
py_library(..., srcs=["foo.py"], imports=["."])
, then with the standard Bazel Python rules I can useimport foo
to reference it. If I link thispy_library
into apex_binary
, it ignores theimports
part, so the files get packed into the pex asfull/workspace/path/foo.py
, instead of asfoo.py
in the root of the pex.Expected result: I should be able to change standard Bazel
py_binary
into apex_binary
and have it magically work. This probably means shuffling files around, or packaging eachpy_library
into a wheel, and packaging those together into the pex?Additional details
I have a Python mono-repo that is set up something like this:
package_foo/setup.py
- A "standard" setuptools setup.py to build a wheelpackage_foo/foo/__init__.py
- Python packagefoo
somebinary/bin.py
- A Python program that usesimport foo
(Imagine more packages and binaries)
Each subdirectory is a "standard" Python package. We are still evaluating the various monorepo build tools (Pants, Buck, Bazel), so this lets us make it work fairly easily. I'd like to just "drop in" the appropriate
BUILD
rules, but I can't figure out how to makepex_binary
work in this case, since I need to "fix" the import path somehow.PS. Thanks for creating these rules! Being able to directly link wheels is great.
The text was updated successfully, but these errors were encountered: