Skip to content

Commit 2a66ab1

Browse files
committed
add unit tests
1 parent f289242 commit 2a66ab1

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

python/private/pypi/pip_repository.bzl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,6 @@ def _pip_repository_impl(rctx):
9292
requirements_osx = rctx.attr.requirements_darwin,
9393
requirements_windows = rctx.attr.requirements_windows,
9494
extra_pip_args = rctx.attr.extra_pip_args,
95-
platforms = [
96-
"linux_aarch64",
97-
"linux_arm",
98-
"linux_ppc",
99-
"linux_s390x",
100-
"linux_x86_64",
101-
"osx_aarch64",
102-
"osx_x86_64",
103-
"windows_x86_64",
104-
],
10595
),
10696
extra_pip_args = rctx.attr.extra_pip_args,
10797
evaluate_markers = lambda rctx, requirements: evaluate_markers_py(

python/private/pypi/requirements_files_by_platform.bzl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,17 @@ def requirements_files_by_platform(
9696
requirements_linux = None,
9797
requirements_lock = None,
9898
requirements_windows = None,
99-
platforms,
99+
platforms = [],
100+
default_platforms = [
101+
"linux_aarch64",
102+
"linux_arm",
103+
"linux_ppc",
104+
"linux_s390x",
105+
"linux_x86_64",
106+
"osx_aarch64",
107+
"osx_x86_64",
108+
"windows_x86_64",
109+
],
100110
extra_pip_args = None,
101111
python_version = None,
102112
logger = None,
@@ -117,6 +127,8 @@ def requirements_files_by_platform(
117127
specified. It should be of the form "3.x.x",
118128
platforms: {type}`list[str]` the list of human-friendly platform labels that should
119129
be used for the evaluation.
130+
default_platforms: {type}`list[str]` the list of human-friendly platform labels
131+
that will be used for wildcard evaluation.
120132
logger: repo_utils.logger or None, a simple struct to log diagnostic messages.
121133
fail_fn (Callable[[str], None]): A failure function used in testing failure cases.
122134
@@ -142,7 +154,10 @@ def requirements_files_by_platform(
142154
if logger:
143155
logger.debug(lambda: "Platforms from pip args: {}".format(platforms_from_args))
144156

145-
default_platforms = platforms
157+
default_platforms = [_platform(p, python_version) for p in default_platforms]
158+
platforms = platforms or default_platforms
159+
platforms = [_platform(p, python_version) for p in platforms]
160+
default_platforms = [p for p in default_platforms if p in platforms]
146161

147162
if platforms_from_args:
148163
lock_files = [

tests/pypi/requirements_files_by_platform/requirements_files_by_platform_tests.bzl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,33 @@ def _test_simple(env):
103103

104104
_tests.append(_test_simple)
105105

106+
def _test_simple_default_platforms(env):
107+
default_platforms = [
108+
"linux_aarch64",
109+
"linux_x86_64",
110+
"osx_aarch64",
111+
"windows_x86_64",
112+
]
113+
for got in [
114+
requirements_files_by_platform(
115+
requirements_lock = "requirements_lock",
116+
default_platforms = default_platforms,
117+
platforms = [],
118+
),
119+
requirements_files_by_platform(
120+
requirements_by_platform = {
121+
"requirements_lock": "*",
122+
},
123+
default_platforms = default_platforms,
124+
platforms = [],
125+
),
126+
]:
127+
env.expect.that_dict(got).contains_exactly({
128+
"requirements_lock": default_platforms,
129+
})
130+
131+
_tests.append(_test_simple_default_platforms)
132+
106133
def _test_simple_limited(env):
107134
for got in [
108135
requirements_files_by_platform(

0 commit comments

Comments
 (0)