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 5c948dc

Browse filesBrowse files
author
Jonathon Belotti
authored
README update (related to 0.1.0 release) (bazel-contrib#369)
* README update: remove outdated refs to 'pip_import', add 'Recent Update', remove 'git_repository' usage * add section about legacy 'pip_import'
1 parent c8c79aa commit 5c948dc
Copy full SHA for 5c948dc

File tree

1 file changed

+46
-30
lines changed
Filter options

1 file changed

+46
-30
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+46-30Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
## Recent updates
77

8+
* 2020-10-15: Release [`0.1.0` was published](https://github.com/bazelbuild/rules_python/releases/tag/0.1.0), upstreaming
9+
the `pip_install` rule functionality from [github.com/dillon-giacoppo/rules_python_external](https://github.com/dillon-giacoppo/rules_python_external)
10+
to address a number of long-standing issues with `pip_import` (eg. [#96](https://github.com/bazelbuild/rules_python/issues/96), [#71](https://github.com/bazelbuild/rules_python/issues/71), [#102](https://github.com/bazelbuild/rules_python/issues/102)).
11+
Note that this is a backwards-incompatible release on account of the removal of `pip_import` from `@rules_python//python:pip.bzl`.
12+
813
* 2019-11-15: Added support for `pip3_import` (and more generally, a
914
`python_interpreter` attribute to `pip_import`). The canonical naming for wheel
1015
repositories has changed to accomodate loading wheels for both `pip_import` and
@@ -38,7 +43,7 @@ Once they are fully migrated to rules_python, they may evolve at a different
3843
rate, but this repository will still follow
3944
[semantic versioning](https://semver.org).
4045

41-
The packaging rules (`pip_import`, etc.) are less stable. We may make breaking
46+
The packaging rules (`pip_install`, etc.) are less stable. We may make breaking
4247
changes as they evolve. There are no guarantees for rules underneath the
4348
`experimental/` directory.
4449

@@ -56,9 +61,8 @@ To import rules_python in your project, you first need to add it to your
5661
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
5762
http_archive(
5863
name = "rules_python",
59-
url = "https://github.com/bazelbuild/rules_python/releases/download/0.0.2/rules_python-0.0.2.tar.gz",
60-
strip_prefix = "rules_python-0.0.2",
61-
sha256 = "b5668cde8bb6e3515057ef465a35ad712214962f0b3a314e551204266c7be90c",
64+
url = "https://github.com/bazelbuild/rules_python/releases/download/0.1.0/rules_python-0.1.0.tar.gz",
65+
sha256 = "b6d46438523a3ec0f3cead544190ee13223a52f6a6765a29eae7b7cc24cc83a0",
6266
)
6367
```
6468

@@ -69,20 +73,21 @@ load("@rules_python//python:pip.bzl", "pip_repositories")
6973
pip_repositories()
7074
```
7175

72-
To depend on a particular unreleased version (not recommended), you can
73-
use `git_repository` instead of `http_archive`:
76+
To depend on a particular unreleased version (not recommended), you can do:
7477

7578
```python
76-
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
79+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
80+
81+
rules_python_version = "c8c79aae9aa1b61d199ad03d5fe06338febd0774" # Latest @ 2020-10-15
7782

78-
git_repository(
83+
http_archive(
7984
name = "rules_python",
80-
remote = "https://github.com/bazelbuild/rules_python.git",
81-
# NOT VALID: Replace with actual Git commit SHA.
82-
commit = "{HEAD}",
85+
sha256 = "5be9610a959772697f57ec66bb58c8132970686ed7fb0f1cf81b22ddf12f5368",
86+
strip_prefix = "rules_python-{}".format(rules_python_version),
87+
url = "https://github.com/bazelbuild/rules_python/archive/{}.zip".format(rules_python_version),
8388
)
8489

85-
# Then load and call py_repositories() and possibly pip_repositories() as
90+
# Then load and call py_repositories() as
8691
# above.
8792
```
8893

@@ -110,47 +115,58 @@ target in the appropriate wheel repo.
110115

111116
### Importing `pip` dependencies
112117

113-
Adding pip dependencies to your `WORKSPACE` is a two-step process. First you
114-
declare the central repository using `pip_import`, which invokes pip to read
115-
a `requirements.txt` file and download the appropriate wheels. Then you load
116-
the `pip_install` function from the central repo, and call it to create the
118+
To add pip dependencies to your `WORKSPACE` is you load
119+
the `pip_install` function, and call it to create the
117120
individual wheel repos.
118121

119-
**Important:** If you are using Python 3, load and call `pip3_import` instead.
120122

121123
```python
122-
load("@rules_python//python:pip.bzl", "pip_import")
124+
load("@rules_python//python:pip.bzl", "pip_install")
123125

124126
# Create a central repo that knows about the dependencies needed for
125127
# requirements.txt.
126-
pip_import( # or pip3_import
128+
pip_install( # or pip3_import
127129
name = "my_deps",
128130
requirements = "//path/to:requirements.txt",
129131
)
130-
131-
# Load the central repo's install function from its `//:requirements.bzl` file,
132-
# and call it.
133-
load("@my_deps//:requirements.bzl", "pip_install")
134-
pip_install()
135132
```
136133

137134
Note that since pip is executed at WORKSPACE-evaluation time, Bazel has no
138135
information about the Python toolchain and cannot enforce that the interpreter
139136
used to invoke pip matches the interpreter used to run `py_binary` targets. By
140-
default, `pip_import` uses the system command `"python"`, which on most
137+
default, `pip_install` uses the system command `"python"`, which on most
141138
platforms is a Python 2 interpreter. This can be overridden by passing the
142-
`python_interpreter` attribute to `pip_import`. `pip3_import` just acts as a
143-
wrapper that sets `python_interpreter` to `"python3"`.
139+
`python_interpreter` attribute or `python_interpreter_target` attribute to `pip_install`.
144140

145-
You can have multiple `pip_import`s in the same workspace, e.g. for Python 2
141+
You can have multiple `pip_install`s in the same workspace, e.g. for Python 2
146142
and Python 3. This will create multiple central repos that have no relation to
147143
one another, and may result in downloading the same wheels multiple times.
148144

149-
As with any repository rule, if you would like to ensure that `pip_import` is
150-
reexecuted in order to pick up a non-hermetic change to your environment (e.g.,
145+
As with any repository rule, if you would like to ensure that `pip_install` is
146+
re-executed in order to pick up a non-hermetic change to your environment (e.g.,
151147
updating your system `python` interpreter), you can completely flush out your
152148
repo cache with `bazel clean --expunge`.
153149

150+
### Importing `pip` dependencies with `pip_import` (legacy)
151+
152+
The deprecated `pip_import` can still be used if needed.
153+
154+
```
155+
load("@rules_python//python/legacy_pip_import:pip.bzl", "pip_import", "pip_repositories")
156+
157+
# Create a central repo that knows about the dependencies needed for requirements.txt.
158+
pip_import( # or pip3_import
159+
name = "my_deps",
160+
requirements = "//path/to:requirements.txt",
161+
)
162+
163+
# Load the central repo's install function from its `//:requirements.bzl` file, and call it.
164+
load("@my_deps//:requirements.bzl", "pip_install")
165+
pip_install()
166+
```
167+
168+
An example can be found in [`examples/legacy_pip_import](examples/legacy_pip_import).
169+
154170
### Consuming `pip` dependencies
155171

156172
Each extracted wheel repo contains a `py_library` target representing the

0 commit comments

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