-
Notifications
You must be signed in to change notification settings - Fork 13
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
New Rules #16
Comments
Thanks for the writeup. We have been using this for our internal monorepo, everything works great other than things due to lack of target platform support. This becomes super visible when building docker images on a Mac (which just does not work due to Linux deps required but OsX deps provided into the built image). We are going to test this branch out over the weekend and will let you our findings. One change we had to make was to enable support for purelib/platlib (like tensorflow). You can see the changes SpotDraft@88ec9ae. While there are a lot of TODOs and NOTEs in there, we have been running 50+ rules off this depending on pure/platlibs. I can open a separate bug for this if you support of such pip deps is something you intend to support in this repo. Also, was just wondering how this would be potentially supported now that you have updated to always build wheels/use prebuilt wheels. Or in other words, would be great to have some clarity around this part:
Specifically does rules_pip handle the building of wheels? Is the https://github.com/apt-itude/rules_pip/blob/repository-rule-per-distribution/src/bin/create_wheel_repository.py binary the right place to target to make changes for purelib/platlib support? |
@codebreach sorry for the delay. I would love to hear your results if you've tested it out for building Docker images. Regarding the "built wheels" confusion, I meant that the It does not mean that you're on your own for building those wheels. The Your use case sounds like you want to run Bazel on macOS to build a Linux Docker image, so you could potentially use something like dazel to run the Regarding purelib/platlib support, you are correct that the |
All of these suggestions sound great. Thoughts on how to evolve testing
support?
…On Wed, Jul 10, 2019 at 7:11 AM Alex Thompson ***@***.***> wrote:
@codebreach <https://github.com/codebreach> sorry for the delay. I would
love to hear your results if you've tested it out for building Docker
images.
Regarding the "built wheels" confusion, I meant that the pip_repository
and pip_install rules would only support wheels, rather than source
distributions, because building wheels hermetically is a real challenge.
This also means that all sources in the requirements-lock.json file must
be wheels.
It does not mean that you're on your own for building those wheels. The
pip_lock rule, which is used as a manual bazel run step to
generate/update your requirements-lock.json, will build wheels for all
packages that are only available as sdists on PyPI. However, it builds the
wheels for the host platform, not the target platform, so you need to run
the rule on each of your target platforms.
Your use case sounds like you want to run Bazel on macOS to build a Linux
Docker image, so you could potentially use something like dazel
<https://github.com/nadirizr/dazel> to run the pip_lock rule in a Docker
container and mount the wheels directory as a volume.
Regarding purelib/platlib support, you are correct that the
create_wheel_repository.py script would be the place to do it. That is
the tool used to convert a wheel file into a py_library. We already have
issue #15 <#15> to track
this, and you are welcome to help tackle that.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#16?email_source=notifications&email_token=AAAA7CIXW4VKPWA2IS36UGDP6XUXJA5CNFSM4HW2SQMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZTSW6Y#issuecomment-510077819>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAA7CMBIWNUBF2X5OXTGADP6XUXJANCNFSM4HW2SQMA>
.
|
@tmc can you elaborate on what you mean by that? |
I meant did you have plans to expand the pytest support.
…On Fri, Jul 12, 2019 at 10:59 AM Alex Thompson ***@***.***> wrote:
@tmc <https://github.com/tmc> can you elaborate on what you mean by that?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#16?email_source=notifications&email_token=AAAA7CKGN3KL2OEYG6ZD5PDP7DBBDA5CNFSM4HW2SQMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZ2OQHY#issuecomment-510978079>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAA7CL4TMJBTVH52YKXRA3P7DBBDANCNFSM4HW2SQMA>
.
|
Ah gotcha. I really didn't intend to expose or support pytest rules (the repo is named |
@apt-itude how are things going here? might have some spare cycles to help hack on these improvements. |
@tmc the new rules are actually very much functional. I have a development branch going with the new rules in our repo at 128 Technology, which has over 250 You can track the status of this effort in the New Rules Project as well as the status of the broader 1.0.0 Milestone. Issues that are done aren't actually closed since they haven't been merged into master but are labeled as Honestly, one of the most helpful things would be to just try out the new rules and provide feedback on any issues you run into or whether they even improve your development experience. I'll try to whip up a migration section in the README to help with the switch. Thanks for the help/interest! |
Update: I added a whole bunch of detail to the README in the new branch, including a migration section. |
This looks awesome! Am I correct to say that these new rules would work with remote execution? And do you have an example by any chance of the setup you described to build Linux docker images on a Mac through Dazel? If remote execution is enabled (which would run on Linux I assume), Dazel wouldn’t be necessarily needed I guess? |
This does indeed look awesome! @apt-itude are you still likely to continue pushing this forward? |
Hey guys, The new rules are actually pretty functional in their current state, but as we started to use them at 128, it became clear that using a single Obviously, anyone is welcome to fork this and take it over. I'd be happy to answer questions about it. |
Thanks for your honesty @apt-itude Good luck with your new gig! It's a shame (from a purely selfish perspective), but hopefully the community can pick this up or there another promising set of rules for Python dependencies emerges. |
The current pip rules have a few major flaws that really warrant a rewrite. This repo doesn't have a whole lot of traction, but I plan to make some very breaking changes, and I don't want to rip the rug out from under anyone who might actually be using these rules without an explanation of the overhaul.
@tmc @Globegitter @kerinin @chaoran: If any of you are using the current rules, I would love feedback on whether the proposed changes would make your lives easier or harder and whether it would be difficult to migrate. Also open to ideas, although I have a POC of what I'm proposing that's about 85% done available via the
repository-rule-per-distribution
branch.Current Problems
All Python distributions are obtained via a single repository rule (
pip_repository
) which basically just executespip wheel
This causes the following problems:
1. This forces all dependencies to be downloaded in order to build/test any Python target, which can slow in a large repository
1. This forces all dependencies to be re-downloaded any time one dependency changes
1. If any wheel fails to download or build, the user gets a vague error about a pip package not containing a BUILD file, and then has to run
bazel clean --expunge
and re-download everything yet againThe
pip_repository
rule runspip wheel
under the host configuration,This means it may build platform-specific wheels for packages that are only available as source distributions which, as far as I can tell, makes Bazel remote execution impossible.
The
pip_repository
rule may only be used with a single Python versionIn a workspace that contains both Python 2 and Python 3 code, you must create separate
@pip2
and@pip3
repositories. This makes it difficult for a library to be compatible with both Python 2 and Python 3 unless all dependencies happen to be universal wheels. Even then, it seems wrong for a Python 3 target to transitively depend on a@pip2
package.It requires developers of the rules to compile and source control
.par
files for each of the tools whenever changes are madeThis is a PITA and it's hard to enforce through CI that developers actually do this every time.
Requirements
To solve these issues, the rules should be enhanced or rewritten to support the following goals:
A single repository rule should be created for each Python distribution in the requirement set
Each distribution in the locked, exhaustive set of requirements should correspond to a separate repository rule that will be responsible for fetching that distribution and creating an external workspace for it.
This will allow Bazel to fetch only the distributions that are actually needed for a given target, and it will allow new dependencies to be fetched incrementally instead of re-fetching everything when the requirements change.
The repository rules should operate exclusively on wheels
When compiling the locked, exhaustive requirement set (i.e. the current
compile_pip_requirements
rule), wheels must be built for all distributions that do not publish a wheel for the target platform. The built wheels then must either be committed to source control or published to a custom Python package index. These steps must be repeated for all supported platforms.This means that no build step will be necessary at fetch time, so there is no risk of non-hermetic actions failing and forcing the user to use
--expunge
. It also means that the correct wheel can be fetched based on the target platform instead of the host platform, enabling remote execution.The correct wheel should be selected based on Python version and platform
Every required distribution should be available as a
py_library
via a simple@pip//<name>
label (e.g@pip//lxml
or@pip//pytest_mock
). This label should select the correct wheel for the target platform and Python version.This can be accomplished via an
alias
that usesselect
statements with the@bazel_tools//tools/python
and@bazel_tools//platforms
conditions.This will allow a library with
pip
dependencies to be a dependency of a binary target withpython_version
set toPY2
orPY3
.Any Python tool used by a repository rule should be a single file with no dependencies outside the standard library
This eliminates the need to compile and source-control
.par
files.New Rules
The rules are actively being rewritten or replaced to accomplish the above goals. The new rule set will consist of the following:
pip_lock
pip_repository
Example usage
WORKSPACE
thirdparty/pip/BUILD
thirdparty/pip/requirements.txt
Generate lock file
bazel run //thirdparty/pip:lock
Add to
WORKSPACE
some/package/BUILD
The text was updated successfully, but these errors were encountered: