• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!-- Generated with Stardoc: http://skydoc.bazel.build -->
2
3Core rules for building Python projects.
4
5<a id="current_py_toolchain"></a>
6
7## current_py_toolchain
8
9<pre>
10current_py_toolchain(<a href="#current_py_toolchain-name">name</a>)
11</pre>
12
13
14    This rule exists so that the current python toolchain can be used in the `toolchains` attribute of
15    other rules, such as genrule. It allows exposing a python toolchain after toolchain resolution has
16    happened, to a rule which expects a concrete implementation of a toolchain, rather than a
17    toolchain_type which could be resolved to that toolchain.
18
19
20**ATTRIBUTES**
21
22
23| Name  | Description | Type | Mandatory | Default |
24| :------------- | :------------- | :------------- | :------------- | :------------- |
25| <a id="current_py_toolchain-name"></a>name |  A unique name for this target.   | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required |  |
26
27
28<a id="py_import"></a>
29
30## py_import
31
32<pre>
33py_import(<a href="#py_import-name">name</a>, <a href="#py_import-deps">deps</a>, <a href="#py_import-srcs">srcs</a>)
34</pre>
35
36This rule allows the use of Python packages as dependencies.
37
38    It imports the given `.egg` file(s), which might be checked in source files,
39    fetched externally as with `http_file`, or produced as outputs of other rules.
40
41    It may be used like a `py_library`, in the `deps` of other Python rules.
42
43    This is similar to [java_import](https://docs.bazel.build/versions/master/be/java.html#java_import).
44
45
46**ATTRIBUTES**
47
48
49| Name  | Description | Type | Mandatory | Default |
50| :------------- | :------------- | :------------- | :------------- | :------------- |
51| <a id="py_import-name"></a>name |  A unique name for this target.   | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required |  |
52| <a id="py_import-deps"></a>deps |  The list of other libraries to be linked in to the binary target.   | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
53| <a id="py_import-srcs"></a>srcs |  The list of Python package files provided to Python targets that depend on this target. Note that currently only the .egg format is accepted. For .whl files, try the whl_library rule. We accept contributions to extend py_import to handle .whl.   | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
54
55
56<a id="py_binary"></a>
57
58## py_binary
59
60<pre>
61py_binary(<a href="#py_binary-attrs">attrs</a>)
62</pre>
63
64See the Bazel core [py_binary](https://docs.bazel.build/versions/master/be/python.html#py_binary) documentation.
65
66**PARAMETERS**
67
68
69| Name  | Description | Default Value |
70| :------------- | :------------- | :------------- |
71| <a id="py_binary-attrs"></a>attrs |  Rule attributes   |  none |
72
73
74<a id="py_library"></a>
75
76## py_library
77
78<pre>
79py_library(<a href="#py_library-attrs">attrs</a>)
80</pre>
81
82See the Bazel core [py_library](https://docs.bazel.build/versions/master/be/python.html#py_library) documentation.
83
84**PARAMETERS**
85
86
87| Name  | Description | Default Value |
88| :------------- | :------------- | :------------- |
89| <a id="py_library-attrs"></a>attrs |  Rule attributes   |  none |
90
91
92<a id="py_runtime"></a>
93
94## py_runtime
95
96<pre>
97py_runtime(<a href="#py_runtime-attrs">attrs</a>)
98</pre>
99
100See the Bazel core [py_runtime](https://docs.bazel.build/versions/master/be/python.html#py_runtime) documentation.
101
102**PARAMETERS**
103
104
105| Name  | Description | Default Value |
106| :------------- | :------------- | :------------- |
107| <a id="py_runtime-attrs"></a>attrs |  Rule attributes   |  none |
108
109
110<a id="py_runtime_pair"></a>
111
112## py_runtime_pair
113
114<pre>
115py_runtime_pair(<a href="#py_runtime_pair-name">name</a>, <a href="#py_runtime_pair-py2_runtime">py2_runtime</a>, <a href="#py_runtime_pair-py3_runtime">py3_runtime</a>, <a href="#py_runtime_pair-attrs">attrs</a>)
116</pre>
117
118A toolchain rule for Python.
119
120This used to wrap up to two Python runtimes, one for Python 2 and one for Python 3.
121However, Python 2 is no longer supported, so it now only wraps a single Python 3
122runtime.
123
124Usually the wrapped runtimes are declared using the `py_runtime` rule, but any
125rule returning a `PyRuntimeInfo` provider may be used.
126
127This rule returns a `platform_common.ToolchainInfo` provider with the following
128schema:
129
130```python
131platform_common.ToolchainInfo(
132    py2_runtime = None,
133    py3_runtime = &lt;PyRuntimeInfo or None&gt;,
134)
135```
136
137Example usage:
138
139```python
140# In your BUILD file...
141
142load("@rules_python//python:defs.bzl", "py_runtime_pair")
143
144py_runtime(
145    name = "my_py3_runtime",
146    interpreter_path = "/system/python3",
147    python_version = "PY3",
148)
149
150py_runtime_pair(
151    name = "my_py_runtime_pair",
152    py3_runtime = ":my_py3_runtime",
153)
154
155toolchain(
156    name = "my_toolchain",
157    target_compatible_with = &lt;...&gt;,
158    toolchain = ":my_py_runtime_pair",
159    toolchain_type = "@rules_python//python:toolchain_type",
160)
161```
162
163```python
164# In your WORKSPACE...
165
166register_toolchains("//my_pkg:my_toolchain")
167```
168
169
170**PARAMETERS**
171
172
173| Name  | Description | Default Value |
174| :------------- | :------------- | :------------- |
175| <a id="py_runtime_pair-name"></a>name |  str, the name of the target   |  none |
176| <a id="py_runtime_pair-py2_runtime"></a>py2_runtime |  optional Label; must be unset or None; an error is raised otherwise.   |  <code>None</code> |
177| <a id="py_runtime_pair-py3_runtime"></a>py3_runtime |  Label; a target with <code>PyRuntimeInfo</code> for Python 3.   |  <code>None</code> |
178| <a id="py_runtime_pair-attrs"></a>attrs |  Extra attrs passed onto the native rule   |  none |
179
180
181<a id="py_test"></a>
182
183## py_test
184
185<pre>
186py_test(<a href="#py_test-attrs">attrs</a>)
187</pre>
188
189See the Bazel core [py_test](https://docs.bazel.build/versions/master/be/python.html#py_test) documentation.
190
191**PARAMETERS**
192
193
194| Name  | Description | Default Value |
195| :------------- | :------------- | :------------- |
196| <a id="py_test-attrs"></a>attrs |  Rule attributes   |  none |
197
198
199<a id="find_requirements"></a>
200
201## find_requirements
202
203<pre>
204find_requirements(<a href="#find_requirements-name">name</a>)
205</pre>
206
207The aspect definition. Can be invoked on the command line as
208
209    bazel build //pkg:my_py_binary_target         --aspects=@rules_python//python:defs.bzl%find_requirements         --output_groups=pyversioninfo
210
211
212**ASPECT ATTRIBUTES**
213
214
215| Name | Type |
216| :------------- | :------------- |
217| deps| String |
218
219
220**ATTRIBUTES**
221
222
223| Name  | Description | Type | Mandatory | Default |
224| :------------- | :------------- | :------------- | :------------- | :------------- |
225| <a id="find_requirements-name"></a>name |  A unique name for this target.   | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required |   |
226
227
228