Skip to content

pip: 20.3.4 -> 21.0.1 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ http_archive(
)
```

If you want to use the pip packaging rules, also add:

```python
load("@rules_python//python:pip.bzl", "pip_repositories")
pip_repositories()
```

To depend on a particular unreleased version (not recommended), you can do:

```python
Expand Down Expand Up @@ -122,7 +115,7 @@ load("@rules_python//python:pip.bzl", "pip_install")

# Create a central repo that knows about the dependencies needed for
# requirements.txt.
pip_install( # or pip3_import
pip_install(
name = "my_deps",
requirements = "//path/to:requirements.txt",
)
Expand All @@ -131,8 +124,7 @@ pip_install( # or pip3_import
Note that since pip is executed at WORKSPACE-evaluation time, Bazel has no
information about the Python toolchain and cannot enforce that the interpreter
used to invoke pip matches the interpreter used to run `py_binary` targets. By
default, `pip_install` uses the system command `"python"`, which on most
platforms is a Python 2 interpreter. This can be overridden by passing the
default, `pip_install` uses the system command `"python3"`. This can be overridden by passing the
`python_interpreter` attribute or `python_interpreter_target` attribute to `pip_install`.

You can have multiple `pip_install`s in the same workspace, e.g. for Python 2
Expand Down Expand Up @@ -184,7 +176,7 @@ py_library(
deps = [
":myotherlib",
requirement("some_pip_dep"),
requirement("anohter_pip_dep[some_extra]"),
requirement("another_pip_dep[some_extra]"),
]
)
```
Expand All @@ -196,6 +188,20 @@ are replaced with `_`. While this naming pattern doesn't change often, it is
not guaranted to remain stable, so use of the `requirement()` function is
recommended.

### Consuming Wheel Dists Directly

If you need to depend on the wheel dists themselves, for instance to pass them
to some other packaging tool, you can get a handle to them with the `whl_requirement` macro. For example:

```python
filegroup(
name = "whl_files",
data = [
whl_requirement("boto3"),
]
)
```

## Migrating from the bundled rules

The core rules are currently available in Bazel as built-in symbols, but this
Expand Down
1 change: 0 additions & 1 deletion distro/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ print_rel_notes(
name = "relnotes",
outs = ["relnotes.txt"],
repo = "rules_python",
setup_file = "python:repositories.bzl",
version = version,
)
44 changes: 43 additions & 1 deletion experimental/examples/wheel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ py_library(
],
)

py_library(
name = "main_with_gen_data",
srcs = ["main.py"],
data = [
":gen_dir",
],
)

genrule(
name = "gen_dir",
outs = ["someDir"],
cmd = "mkdir -p $@ && touch $@/foo.py",
)

# Package just a specific py_libraries, without their dependencies
py_wheel(
name = "minimal_with_py_library",
Expand All @@ -53,6 +67,12 @@ py_package(
deps = [":main"],
)

py_package(
name = "example_pkg_with_data",
packages = ["experimental.examples.wheel"],
deps = [":main_with_gen_data"]
)

py_wheel(
name = "minimal_with_py_package",
# Package data. We're building "example_minimal_package-0.0.1-py3-none-any.whl"
Expand Down Expand Up @@ -146,6 +166,26 @@ py_wheel(
],
)

py_wheel(
name = "use_genrule_with_dir_in_outs",
distribution = "use_genrule_with_dir_in_outs",
python_tag = "py3",
version = "0.0.1",
deps = [
":example_pkg_with_data"
]
)

py_wheel(
name = "python_abi3_binary_wheel",
abi = "abi3",
distribution = "example_python_abi3_binary_wheel",
platform = "manylinux2014_x86_64",
python_requires = ">=3.8",
python_tag = "cp38",
version = "0.0.1",
)

py_test(
name = "wheel_test",
srcs = ["wheel_test.py"],
Expand All @@ -156,6 +196,8 @@ py_test(
":customized",
":minimal_with_py_library",
":minimal_with_py_package",
":python_requires_in_a_package"
":python_abi3_binary_wheel",
":python_requires_in_a_package",
":use_genrule_with_dir_in_outs",
],
)
53 changes: 53 additions & 0 deletions experimental/examples/wheel/wheel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,59 @@ def test_python_requires_wheel(self):
UNKNOWN
""")

def test_python_abi3_binary_wheel(self):
filename = os.path.join(
os.environ["TEST_SRCDIR"],
"rules_python",
"experimental",
"examples",
"wheel",
"example_python_abi3_binary_wheel-0.0.1-cp38-abi3-manylinux2014_x86_64.whl",
)
with zipfile.ZipFile(filename) as zf:
metadata_contents = zf.read(
"example_python_abi3_binary_wheel-0.0.1.dist-info/METADATA"
)
# The entries are guaranteed to be sorted.
self.assertEqual(
metadata_contents,
b"""\
Metadata-Version: 2.1
Name: example_python_abi3_binary_wheel
Version: 0.0.1
Requires-Python: >=3.8

UNKNOWN
""",
)
wheel_contents = zf.read(
"example_python_abi3_binary_wheel-0.0.1.dist-info/WHEEL"
)
self.assertEqual(
wheel_contents,
b"""\
Wheel-Version: 1.0
Generator: bazel-wheelmaker 1.0
Root-Is-Purelib: false
Tag: cp38-abi3-manylinux2014_x86_64
""",
)

def test_genrule_creates_directory_and_is_included_in_wheel(self):
filename = os.path.join(os.environ['TEST_SRCDIR'],
'rules_python', 'experimental',
'examples', 'wheel',
'use_genrule_with_dir_in_outs-0.0.1-py3-none-any.whl')

with zipfile.ZipFile(filename) as zf:
self.assertEquals(
zf.namelist(),
['experimental/examples/wheel/main.py',
'experimental/examples/wheel/someDir/foo.py',
'use_genrule_with_dir_in_outs-0.0.1.dist-info/WHEEL',
'use_genrule_with_dir_in_outs-0.0.1.dist-info/METADATA',
'use_genrule_with_dir_in_outs-0.0.1.dist-info/RECORD'])


if __name__ == '__main__':
unittest.main()
20 changes: 16 additions & 4 deletions experimental/python/wheel.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,27 @@ This should match the project name onm PyPI. It's also the name that is used to
refer to the package in other packages' dependencies.
""",
),
# TODO(pstradomski): Support non-pure wheels
"platform": attr.string(
default = "any",
doc = "Supported platforms. 'any' for pure-Python wheel.",
doc = """\
Supported platform. Use 'any' for pure-Python wheel.

If you have included platform-specific data, such as a .pyd or .so
extension module, you will need to specify the platform in standard
pip format. If you support multiple platforms, you can define
platform constraints, then use a select() to specify the appropriate
specifier, eg:

platform = select({
"//platforms:windows_x86_64": "win_amd64",
"//platforms:macos_x86_64": "macosx_10_7_x86_64",
"//platforms:linux_x86_64": "manylinux2014_x86_64",
})
""",
),
"python_tag": attr.string(
default = "py3",
doc = "Supported Python major version. 'py2' or 'py3'",
values = ["py2", "py3"],
doc = "Supported Python version(s), eg 'py3', 'cp35.cp36', etc",
),
"version": attr.string(
mandatory = True,
Expand Down
14 changes: 9 additions & 5 deletions experimental/tools/wheelmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ def arcname_from(name):

return normalized_arcname

if os.path.isdir(real_filename):
directory_contents = os.listdir(real_filename)
for file_ in directory_contents:
self.add_file("{}/{}".format(package_filename, file_),
"{}/{}".format(real_filename, file_))
return

arcname = arcname_from(package_filename)

self._zipfile.write(real_filename, arcname=arcname)
Expand All @@ -123,8 +130,8 @@ def add_wheelfile(self):
wheel_contents = """\
Wheel-Version: 1.0
Generator: bazel-wheelmaker 1.0
Root-Is-Purelib: true
"""
Root-Is-Purelib: {}
""".format("true" if self._platform == "any" else "false")
for tag in self.disttags():
wheel_contents += "Tag: %s\n" % tag
self.add_string(self.distinfo_path('WHEEL'), wheel_contents)
Expand Down Expand Up @@ -255,9 +262,6 @@ def main():
"Can be supplied multiple times.")
arguments = parser.parse_args(sys.argv[1:])

# add_wheelfile and add_metadata currently assume pure-Python.
assert arguments.platform == 'any', "Only pure-Python wheels are supported"

if arguments.input_file:
input_files = [i.split(';') for i in arguments.input_file]
else:
Expand Down
Loading