Skip to content

Commit

Permalink
Merge branch 'bazelbuild:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ianoc authored May 31, 2022
2 parents 3c4c15a + d598085 commit d34cf10
Show file tree
Hide file tree
Showing 55 changed files with 1,804 additions and 146 deletions.
2 changes: 2 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ platforms:
- "-//gazelle/..."
# The dependencies needed for this test are not cross-platform: https://github.com/bazelbuild/rules_python/issues/260
- "-//tests:pip_repository_entry_points_example"
test_flags:
- "--test_tag_filters=-fix-windows"
6 changes: 4 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# This lets us glob() up all the files inside the examples to make them inputs to tests
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
# To update these lines, run tools/bazel_integration_test/update_deleted_packages.sh
build --deleted_packages=examples/build_file_generation,examples/pip_install,examples/pip_parse,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/pip_repository_entry_points
query --deleted_packages=examples/build_file_generation,examples/pip_install,examples/pip_parse,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/pip_repository_entry_points
build --deleted_packages=examples/build_file_generation,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/pip_repository_entry_points
query --deleted_packages=examples/build_file_generation,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/pip_repository_entry_points

test --test_output=errors

Expand All @@ -18,3 +18,5 @@ build --incompatible_default_to_explicit_init_py

# Windows makes use of runfiles for some rules
build --enable_runfiles
# TODO(f0rmiga): remove this so that other features don't start relying on it.
startup --windows_enable_symlinks
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs/*.md linguist-generated=true
6 changes: 3 additions & 3 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# NB: Last matching rule takes precedence in CODEOWNERS.

# Fall-through to community maintainers.
* @thundergolfer @andyscott
* @thundergolfer

# Core Python rules belong to the Bazel team.
/python/ @brandjon @lberki
# But not everything under python/ is the core Python rules.
/python/pip.bzl @thundergolfer @andyscott
/python/requirements.txt @thundergolfer @andyscott
/python/pip.bzl @thundergolfer
/python/requirements.txt @thundergolfer

# Directory containing the Gazelle extension and Go code.
/gazelle/ @f0rmiga
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/workspace_snippet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -o errexit -o nounset -o pipefail
# Set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
TAG=${GITHUB_REF_NAME}
PREFIX="rules_python-${TAG:1}"
PREFIX="rules_python-${TAG}"
SHA=$(git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip | shasum -a 256 | awk '{print $1}')

cat << EOF
Expand All @@ -17,7 +17,7 @@ http_archive(
name = "rules_python",
sha256 = "${SHA}",
strip_prefix = "${PREFIX}",
url = "https://github.com/bazelbuild/rules_python/archive/${TAG}.tar.gz",
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/${TAG}.tar.gz",
)
\`\`\`
EOF
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,37 @@ http_archive(
)
```

### Toolchain registration

To register a hermetic Python toolchain rather than rely on a system-installed interpreter for runtime execution, you can add to the `WORKSPACE` file:

```python
load("@rules_python//python:repositories.bzl", "python_register_toolchains")

python_register_toolchains(
name = "python3_9",
# Available versions are listed in @rules_python//python:versions.bzl.
# We recommend using the same version your team is already standardized on.
python_version = "3.9",
)

load("@python3_9//:defs.bzl", "interpreter")

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

pip_parse(
...
python_interpreter_target = interpreter,
...
)
```

After registration, your Python targets will use the toolchain's interpreter during execution, but a system-installed interpreter
is still used to 'bootstrap' Python targets (see https://github.com/bazelbuild/rules_python/issues/691).
You may also find some quirks while using this toolchain. Please refer to [python-build-standalone documentation's _Quirks_ section](https://python-build-standalone.readthedocs.io/en/latest/quirks.html) for details.

### "Hello World"

Once you've imported the rule set into your `WORKSPACE` using any of these
methods, you can then load the core rules in your `BUILD` files with:

Expand Down Expand Up @@ -109,8 +140,8 @@ one another, and may result in downloading the same wheels multiple times.

As with any repository rule, if you would like to ensure that `pip_install` is
re-executed in order to pick up a non-hermetic change to your environment (e.g.,
updating your system `python` interpreter), you can completely flush out your
repo cache with `bazel clean --expunge`.
updating your system `python` interpreter), you can force it to re-execute by running
`bazel sync --only [pip_install name]`.

### Fetch `pip` dependencies lazily

Expand Down
9 changes: 9 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ load("//:internal_setup.bzl", "rules_python_internal_setup")

rules_python_internal_setup()

load("//python:repositories.bzl", "python_register_toolchains")
load("//python:versions.bzl", "MINOR_MAPPING")

python_register_toolchains(
name = "python",
# We always use the latest Python internally.
python_version = MINOR_MAPPING.values()[-1],
)

load("//gazelle:deps.bzl", "gazelle_deps")

# gazelle:repository_macro gazelle/deps.bzl%gazelle_deps
Expand Down
13 changes: 13 additions & 0 deletions docs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ licenses(["notice"]) # Apache 2.0
_DOCS = {
"packaging": "//docs:packaging-docs",
"pip": "//docs:pip-docs",
"pip_repository": "//docs:pip-repository",
"python": "//docs:core-docs",
}

Expand Down Expand Up @@ -104,6 +105,18 @@ stardoc(
],
)

stardoc(
name = "pip-repository",
out = "pip_repository.md_",
input = "//python/pip_install:pip_repository.bzl",
target_compatible_with = _NOT_WINDOWS,
deps = [
":bazel_repo_tools",
":pip_install_bzl",
"//third_party/github.com/bazelbuild/bazel-skylib/lib:versions",
],
)

stardoc(
name = "packaging-docs",
out = "packaging.md_",
Expand Down
32 changes: 26 additions & 6 deletions docs/pip.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d34cf10

Please sign in to comment.