Skip to content
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

feat: multi-toolchain support #846

Merged
merged 38 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5d004e0
feat: multi-toolchain support
f0rmiga Oct 3, 2022
ecc3ba9
feat: cross-version testing
f0rmiga Oct 3, 2022
ae419f2
fix: error message
f0rmiga Oct 3, 2022
4d79a84
doc: add link to bazelbuild/bazel PR fixing expand_location
f0rmiga Oct 4, 2022
3441145
fix: set environment variables for py_binary too
f0rmiga Oct 4, 2022
44d6cb4
test: extra case for default version taking another version
f0rmiga Oct 4, 2022
557848a
fix: fail if args attribute is set
f0rmiga Oct 4, 2022
5755c01
fix: remove confusing output with same target name
f0rmiga Oct 4, 2022
cbe5a11
fix: buildifier
f0rmiga Oct 4, 2022
30e520d
revert: use testing.TestEnvironment
f0rmiga Oct 5, 2022
9eb0f3b
fix: linting issues
f0rmiga Oct 5, 2022
3891e54
fix: black linter
f0rmiga Oct 5, 2022
3f65659
refactor: move tests to a sub-dir
f0rmiga Oct 5, 2022
0ec1d4f
feat: add multi_pip_parse
f0rmiga Oct 7, 2022
c412a2e
fix: add missing aliases
f0rmiga Oct 7, 2022
32fa462
fix: use requirement function in example
f0rmiga Oct 7, 2022
17b0ba1
fix: deleted packages
f0rmiga Oct 7, 2022
835d25f
fix: update generated docs
f0rmiga Oct 7, 2022
75ad960
refactor: version checking of the rule is already done by other tests
f0rmiga Oct 7, 2022
ffe07ac
fix: add python_interpreter_target to multi_pip_parse
f0rmiga Oct 11, 2022
8bc79c1
fix: windows
f0rmiga Oct 12, 2022
174663a
refactor: unify py_test and py_binary transition impls
f0rmiga Oct 12, 2022
519f762
fix: test compatible with all platforms
f0rmiga Oct 12, 2022
059aa98
rebase: adjust multi_python_versions on ci
f0rmiga Oct 12, 2022
1053ab0
refactor: use usr flags instead of platforms in transition
f0rmiga Nov 18, 2022
d813740
refactor: rename rule -> rule_impl
f0rmiga Nov 21, 2022
161f068
refactor: reduce repetition of args
f0rmiga Nov 21, 2022
66b33f3
fix: missing test and binary-specific attributes
f0rmiga Nov 21, 2022
cecb3c8
fix: add srcs and deps attrs for path expansion
f0rmiga Nov 21, 2022
90e3314
Merge remote-tracking branch 'origin/main' into f0rmiga/multi-python-…
f0rmiga Nov 22, 2022
562ee9b
fix: missing bazel_skylib on integration tests
f0rmiga Nov 22, 2022
ca49f8b
refactor: use ctx.target_platform_has_constraint over select
f0rmiga Nov 28, 2022
906bb6a
doc: why symlink <name>.zip under Windows
f0rmiga Nov 28, 2022
3316928
fix: apply suggestions from code review
f0rmiga Nov 28, 2022
9c833f1
fix: use incoming edge transitions
f0rmiga Nov 28, 2022
aa0fc9f
fix: use RunEnvironmentInfo when available
f0rmiga Nov 28, 2022
070ec92
Merge remote-tracking branch 'origin/main' into f0rmiga/multi-python-…
f0rmiga Nov 28, 2022
6896f15
fix: cfg should be target not exec
f0rmiga Nov 28, 2022
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
16 changes: 16 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ tasks:
working_directory: examples/bzlmod
platform: windows

integration_test_multi_python_versions_linux:
<<: *reusable_build_test_all
name: multi_python_versions integration tests on Linux
working_directory: examples/multi_python_versions
platform: ubuntu2004
integration_test_multi_python_versions_macos:
<<: *reusable_build_test_all
name: multi_python_versions integration tests on macOS
working_directory: examples/multi_python_versions
platform: macos
integration_test_multi_python_versions_windows:
<<: *reusable_build_test_all
name: multi_python_versions integration tests on Windows
working_directory: examples/multi_python_versions
platform: windows

integration_test_pip_install_linux:
<<: *reusable_build_test_all
name: pip_install integration tests on Linux
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/bzlmod,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,tests/pip_deps
query --deleted_packages=examples/build_file_generation,examples/bzlmod,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,tests/pip_deps
build --deleted_packages=examples/build_file_generation,examples/bzlmod,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/relative_requirements,tests/pip_repository_entry_points,tests/pip_deps
query --deleted_packages=examples/build_file_generation,examples/bzlmod,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/relative_requirements,tests/pip_repository_entry_points,tests/pip_deps

test --test_output=errors

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

rules_python_internal_setup()

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

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

load("//gazelle:deps.bzl", "gazelle_deps")
Expand Down
77 changes: 67 additions & 10 deletions docs/pip.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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ bazel_integration_test(
timeout = "long",
)

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

bazel_integration_test(
name = "bzlmod_example",
bzlmod = True,
Expand Down
5 changes: 5 additions & 0 deletions examples/multi_python_versions/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test --test_output=errors

# Windows requires these for multi-python support:
f0rmiga marked this conversation as resolved.
Show resolved Hide resolved
build --enable_runfiles
startup --windows_enable_symlinks
1 change: 1 addition & 0 deletions examples/multi_python_versions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel-*
59 changes: 59 additions & 0 deletions examples/multi_python_versions/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
workspace(name = "rules_python_multi_python_versions")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_skylib",
sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
],
)

local_repository(
name = "rules_python",
path = "../..",
)

load("@rules_python//python/pip_install:repositories.bzl", "pip_install_dependencies")

pip_install_dependencies()

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

default_python_version = "3.9"

python_register_multi_toolchains(
name = "python",
default_version = default_python_version,
python_versions = [
"3.8",
"3.9",
"3.10",
],
)

load("@python//:pip.bzl", "multi_pip_parse")
load("@python//3.10:defs.bzl", interpreter_3_10 = "interpreter")
load("@python//3.8:defs.bzl", interpreter_3_8 = "interpreter")
load("@python//3.9:defs.bzl", interpreter_3_9 = "interpreter")

multi_pip_parse(
name = "pypi",
default_version = default_python_version,
python_interpreter_target = {
"3.10": interpreter_3_10,
"3.8": interpreter_3_8,
"3.9": interpreter_3_9,
},
requirements_lock = {
"3.10": "//requirements:requirements_lock_3_10.txt",
"3.8": "//requirements:requirements_lock_3_8.txt",
"3.9": "//requirements:requirements_lock_3_9.txt",
},
)

load("@pypi//:requirements.bzl", "install_deps")

install_deps()
9 changes: 9 additions & 0 deletions examples/multi_python_versions/libs/my_lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@pypi//:requirements.bzl", "requirement")
load("@rules_python//python:defs.bzl", "py_library")

py_library(
name = "my_lib",
srcs = ["__init__.py"],
visibility = ["@//tests:__pkg__"],
deps = [requirement("websockets")],
)
5 changes: 5 additions & 0 deletions examples/multi_python_versions/libs/my_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import websockets


def websockets_is_for_python_version(sanitized_version_check):
return f"pypi_{sanitized_version_check}_websockets" in websockets.__file__
24 changes: 24 additions & 0 deletions examples/multi_python_versions/requirements/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@python//3.10:defs.bzl", compile_pip_requirements_3_10 = "compile_pip_requirements")
load("@python//3.8:defs.bzl", compile_pip_requirements_3_8 = "compile_pip_requirements")
load("@python//3.9:defs.bzl", compile_pip_requirements_3_9 = "compile_pip_requirements")

compile_pip_requirements_3_8(
name = "requirements_3_8",
extra_args = ["--allow-unsafe"],
requirements_in = "requirements.in",
requirements_txt = "requirements_lock_3_8.txt",
)

compile_pip_requirements_3_9(
name = "requirements_3_9",
extra_args = ["--allow-unsafe"],
requirements_in = "requirements.in",
requirements_txt = "requirements_lock_3_9.txt",
)

compile_pip_requirements_3_10(
name = "requirements_3_10",
extra_args = ["--allow-unsafe"],
requirements_in = "requirements.in",
requirements_txt = "requirements_lock_3_10.txt",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
websockets
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# This file is autogenerated by pip-compile with python 3.10
# To update, run:
#
# bazel run //requirements:requirements_3_10.update
#
websockets==10.3 \
--hash=sha256:07cdc0a5b2549bcfbadb585ad8471ebdc7bdf91e32e34ae3889001c1c106a6af \
--hash=sha256:210aad7fdd381c52e58777560860c7e6110b6174488ef1d4b681c08b68bf7f8c \
--hash=sha256:28dd20b938a57c3124028680dc1600c197294da5db4292c76a0b48efb3ed7f76 \
--hash=sha256:2f94fa3ae454a63ea3a19f73b95deeebc9f02ba2d5617ca16f0bbdae375cda47 \
--hash=sha256:31564a67c3e4005f27815634343df688b25705cccb22bc1db621c781ddc64c69 \
--hash=sha256:347974105bbd4ea068106ec65e8e8ebd86f28c19e529d115d89bd8cc5cda3079 \
--hash=sha256:379e03422178436af4f3abe0aa8f401aa77ae2487843738542a75faf44a31f0c \
--hash=sha256:3eda1cb7e9da1b22588cefff09f0951771d6ee9fa8dbe66f5ae04cc5f26b2b55 \
--hash=sha256:51695d3b199cd03098ae5b42833006a0f43dc5418d3102972addc593a783bc02 \
--hash=sha256:54c000abeaff6d8771a4e2cef40900919908ea7b6b6a30eae72752607c6db559 \
--hash=sha256:5b936bf552e4f6357f5727579072ff1e1324717902127ffe60c92d29b67b7be3 \
--hash=sha256:6075fd24df23133c1b078e08a9b04a3bc40b31a8def4ee0b9f2c8865acce913e \
--hash=sha256:661f641b44ed315556a2fa630239adfd77bd1b11cb0b9d96ed8ad90b0b1e4978 \
--hash=sha256:6ea6b300a6bdd782e49922d690e11c3669828fe36fc2471408c58b93b5535a98 \
--hash=sha256:6ed1d6f791eabfd9808afea1e068f5e59418e55721db8b7f3bfc39dc831c42ae \
--hash=sha256:7934e055fd5cd9dee60f11d16c8d79c4567315824bacb1246d0208a47eca9755 \
--hash=sha256:7ab36e17af592eec5747c68ef2722a74c1a4a70f3772bc661079baf4ae30e40d \
--hash=sha256:7f6d96fdb0975044fdd7953b35d003b03f9e2bcf85f2d2cf86285ece53e9f991 \
--hash=sha256:83e5ca0d5b743cde3d29fda74ccab37bdd0911f25bd4cdf09ff8b51b7b4f2fa1 \
--hash=sha256:85506b3328a9e083cc0a0fb3ba27e33c8db78341b3eb12eb72e8afd166c36680 \
--hash=sha256:8af75085b4bc0b5c40c4a3c0e113fa95e84c60f4ed6786cbb675aeb1ee128247 \
--hash=sha256:8b1359aba0ff810d5830d5ab8e2c4a02bebf98a60aa0124fb29aa78cfdb8031f \
--hash=sha256:8fbd7d77f8aba46d43245e86dd91a8970eac4fb74c473f8e30e9c07581f852b2 \
--hash=sha256:907e8247480f287aa9bbc9391bd6de23c906d48af54c8c421df84655eef66af7 \
--hash=sha256:93d5ea0b5da8d66d868b32c614d2b52d14304444e39e13a59566d4acb8d6e2e4 \
--hash=sha256:97bc9d41e69a7521a358f9b8e44871f6cdeb42af31815c17aed36372d4eec667 \
--hash=sha256:994cdb1942a7a4c2e10098d9162948c9e7b235df755de91ca33f6e0481366fdb \
--hash=sha256:a141de3d5a92188234afa61653ed0bbd2dde46ad47b15c3042ffb89548e77094 \
--hash=sha256:a1e15b230c3613e8ea82c9fc6941b2093e8eb939dd794c02754d33980ba81e36 \
--hash=sha256:aad5e300ab32036eb3fdc350ad30877210e2f51bceaca83fb7fef4d2b6c72b79 \
--hash=sha256:b529fdfa881b69fe563dbd98acce84f3e5a67df13de415e143ef053ff006d500 \
--hash=sha256:b9c77f0d1436ea4b4dc089ed8335fa141e6a251a92f75f675056dac4ab47a71e \
--hash=sha256:bb621ec2dbbbe8df78a27dbd9dd7919f9b7d32a73fafcb4d9252fc4637343582 \
--hash=sha256:c7250848ce69559756ad0086a37b82c986cd33c2d344ab87fea596c5ac6d9442 \
--hash=sha256:c8d1d14aa0f600b5be363077b621b1b4d1eb3fbf90af83f9281cda668e6ff7fd \
--hash=sha256:d1655a6fc7aecd333b079d00fb3c8132d18988e47f19740c69303bf02e9883c6 \
--hash=sha256:d6353ba89cfc657a3f5beabb3b69be226adbb5c6c7a66398e17809b0ce3c4731 \
--hash=sha256:da4377904a3379f0c1b75a965fff23b28315bcd516d27f99a803720dfebd94d4 \
--hash=sha256:e49ea4c1a9543d2bd8a747ff24411509c29e4bdcde05b5b0895e2120cb1a761d \
--hash=sha256:e4e08305bfd76ba8edab08dcc6496f40674f44eb9d5e23153efa0a35750337e8 \
--hash=sha256:e6fa05a680e35d0fcc1470cb070b10e6fe247af54768f488ed93542e71339d6f \
--hash=sha256:e7e6f2d6fd48422071cc8a6f8542016f350b79cc782752de531577d35e9bd677 \
--hash=sha256:e904c0381c014b914136c492c8fa711ca4cced4e9b3d110e5e7d436d0fc289e8 \
--hash=sha256:ec2b0ab7edc8cd4b0eb428b38ed89079bdc20c6bdb5f889d353011038caac2f9 \
--hash=sha256:ef5ce841e102278c1c2e98f043db99d6755b1c58bde475516aef3a008ed7f28e \
--hash=sha256:f351c7d7d92f67c0609329ab2735eee0426a03022771b00102816a72715bb00b \
--hash=sha256:fab7c640815812ed5f10fbee7abbf58788d602046b7bb3af9b1ac753a6d5e916 \
--hash=sha256:fc06cc8073c8e87072138ba1e431300e2d408f054b27047d047b549455066ff4
# via -r requirements/requirements.in
Loading