Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aignas committed May 24, 2024
1 parent 01719b2 commit 6c19b7b
Show file tree
Hide file tree
Showing 4 changed files with 356 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
# To update these lines, execute
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/dupe_requirements,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/pip_repository_entry_points,tests/integration/py_cc_toolchain_registered
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/dupe_requirements,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/pip_repository_entry_points,tests/integration/py_cc_toolchain_registered
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/python/private,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/pip_repository_entry_points,tests/integration/py_cc_toolchain_registered
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/python/private,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/pip_repository_entry_points,tests/integration/py_cc_toolchain_registered

test --test_output=errors

Expand Down
5 changes: 5 additions & 0 deletions tests/private/pip_config_settings/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load(":pip_config_settings_tests.bzl", "pip_config_settings_test_suite")

pip_config_settings_test_suite(
name = "pip_config_settings",
)
341 changes: 341 additions & 0 deletions tests/private/pip_config_settings/pip_config_settings_tests.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,341 @@
# Copyright 2024 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for construction of Python version matching config settings."""

load("@bazel_skylib//lib:selects.bzl", "selects")
load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
load("@rules_testing//lib:test_suite.bzl", "test_suite")
load("@rules_testing//lib:truth.bzl", "subjects")
load("@rules_testing//lib:util.bzl", rt_util = "util")
load("//python/private:pip_config_settings.bzl", "pip_config_settings")
load("//python/private:whl_select_dict.bzl", "whl_select_dict")

_PLATFORMS = [
"manylinux1_x86_64",
"manylinux_2_27_aarch64",
"musllinux_1_1_x86_64",
"musllinux_1_1_aarch64",
"macosx_12_0_universal2",
"macosx_12_0_aarch64",
"macosx_12_0_x86_64",
"win_amd64",
]

_tests = []

def _subject_impl(ctx):
_ = ctx # @unused
return [DefaultInfo()]

_subject = rule(
implementation = _subject_impl,
attrs = {
"all_dists_match": attr.string(),
"any_match": attr.string(),
"sdist_match": attr.string(),
},
)

def _test_library_matching(name, test):
select_values = {}
dists = [
(
"foo-0.0.1{}".format(suffix),
[
("3.11", None),
("3.12", None),
] if "-cp311-" not in suffix else [
("3.11", None),
],
)
for suffix in [
".tar.gz",
"-py3-none-any.whl",
#"-py3-abi3-any.whl",
] + [
"-" + "-".join([py, abi_tag, platform + ".whl"])
for py in ["py3"]
# Let's simulate not all whls being available on cp312
for abi_tag in ["none", "abi3", "cp311"]
for platform in _PLATFORMS
]
]

attr_dists = {
"all_dists_match": dists,
"any_match": [
(
"foo-0.0.1-py2.py3-none-any.whl",
[
("3.11", None),
],
),
(
"foo-0.0.1.tar.gz",
[
("3.11", None),
],
),
],
"sdist_match": [
(
"foo-0.0.1.tar.gz",
[
("3.11", None),
],
),
],
}
for attr, dists in attr_dists.items():
if attr not in test.attrs:
continue
select_value, _ = whl_select_dict(
hub_name = "hub",
default_version = "3.11",
target_name = "pkg",
dists = dists,
condition_package = Label(":unused").package,
)
select_values[attr] = select_value

rt_util.helper_target(
_subject,
name = name + "_subject",
**{
k: selects.with_or(v)
for k, v in select_values.items()
}
)

config_settings = {
"cp311_linux_aarch64": {
Label("//python/config_settings:python_version"): "3.11.1",
"//command_line_option:platforms": Label("//tests/support:linux_aarch64"),
},
"cp311_linux_aarch64_sdist": {
Label(":whl"): "no",
Label("//python/config_settings:python_version"): "3.11.1",
"//command_line_option:platforms": Label("//tests/support:linux_aarch64"),
},
"cp312_osx_aarch64": {
Label("//python/config_settings:python_version"): "3.12.1",
"//command_line_option:platforms": Label("//tests/support:osx_aarch64"),
},
"linux_aarch64": {
"//command_line_option:platforms": Label("//tests/support:linux_aarch64"),
},
"linux_aarch64_musl": {
Label(":whl_linux_libc"): "musl",
"//command_line_option:platforms": Label("//tests/support:linux_aarch64"),
},
"osx_aarch64_any": {
Label(":whl_plat"): "no",
"//command_line_option:platforms": Label("//tests/support:osx_aarch64"),
},
"osx_aarch64_any_abi_none": {
Label(":whl_abi3"): "no",
Label(":whl_cpxy"): "no",
Label(":whl_plat"): "no",
"//command_line_option:platforms": Label("//tests/support:osx_aarch64"),
},
"osx_aarch64_multiarch": {
Label(":whl_osx_arch"): "multiarch",
"//command_line_option:platforms": Label("//tests/support:osx_aarch64"),
},
}

analysis_test(
name = name,
target = name + "_subject",
impl = test.expect,
config_settings = {
str(k): str(v)
for k, v in config_settings[test.setting].items()
},
)

def _match(env, target, expect):
target = env.expect.that_target(target)
for attr, want in expect.items():
target.attr(attr, factory = subjects.str).equals(want)

def _test_matching_defaults(name):
_test_library_matching(
name = name,
test = struct(
name = "selecting an any wheel by default",
setting = "linux_aarch64",
attrs = [
"any_match",
"all_dists_match",
"sdist_match",
],
expect = lambda env, target: _match(env, target, {
"all_dists_match": "@hub_foo_0_0_1_py3_cp311_manylinux_2_27_aarch64//:pkg",
"any_match": "@hub_foo_0_0_1_py3_none_any//:pkg",
"sdist_match": "@hub_foo_0_0_1_sdist//:pkg",
}),
),
)

_tests.append(_test_matching_defaults)

def _test_matching_with_py_version(name):
_test_library_matching(
name = name,
test = struct(
name = "selecting an any wheel by default",
setting = "cp311_linux_aarch64",
attrs = [
"any_match",
"sdist_match",
],
expect = lambda env, target: _match(env, target, {
"any_match": "@hub_foo_0_0_1_py3_none_any//:pkg",
"sdist_match": "@hub_foo_0_0_1_sdist//:pkg",
}),
),
)

_tests.append(_test_matching_with_py_version)

def _test_using_sdists(name):
_test_library_matching(
name = name,
test = struct(
setting = "cp311_linux_aarch64_sdist",
attrs = [
"all_dists_match",
"sdist_match",
],
expect = lambda env, target: _match(env, target, {
"all_dists_match": "@hub_foo_0_0_1_sdist//:pkg",
"sdist_match": "@hub_foo_0_0_1_sdist//:pkg",
}),
),
)

_tests.append(_test_using_sdists)

def _test_using_osx_fat_wheels(name):
_test_library_matching(
name = name,
test = struct(
setting = "osx_aarch64_multiarch",
attrs = [
"any_match",
"all_dists_match",
"sdist_match",
],
expect = lambda env, target: _match(env, target, {
"all_dists_match": "@hub_foo_0_0_1_py3_cp311_macosx_12_0_universal2//:pkg",
"any_match": "@hub_foo_0_0_1_py3_none_any//:pkg",
"sdist_match": "@hub_foo_0_0_1_sdist//:pkg",
}),
),
)

_tests.append(_test_using_osx_fat_wheels)

def _test_prefer_any_whls(name):
_test_library_matching(
name = name,
test = struct(
setting = "osx_aarch64_any",
attrs = [
"any_match",
"all_dists_match",
"sdist_match",
],
expect = lambda env, target: _match(env, target, {
"all_dists_match": "@hub_foo_0_0_1_py3_none_any//:pkg",
"any_match": "@hub_foo_0_0_1_py3_none_any//:pkg",
"sdist_match": "@hub_foo_0_0_1_sdist//:pkg",
}),
),
)

_tests.append(_test_prefer_any_whls)

def _test_using_musl_wheels(name):
_test_library_matching(
name = name,
test = struct(
setting = "linux_aarch64_musl",
attrs = [
"any_match",
"all_dists_match",
"sdist_match",
],
expect = lambda env, target: _match(env, target, {
"all_dists_match": "@hub_foo_0_0_1_py3_cp311_musllinux_1_1_aarch64//:pkg",
"any_match": "@hub_foo_0_0_1_py3_none_any//:pkg",
"sdist_match": "@hub_foo_0_0_1_sdist//:pkg",
}),
),
)

_tests.append(_test_using_musl_wheels)

def _test_prefer_abi_none_whls(name):
_test_library_matching(
name = name,
test = struct(
setting = "osx_aarch64_any_abi_none",
attrs = [
"any_match",
"all_dists_match",
"sdist_match",
],
expect = lambda env, target: _match(env, target, {
"all_dists_match": "@hub_foo_0_0_1_py3_none_any//:pkg",
"any_match": "@hub_foo_0_0_1_py3_none_any//:pkg",
"sdist_match": "@hub_foo_0_0_1_sdist//:pkg",
}),
),
)

_tests.append(_test_prefer_abi_none_whls)

def _test_new_version_of_python(name):
_test_library_matching(
name = name,
test = struct(
setting = "cp312_osx_aarch64",
debug = True,
attrs = [
"any_match",
"all_dists_match",
"sdist_match",
],
expect = lambda env, target: _match(env, target, {
"all_dists_match": "@hub_foo_0_0_1_py3_abi3_macosx_12_0_aarch64//:pkg",
"any_match": "@hub_foo_0_0_1_py3_none_any//:pkg",
"sdist_match": "@hub_foo_0_0_1_sdist//:pkg",
}),
),
)

_tests.append(_test_new_version_of_python)

def pip_config_settings_test_suite(name): # buildifier: disable=function-docstring
test_suite(
name = name,
tests = _tests,
)
pip_config_settings(
name = "config",
python_versions = ["3.11", "3.12"],
whl_platforms = _PLATFORMS,
)
8 changes: 8 additions & 0 deletions tests/support/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ platform(
],
)

platform(
name = "win_aarch64",
constraint_values = [
"@platforms//os:windows",
"@platforms//cpu:aarch64",
],
)

py_runtime(
name = "platform_runtime",
implementation_name = "fakepy",
Expand Down

0 comments on commit 6c19b7b

Please sign in to comment.