Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b4d1e5d

Browse filesBrowse files
author
Marian Dvorsky
committed
2 parents 4418699 + 9d68f24 commit b4d1e5d
Copy full SHA for b4d1e5d

File tree

25 files changed

+215
-221
lines changed
Filter options

25 files changed

+215
-221
lines changed

‎.bazelci/presubmit.yml

Copy file name to clipboardExpand all lines: .bazelci/presubmit.yml
+7-21Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,19 @@
44
# TODO(#144): When Bazel 0.29 is released, the docgen workflow will work, and
55
# we can go back to using `...` for build_targets.
66
---
7-
platforms:
8-
ubuntu1604:
9-
# I don't trust my knowledge of YAML enough to factor this list into an
10-
# anchor.
7+
all_targets: &all_targets
118
build_targets:
129
- "//examples/..."
1310
- "//experimental/..."
11+
- "//packaging/..."
1412
- "//python/..."
15-
- "//rules_python/..."
1613
- "//tools/..."
1714
test_targets:
1815
- "..."
16+
platforms:
17+
ubuntu1604:
18+
<<: *all_targets
1919
ubuntu1804:
20-
build_targets:
21-
- "//examples/..."
22-
- "//experimental/..."
23-
- "//python/..."
24-
- "//rules_python/..."
25-
- "//tools/..."
26-
test_targets:
27-
- "..."
20+
<<: *all_targets
2821
macos:
29-
build_targets:
30-
- "//examples/..."
31-
- "//experimental/..."
32-
- "//python/..."
33-
- "//rules_python/..."
34-
- "//tools/..."
35-
test_targets:
36-
- "..."
22+
<<: *all_targets

‎README.md

Copy file name to clipboardExpand all lines: README.md
+54-22Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,37 @@ Status: This is **ALPHA** software.
1010

1111
## Rules
1212

13-
* [pip_import](docs/python/pip.md#pip_import)
14-
* [py_library](docs/python/python.md#py_library)
15-
* [py_binary](docs/python/python.md#py_binary)
16-
* [py_test](docs/python/python.md#py_test)
13+
### Core Python rules
14+
15+
* [py_library](docs/python.md#py_library)
16+
* [py_binary](docs/python.md#py_binary)
17+
* [py_test](docs/python.md#py_test)
18+
* [py_runtime](docs/python.md#py_runtime)
19+
* [py_runtime_pair](docs/python.md#py_runtime_pair)
20+
21+
### Packaging rules
22+
23+
* [pip_import](docs/pip.md#pip_import)
1724

1825
## Overview
1926

20-
This repository provides Python rules for Bazel. Currently, support for
21-
rules that are available from Bazel core are simple aliases to that bundled
22-
functionality. On top of that, this repository provides support for installing
23-
dependencies typically managed via `pip`.
27+
This repository provides two sets of Python rules for Bazel. The core rules
28+
provide the essential library, binary, test, and toolchain rules that are
29+
expected for any language supported in Bazel. The packaging rules provide
30+
support for integration with dependencies that, in a non-Bazel environment,
31+
would typically be managed by `pip`.
32+
33+
Historically, the core rules have been bundled with Bazel itself. The Bazel
34+
team is in the process of transitioning these rules to live in
35+
bazelbuild/rules_python instead. In the meantime, all users of Python rules in
36+
Bazel should migrate their builds to load these rules and their related symbols
37+
(`PyInfo`, etc.) from `@rules_python` instead of using built-ins or
38+
`@bazel_tools//tools/python`.
2439

2540
## Setup
2641

27-
Add the following to your `WORKSPACE` file to add the external repositories:
42+
To use this repository, first modify your `WORKSPACE` file to load it and call
43+
the initialization functions as needed:
2844

2945
```python
3046
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
@@ -36,19 +52,19 @@ git_repository(
3652
commit = "{HEAD}",
3753
)
3854

39-
# Only needed for PIP support:
40-
load("@rules_python//python:pip.bzl", "pip_repositories")
55+
# This call should always be present.
56+
load("@rules_python//python:repositories.bzl", "py_repositories")
57+
py_repositories()
4158

59+
# This one is only needed if you're using the packaging rules.
60+
load("@rules_python//python:pip.bzl", "pip_repositories")
4261
pip_repositories()
4362
```
4463

45-
Then in your `BUILD` files load the python rules with:
64+
Then in your `BUILD` files, load the core rules as needed with:
4665

4766
``` python
48-
load(
49-
"@rules_python//python:defs.bzl",
50-
"py_binary", "py_library", "py_test",
51-
)
67+
load("@rules_python//python:defs.bzl", "py_binary")
5268

5369
py_binary(
5470
name = "main",
@@ -118,18 +134,34 @@ format in the future.
118134
https://packaging.python.org/tutorials/installing-packages/#installing-setuptools-extras)
119135
will have a target of the extra name (in place of `pkg` above).
120136

121-
## Updating `docs/`
137+
## Development
138+
139+
### Documentation
140+
141+
All of the content under `docs/` besides the `BUILD` file is generated with
142+
Stardoc. To regenerate the documentation, simply run
122143

123-
All of the content (except `BUILD`) under `docs/` is generated. To update the
124-
documentation simply run this in the root of the repository:
125144
```shell
126145
./update_docs.sh
127146
```
128147

129-
## Updating `tools/`
148+
from the repository root.
149+
150+
### Precompiled par files
151+
152+
The `piptool.par` and `whltool.par` files underneath `tools/` are compiled
153+
versions of the Python scripts under the `rules_python/` directory. We need to
154+
check in built artifacts because they are executed during `WORKSPACE`
155+
evaluation, before Bazel itself is able to build anything from source.
156+
157+
The .par files need to be regenerated whenever their sources are updated. This
158+
can be done by running
130159

131-
All of the content (except `BUILD`) under `tools/` is generated. To update the
132-
documentation simply run this in the root of the repository:
133160
```shell
134161
./update_tools.sh
135162
```
163+
164+
from the repository root. However, since these files contain compiled code,
165+
we do not accept commits that modify them from untrusted sources. If you submit
166+
a pull request that modifies the sources and we accept the changes, we will
167+
regenerate these files for you before merging.

‎WORKSPACE

Copy file name to clipboardExpand all lines: WORKSPACE
+16-147Lines changed: 16 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -14,111 +14,11 @@
1414

1515
workspace(name = "rules_python")
1616

17-
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
18-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
19-
20-
#################################
21-
# Stardoc and its dependencies. #
22-
#################################
23-
24-
# Initialization taken from:
25-
# https://skydoc.bazel.build/docs/getting_started_stardoc.html
26-
27-
git_repository(
28-
name = "io_bazel_skydoc",
29-
remote = "https://github.com/bazelbuild/skydoc.git",
30-
tag = "0.3.0",
31-
)
32-
33-
load("@io_bazel_skydoc//:setup.bzl", "skydoc_repositories")
34-
skydoc_repositories()
35-
36-
load("@io_bazel_rules_sass//:package.bzl", "rules_sass_dependencies")
37-
rules_sass_dependencies()
38-
39-
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")
40-
node_repositories()
41-
42-
load("@io_bazel_rules_sass//:defs.bzl", "sass_repositories")
43-
sass_repositories()
44-
45-
##########################################
46-
# Requirements for building our piptool. #
47-
##########################################
48-
49-
load("//python:pip.bzl", "pip_import")
50-
51-
pip_import(
52-
name = "piptool_deps",
53-
requirements = "//python:requirements.txt",
54-
)
55-
56-
load(
57-
"@piptool_deps//:requirements.bzl",
58-
_piptool_install = "pip_install",
59-
)
60-
61-
_piptool_install()
62-
63-
git_repository(
64-
name = "subpar",
65-
remote = "https://github.com/google/subpar",
66-
tag = "2.0.0",
67-
)
68-
6917
###################################
7018
# Test data for WHL tool testing. #
7119
###################################
7220

73-
http_file(
74-
name = "grpc_whl",
75-
downloaded_file_path = "grpcio-1.6.0-cp27-cp27m-manylinux1_i686.whl",
76-
sha256 = "c232d6d168cb582e5eba8e1c0da8d64b54b041dd5ea194895a2fe76050916561",
77-
# From https://pypi.python.org/pypi/grpcio/1.6.0
78-
urls = [("https://pypi.python.org/packages/c6/28/" +
79-
"67651b4eabe616b27472c5518f9b2aa3f63beab8f62100b26f05ac428639/" +
80-
"grpcio-1.6.0-cp27-cp27m-manylinux1_i686.whl")],
81-
)
82-
83-
http_file(
84-
name = "futures_3_1_1_whl",
85-
downloaded_file_path = "futures-3.1.1-py2-none-any.whl",
86-
sha256 = "c4884a65654a7c45435063e14ae85280eb1f111d94e542396717ba9828c4337f",
87-
# From https://pypi.python.org/pypi/futures
88-
urls = [("https://pypi.python.org/packages/a6/1c/" +
89-
"72a18c8c7502ee1b38a604a5c5243aa8c2a64f4bba4e6631b1b8972235dd/" +
90-
"futures-3.1.1-py2-none-any.whl")],
91-
)
92-
93-
http_file(
94-
name = "futures_2_2_0_whl",
95-
downloaded_file_path = "futures-2.2.0-py2.py3-none-any.whl",
96-
sha256 = "9fd22b354a4c4755ad8c7d161d93f5026aca4cfe999bd2e53168f14765c02cd6",
97-
# From https://pypi.python.org/pypi/futures/2.2.0
98-
urls = [("https://pypi.python.org/packages/d7/1d/" +
99-
"68874943aa37cf1c483fc61def813188473596043158faa6511c04a038b4/" +
100-
"futures-2.2.0-py2.py3-none-any.whl")],
101-
)
102-
103-
http_file(
104-
name = "mock_whl",
105-
downloaded_file_path = "mock-2.0.0-py2.py3-none-any.whl",
106-
sha256 = "5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1",
107-
# From https://pypi.python.org/pypi/mock
108-
urls = [("https://pypi.python.org/packages/e6/35/" +
109-
"f187bdf23be87092bd0f1200d43d23076cee4d0dec109f195173fd3ebc79/" +
110-
"mock-2.0.0-py2.py3-none-any.whl")],
111-
)
112-
113-
http_file(
114-
name = "google_cloud_language_whl",
115-
downloaded_file_path = "google_cloud_language-0.29.0-py2.py3-none-any.whl",
116-
sha256 = "a2dd34f0a0ebf5705dcbe34bd41199b1d0a55c4597d38ed045bd183361a561e9",
117-
# From https://pypi.python.org/pypi/google-cloud-language
118-
urls = [("https://pypi.python.org/packages/6e/86/" +
119-
"cae57e4802e72d9e626ee5828ed5a646cf4016b473a4a022f1038dba3460/" +
120-
"google_cloud_language-0.29.0-py2.py3-none-any.whl")],
121-
)
21+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
12222

12323
http_file(
12424
name = "apispec_2_0_1_whl",
@@ -160,54 +60,23 @@ http_file(
16060
"google_cloud_spanner-1.9.0-py2.py3-none-any.whl")]
16161
)
16262

163-
#########################
164-
# Imports for examples. #
165-
#########################
166-
167-
pip_import(
168-
name = "examples_helloworld",
169-
requirements = "//examples/helloworld:requirements.txt",
170-
)
171-
172-
load(
173-
"@examples_helloworld//:requirements.bzl",
174-
_helloworld_install = "pip_install",
63+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
64+
http_archive(
65+
name = "bazel_federation",
66+
url = "https://github.com/bazelbuild/bazel-federation/archive/4da9b5f83ffae17613fa025a0701fa9db9350d41.zip",
67+
sha256 = "5b1cf980e327a8f30fc81c00c04007c543e17c09ed612fb645753936de790ed7",
68+
strip_prefix = "bazel-federation-4da9b5f83ffae17613fa025a0701fa9db9350d41",
69+
type = "zip",
17570
)
17671

177-
_helloworld_install()
72+
load("@bazel_federation//:repositories.bzl", "rules_python_deps")
73+
rules_python_deps()
17874

179-
pip_import(
180-
name = "examples_version",
181-
requirements = "//examples/version:requirements.txt",
182-
)
183-
184-
load(
185-
"@examples_version//:requirements.bzl",
186-
_version_install = "pip_install",
187-
)
188-
189-
_version_install()
190-
191-
pip_import(
192-
name = "examples_boto",
193-
requirements = "//examples/boto:requirements.txt",
194-
)
75+
load("@bazel_federation//setup:rules_python.bzl", "rules_python_setup")
76+
rules_python_setup(use_pip=True)
19577

196-
load(
197-
"@examples_boto//:requirements.bzl",
198-
_boto_install = "pip_install",
199-
)
200-
201-
_boto_install()
202-
203-
pip_import(
204-
name = "examples_extras",
205-
requirements = "//examples/extras:requirements.txt",
206-
)
207-
208-
load(
209-
"@examples_extras//:requirements.bzl",
210-
_extras_install = "pip_install",
211-
)
78+
load("//:internal_deps.bzl", "rules_python_internal_deps")
79+
rules_python_internal_deps()
21280

213-
_extras_install()
81+
load("//:internal_setup.bzl", "rules_python_internal_setup")
82+
rules_python_internal_setup()

‎docs/BUILD

Copy file name to clipboardExpand all lines: docs/BUILD
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ bzl_library(
3434
"@bazel_tools//tools/python:srcs_version.bzl",
3535
"@bazel_tools//tools/python:toolchain.bzl",
3636
"@bazel_tools//tools/python:utils.bzl",
37+
"@bazel_tools//tools/python:private/defs.bzl",
3738
],
3839
)
3940

‎docs/pip.md

Copy file name to clipboardExpand all lines: docs/pip.md
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ pip_import(<a href="#pip_import-name">name</a>, <a href="#pip_import-requirement
4545
pip_repositories()
4646
</pre>
4747

48-
Pull in dependencies needed for pulling in pip dependencies.
49-
50-
A placeholder method that will eventually pull in any dependencies
51-
needed to install pip dependencies.
48+
Pull in dependencies needed to use the packaging rules.
5249

5350

5451

‎docs/python.md

Copy file name to clipboardExpand all lines: docs/python.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Example usage:
3333
```python
3434
# In your BUILD file...
3535

36-
load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
36+
load("@rules_python//python:defs.bzl", "py_runtime_pair")
3737

3838
py_runtime(
3939
name = "my_py2_runtime",
@@ -57,7 +57,7 @@ toolchain(
5757
name = "my_toolchain",
5858
target_compatible_with = <...>,
5959
toolchain = ":my_py_runtime_pair",
60-
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
60+
toolchain_type = "@rules_python//python:toolchain_type",
6161
)
6262
```
6363

‎examples/boto/BUILD

Copy file name to clipboardExpand all lines: examples/boto/BUILD
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package(default_visibility = ["//visibility:public"])
1616
licenses(["notice"]) # Apache 2.0
1717

1818
load("@examples_boto//:requirements.bzl", "requirement")
19-
load("//python:python.bzl", "py_test")
19+
load("//python:defs.bzl", "py_test")
2020

2121
py_test(
2222
name = "boto_test",

‎examples/extras/BUILD

Copy file name to clipboardExpand all lines: examples/extras/BUILD
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package(default_visibility = ["//visibility:public"])
1616
licenses(["notice"]) # Apache 2.0
1717

1818
load("@examples_extras//:requirements.bzl", "requirement")
19-
load("//python:python.bzl", "py_test")
19+
load("//python:defs.bzl", "py_test")
2020

2121
py_test(
2222
name = "extras_test",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.