|
4 | 4 | https://github.com/bazelbuild/rules_python.
|
5 | 5 | It is currently in pre-release, but we are committed to more development towards a 1.0 stable release.
|
6 | 6 |
|
7 |
| -Some parts of `rules_python` are reused: |
| 7 | +The lower layer of `rules_python` is currently reused, dealing with the toolchain and dependencies: |
8 | 8 |
|
9 | 9 | - Same toolchain for fetching a hermetic python interpreter.
|
10 | 10 | - `pip_parse` rule for translating a requirements-lock.txt file into Bazel repository fetching rules
|
11 | 11 | and installing those packages into external repositories.
|
12 | 12 | - The Gazelle extension for generating BUILD.bazel files works the same.
|
13 | 13 |
|
14 | 14 | However, this ruleset introduces a new implementation of `py_library`, `py_binary`, and `py_test`.
|
15 |
| -The starlark implementations allow us to innovate, while the existing ones are embedded in Bazel's |
16 |
| -Java sources in the bazelbuild/bazel repo and therefore very difficult to get changes made. |
| 15 | +Our philosophy is to behave more like idiomatic python ecosystem tools, where rules_python is closely |
| 16 | +tied to the way Google does Python development in their internal monorepo, google3. |
17 | 17 |
|
18 |
| -> We understand that there is also an effort at Google to "starlarkify" the Python rules, |
19 |
| -> but there is no committed roadmap or dates. |
20 |
| -> Given the history of other projects coming from Google, we've chosen not to wait. |
| 18 | +Things you'll love about rules_py: |
21 | 19 |
|
22 |
| -Our philosophy is to behave more like idiomatic python ecosystem tools. |
23 |
| -Having a starlark implementation allows us to do things like |
24 |
| -attach Bazel transitions, mypy typechecking actions, etc. |
25 |
| - |
26 |
| -Things that are improved in rules_py: |
27 |
| - |
28 |
| -- We don't mess with the Python `sys.path`/`$PYTHONPATH`. Instead we use the standard `site-packages` folder layout produced by `pip_install`. This avoids problems like package naming collisions with built-ins (e.g. `collections`) or where `argparse` comes from a transitive dependency instead. (Maybe helps with diamond dependencies too). |
29 |
| -- We run python in isolated mode so we don't accidentally break out of Bazel's action sandbox, fixing: |
| 20 | +- We don't mess with the Python `sys.path`/`$PYTHONPATH`. Instead we use the standard `site-packages` folder layout produced by `pip_install`. This avoids problems like package naming collisions with built-ins (e.g. `collections`) or where `argparse` comes from a transitive dependency instead. |
| 21 | +- We run python in isolated mode so we don't accidentally break out of Bazel's action sandbox, fixing bugs like: |
30 | 22 | - [pypi libraries installed to system python are implicitly available to builds](https://github.com/bazelbuild/rules_python/issues/27)
|
31 | 23 | - [sys.path[0] breaks out of runfile tree.](https://github.com/bazelbuild/rules_python/issues/382)
|
32 | 24 | - We create a python-idiomatic virtualenv to run actions, which means better compatibility with userland implementations of [importlib](https://docs.python.org/3/library/importlib.html).
|
33 | 25 | - Thanks to the virtualenv, you can open the project in an editor like PyCharm and have working auto-complete, jump-to-definition, etc.
|
34 |
| -- The launcher uses the Bash toolchain rather than Python, so we have no dependency on a system interpreter - fixes MacOS no longer shipping with python. |
35 |
| - |
36 |
| -Improvements planned: |
37 |
| - |
38 |
| -- Build wheels in actions, so it's possible to have native packages built for the target platform, |
39 |
| - e.g. for a rules_docker py3_image. |
40 |
| -- Support `--only_binary=:all:` by always building wheels from source using a hermetic Bazel cc toolchain. |
41 |
| -- `dep` on wheels directly, rather than on a `py_library` that wraps it. Then we don't have to append to the `.pth` file to locate them. |
| 26 | +- The launcher uses the Bash toolchain rather than Python, so we have no dependency on a system interpreter. |
42 | 27 |
|
43 | 28 | _Need help?_ This ruleset has support provided by https://aspect.dev.
|
44 | 29 |
|
|
0 commit comments