@@ -31,21 +31,44 @@ The packaging rules (`pip_import`, etc.) are less stable. We may make breaking
3131changes as they evolve. There are no guarantees for rules underneath the
3232` experimental/ ` directory.
3333
34+ See the [ How to contribute] ( CONTRIBUTING.md ) page for information on our
35+ devlopment workflow.
36+
3437## Getting started
3538
3639To import rules_python in your project, you first need to add it to your
3740` WORKSPACE ` file. If you are using the [ Bazel
38- Federation] ( https://github.com/bazelbuild/bazel-federation ) , you will want to
39- copy the boilerplate in the rules_python release's notes, under the "WORKSPACE
40- setup" heading. This will look something like the following :
41+ Federation] ( https://github.com/bazelbuild/bazel-federation ) , you just need to
42+ [ import the Federation ] ( https://github.com/bazelbuild/bazel-federation#example-workspace )
43+ and call the rules_python setup methods :
4144
4245``` python
4346load(" @bazel_tools//tools/build_defs/repo:http.bzl" , " http_archive" )
47+
48+ http_archive(
49+ name = " bazel_federation" ,
50+ url = " https://github.com/bazelbuild/bazel-federation/releases/download/0.0.1/bazel_federation-0.0.1.tar.gz" ,
51+ sha256 = " 506dfbfd74ade486ac077113f48d16835fdf6e343e1d4741552b450cfc2efb53" ,
52+ )
53+
54+ load(" @bazel_federation//:repositories.bzl" , " rules_python_deps" )
55+
56+ rules_python_deps()
57+ load(" @bazel_federation//setup:rules_python.bzl" , " rules_python_setup" )
58+ rules_python_setup(use_pip = True )
59+ ```
60+
61+ Note the ` use_pip ` argument: rules_python may be imported either with or
62+ without support for the packaging rules.
63+
64+ If you are not using the Federation, you can simply import rules_python
65+ directly and call its initialization methods as follows:
66+
67+ ``` python
4468http_archive(
4569 name = " rules_python" ,
46- # NOT VALID: Replace with actual version and SHA.
47- url = " https://github.com/bazelbuild/rules_python/releases/download/<RELEASE>/rules_python-<RELEASE>.tar.gz" ,
48- sha256 = " <SHA>" ,
70+ url = " https://github.com/bazelbuild/rules_python/releases/download/0.0.1/rules_python-0.0.1.tar.gz" ,
71+ sha256 = " aa96a691d3a8177f3215b14b0edc9641787abaaa30363a080165d06ab65e1161" ,
4972)
5073load(" @rules_python//python:repositories.bzl" , " py_repositories" )
5174py_repositories()
@@ -54,32 +77,32 @@ load("@rules_python//python:pip.bzl", "pip_repositories")
5477pip_repositories()
5578```
5679
57- Otherwise, you may import rules_python in a standalone way by copying the
58- following :
80+ To depend on a particular unreleased version (not recommended), you can
81+ use ` git_repository ` instead of ` http_archive ` :
5982
6083``` python
6184load(" @bazel_tools//tools/build_defs/repo:git.bzl" , " git_repository" )
85+
6286git_repository(
6387 name = " rules_python" ,
6488 remote = " https://github.com/bazelbuild/rules_python.git" ,
6589 # NOT VALID: Replace with actual Git commit SHA.
6690 commit = " {HEAD} " ,
6791)
68- load(" @rules_python//python:repositories.bzl" , " py_repositories" )
69- py_repositories()
70- # Only needed if using the packaging rules.
71- load(" @rules_python//python:pip.bzl" , " pip_repositories" )
72- pip_repositories()
92+
93+ # Then load and call py_repositories() and possibly pip_repositories() as
94+ # above.
7395```
7496
75- Either way, you can then load the core rules in your ` BUILD ` files with:
97+ Once you've imported the rule set into your WORKSPACE using any of these
98+ methods, you can then load the core rules in your ` BUILD ` files with:
7699
77100``` python
78101load(" @rules_python//python:defs.bzl" , " py_binary" )
79102
80103py_binary(
81104 name = " main" ,
82- ...
105+ srcs = [ " main.py " ],
83106)
84107```
85108
@@ -168,36 +191,3 @@ started](#Getting-started) above.
168191Note that Starlark-defined bundled symbols underneath
169192` @bazel_tools//tools/python ` are also deprecated. These are not yet rewritten
170193by buildifier.
171-
172- ## Development
173-
174- ### Documentation
175-
176- The content underneath ` docs/ ` is generated. To update the documentation,
177- simply run this in the root of the repository:
178-
179- ``` shell
180- ./update_docs.sh
181- ```
182-
183- ### Precompiled .par files
184-
185- The ` piptool.par ` and ` whltool.par ` files underneath ` tools/ ` are compiled
186- versions of the Python scripts under the ` packaging/ ` directory. We need to
187- check in built artifacts because they are executed during ` WORKSPACE `
188- evaluation, before Bazel itself is able to build anything from source.
189-
190- The .par files need to be regenerated whenever their sources are updated. This
191- can be done by running
192-
193- ``` shell
194- # You can pass --nodocker if Docker is not available on your system.
195- ./update_tools.sh
196- ```
197-
198- from the repository root. However, since these files contain compiled code,
199- we do not accept commits that modify them from untrusted sources.<sup >1</sup >
200- If you submit a pull request that modifies the sources and we accept the
201- changes, we will regenerate these files for you before merging.
202-
203- <sup >1</sup > See "[ Reflections on Trusting Trust] ( https://en.wikipedia.org/wiki/Backdoor_(computing)#Compiler_backdoors ) ".
0 commit comments