Skip to content

Commit

Permalink
feat(bzlmod): expose platform-agnostic repo target for toolchain inte…
Browse files Browse the repository at this point in the history
…rpreter (#1155)

This exposes a new repo and target, `@{name}_host_interpreter//:python`,
created by `python.toolchain()`, that points to the host OS's Python
interpreter for that particular toolchain.

This solves two problems:
1. `pip.parse()` can now refer to the same interpreter used in the
toolchains
2. There is now a canonical, public, way to refer to the host OS Python
interpreter
    for repository rules.

The above were _sort of_ possible for users to do already, but it
required them to write much more configuration and extension code to do
so. This moves that sort of boilerplate into our code so they have a
simpler configuration.

Also:
- removing bzlmod support in the build_file_generation example; making
examples work
  with both WORKSPACE and MODULE is a pain, hence splitting them.
- adding an example of bzlmod and gazelle
- improved documentation in the pip arguments

Closes: #1161
  • Loading branch information
chrislovecnm authored May 4, 2023
1 parent 262c699 commit 0912bba
Show file tree
Hide file tree
Showing 33 changed files with 2,288 additions and 17 deletions.
42 changes: 42 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ buildifier:
test_targets: ["..."]
.coverage_targets_example_bzlmod: &coverage_targets_example_bzlmod
coverage_targets: ["//:test"]
.coverage_targets_example_bzlmod_build_file_generation: &coverage_targets_example_bzlmod_build_file_generation
coverage_targets: ["//:bzlmod_build_file_generation_test"]
.coverage_targets_example_multi_python: &coverage_targets_example_multi_python
coverage_targets:
- //tests:my_lib_3_10_test
Expand Down Expand Up @@ -179,6 +181,46 @@ tasks:
working_directory: examples/bzlmod
platform: windows

integration_test_bzlmod_generate_build_file_generation_ubuntu_min:
<<: *minimum_supported_bzlmod_version
<<: *reusable_build_test_all
<<: *coverage_targets_example_bzlmod_build_file_generation
name: example bzlmod build file min bazel version integration test
working_directory: examples/bzlmod_build_file_generation
platform: ubuntu2004
integration_test_bzlmod_generation_build_files_ubuntu:
<<: *reusable_build_test_all
<<: *coverage_targets_example_bzlmod_build_file_generation
name: example bzlmod build file integration test
working_directory: examples/bzlmod_build_file_generation
platform: ubuntu2004
integration_test_bzlmod_generation_build_files_ubuntu_run:
<<: *reusable_build_test_all
name: example bzlmod build file running gazelle and pip integration test
working_directory: examples/bzlmod_build_file_generation
platform: ubuntu2004
shell_commands:
- "bazel run //:gazelle_python_manifest.update"
- "bazel run //:gazelle -- update"
integration_test_bzlmod_build_file_generation_debian:
<<: *reusable_build_test_all
<<: *coverage_targets_example_bzlmod_build_file_generation
name: example bzlmod build file integration test
working_directory: examples/bzlmod_build_file_generation
platform: debian11
integration_test_bzlmod_build_file_generation_macos:
<<: *reusable_build_test_all
<<: *coverage_targets_example_bzlmod_build_file_generation
name: example bzlmod build file integration test
working_directory: examples/bzlmod_build_file_generation
platform: macos
integration_test_bzlmod_build_file_generation_windows:
<<: *reusable_build_test_all
# coverage is not supported on Windows
name: example bzlmod build file integration test
working_directory: examples/bzlmod_build_file_generation
platform: windows

integration_test_multi_python_versions_ubuntu_min:
<<: *minimum_supported_version
<<: *reusable_build_test_all
Expand Down
4 changes: 2 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/build_file_generation/get_url,examples/bzlmod,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/runfiles,examples/multi_python_versions,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/py_proto_library,examples/relative_requirements,tests/compile_pip_requirements,tests/pip_repository_entry_points,tests/pip_deps
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/get_url,examples/bzlmod,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/runfiles,examples/multi_python_versions,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/py_proto_library,examples/relative_requirements,tests/compile_pip_requirements,tests/pip_repository_entry_points,tests/pip_deps
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/get_url,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/runfiles,examples/multi_python_versions,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/py_proto_library,examples/relative_requirements,tests/compile_pip_requirements,tests/pip_repository_entry_points,tests/pip_deps
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/get_url,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/runfiles,examples/multi_python_versions,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/py_proto_library,examples/relative_requirements,tests/compile_pip_requirements,tests/pip_repository_entry_points,tests/pip_deps

test --test_output=errors

Expand Down
4 changes: 2 additions & 2 deletions docs/pip_repository.md

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

5 changes: 5 additions & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ bazel_integration_test(
timeout = "long",
)

bazel_integration_test(
name = "bzlmod_build_file_generation_example",
timeout = "long",
)

bazel_integration_test(
name = "pip_install_example",
timeout = "long",
Expand Down
2 changes: 1 addition & 1 deletion examples/build_file_generation/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test --test_output=errors
test --test_output=errors --enable_runfiles

# Windows requires these for multi-python support:
build --enable_runfiles
Expand Down
Loading

0 comments on commit 0912bba

Please sign in to comment.