@@ -31,21 +31,44 @@ The packaging rules (`pip_import`, etc.) are less stable. We may make breaking
31
31
changes as they evolve. There are no guarantees for rules underneath the
32
32
` experimental/ ` directory.
33
33
34
+ See the [ How to contribute] ( CONTRIBUTING.md ) page for information on our
35
+ devlopment workflow.
36
+
34
37
## Getting started
35
38
36
39
To import rules_python in your project, you first need to add it to your
37
40
` 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 :
41
44
42
45
``` python
43
46
load(" @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
44
68
http_archive(
45
69
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" ,
49
72
)
50
73
load(" @rules_python//python:repositories.bzl" , " py_repositories" )
51
74
py_repositories()
@@ -54,32 +77,32 @@ load("@rules_python//python:pip.bzl", "pip_repositories")
54
77
pip_repositories()
55
78
```
56
79
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 ` :
59
82
60
83
``` python
61
84
load(" @bazel_tools//tools/build_defs/repo:git.bzl" , " git_repository" )
85
+
62
86
git_repository(
63
87
name = " rules_python" ,
64
88
remote = " https://github.com/bazelbuild/rules_python.git" ,
65
89
# NOT VALID: Replace with actual Git commit SHA.
66
90
commit = " {HEAD} " ,
67
91
)
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.
73
95
```
74
96
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:
76
99
77
100
``` python
78
101
load(" @rules_python//python:defs.bzl" , " py_binary" )
79
102
80
103
py_binary(
81
104
name = " main" ,
82
- ...
105
+ srcs = [ " main.py " ],
83
106
)
84
107
```
85
108
@@ -168,36 +191,3 @@ started](#Getting-started) above.
168
191
Note that Starlark-defined bundled symbols underneath
169
192
` @bazel_tools//tools/python ` are also deprecated. These are not yet rewritten
170
193
by 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