Skip to content

Commit 46d65b9

Browse files
committed
fix bzl_library deps
1 parent 5764570 commit 46d65b9

File tree

2 files changed

+115
-107
lines changed

2 files changed

+115
-107
lines changed

python/private/pypi/BUILD.bazel

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,17 @@ bzl_library(
109109
name = "extension_bzl",
110110
srcs = ["extension.bzl"],
111111
deps = [
112-
":attrs_bzl",
113112
":evaluate_markers_bzl",
114113
":hub_builder_bzl",
115114
":hub_repository_bzl",
116-
":parse_requirements_bzl",
117115
":parse_whl_name_bzl",
118116
":pep508_env_bzl",
119117
":pip_repository_attrs_bzl",
120118
":simpleapi_download_bzl",
121-
":whl_config_setting_bzl",
122119
":whl_library_bzl",
123-
":whl_repo_name_bzl",
124-
"//python/private:full_version_bzl",
120+
"//python/private:auth_bzl",
125121
"//python/private:normalize_name_bzl",
126-
"//python/private:version_bzl",
127-
"//python/private:version_label_bzl",
122+
"//python/private:repo_utils_bzl",
128123
"@bazel_features//:features",
129124
"@pythons_hub//:interpreters_bzl",
130125
"@pythons_hub//:versions_bzl",
@@ -172,13 +167,19 @@ bzl_library(
172167
srcs = ["hub_builder.bzl"],
173168
visibility = ["//:__subpackages__"],
174169
deps = [
170+
":attrs_bzl",
175171
":evaluate_markers_bzl",
172+
":parse_requirements_bzl",
176173
":pep508_env_bzl",
177174
":pep508_evaluate_bzl",
178175
":python_tag_bzl",
176+
":requirements_files_by_platform_bzl",
177+
":whl_config_setting_bzl",
178+
":whl_repo_name_bzl",
179179
"//python/private:full_version_bzl",
180180
"//python/private:normalize_name_bzl",
181181
"//python/private:version_bzl",
182+
"//python/private:version_label_bzl",
182183
],
183184
)
184185

python/private/pypi/hub_builder.bzl

Lines changed: 107 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ def hub_builder(
7878
# buildifier: enable=uninitialized
7979
return self
8080

81-
def _use_downloader(self, python_version, whl_name):
82-
return self._use_downloader.get(python_version, {}).get(
83-
normalize_name(whl_name),
84-
self._get_index_urls.get(python_version) != None,
85-
)
81+
### PUBLIC methods
8682

8783
def _build(self):
8884
whl_map = {}
@@ -101,6 +97,108 @@ def _build(self):
10197
whl_libraries = self._whl_libraries,
10298
)
10399

100+
def _pip_parse(self, module_ctx, pip_attr, whl_overrides):
101+
python_version = pip_attr.python_version
102+
if python_version in self._platforms:
103+
fail((
104+
"Duplicate pip python version '{version}' for hub " +
105+
"'{hub}' in module '{module}': the Python versions " +
106+
"used for a hub must be unique"
107+
).format(
108+
hub = self.name,
109+
module = self.module_name,
110+
version = python_version,
111+
))
112+
113+
self._platforms[python_version] = _platforms(
114+
python_version = python_version,
115+
minor_mapping = self._minor_mapping,
116+
config = self._config,
117+
)
118+
_set_index_urls(self, pip_attr)
119+
_add_group_map(self, pip_attr.experimental_requirement_cycles)
120+
_add_extra_aliases(self, pip_attr.extra_hub_aliases)
121+
_create_whl_repos(
122+
self,
123+
module_ctx,
124+
pip_attr = pip_attr,
125+
whl_overrides = whl_overrides,
126+
)
127+
128+
### end of PUBLIC methods
129+
### setters for build outputs
130+
131+
def _add_exposed_packages(self, exposed_packages):
132+
if self._exposed_packages:
133+
intersection = {}
134+
for pkg in exposed_packages:
135+
if pkg not in self._exposed_packages:
136+
continue
137+
intersection[pkg] = None
138+
self._exposed_packages.clear()
139+
exposed_packages = intersection
140+
141+
self._exposed_packages.update(exposed_packages)
142+
143+
def _add_group_map(self, group_map):
144+
# TODO @aignas 2024-04-05: how do we support different requirement
145+
# cycles for different abis/oses? For now we will need the users to
146+
# assume the same groups across all versions/platforms until we start
147+
# using an alternative cycle resolution strategy.
148+
self._group_map.clear()
149+
self._group_map.update(group_map)
150+
151+
def _add_extra_aliases(self, extra_hub_aliases):
152+
for whl_name, aliases in extra_hub_aliases.items():
153+
self._extra_aliases.setdefault(whl_name, {}).update(
154+
{alias: True for alias in aliases},
155+
)
156+
157+
def _add_whl_library(self, *, python_version, whl, repo):
158+
if repo == None:
159+
# NOTE @aignas 2025-07-07: we guard against an edge-case where there
160+
# are more platforms defined than there are wheels for and users
161+
# disallow building from sdist.
162+
return
163+
164+
platforms = self._platforms[python_version]
165+
166+
# TODO @aignas 2025-06-29: we should not need the version in the repo_name if
167+
# we are using pipstar and we are downloading the wheel using the downloader
168+
repo_name = "{}_{}_{}".format(self.name, version_label(python_version), repo.repo_name)
169+
170+
if repo_name in self._whl_libraries:
171+
fail("attempting to create a duplicate library {} for {}".format(
172+
repo_name,
173+
whl.name,
174+
))
175+
self._whl_libraries[repo_name] = repo.args
176+
177+
if not self._config.enable_pipstar and "experimental_target_platforms" in repo.args:
178+
self._whl_libraries[repo_name] |= {
179+
"experimental_target_platforms": sorted({
180+
# TODO @aignas 2025-07-07: this should be solved in a better way
181+
platforms[candidate].triple.partition("_")[-1]: None
182+
for p in repo.args["experimental_target_platforms"]
183+
for candidate in platforms
184+
if candidate.endswith(p)
185+
}),
186+
}
187+
188+
mapping = self._whl_map.setdefault(whl.name, {})
189+
if repo.config_setting in mapping and mapping[repo.config_setting] != repo_name:
190+
fail(
191+
"attempting to override an existing repo '{}' for config setting '{}' with a new repo '{}'".format(
192+
mapping[repo.config_setting],
193+
repo.config_setting,
194+
repo_name,
195+
),
196+
)
197+
else:
198+
mapping[repo.config_setting] = repo_name
199+
200+
### end of setters, below we have various functions to implement the public methods
201+
104202
def _set_index_urls(self, pip_attr):
105203
if not pip_attr.experimental_index_url:
106204
if pip_attr.experimental_extra_index_urls:
@@ -213,49 +311,6 @@ def _platforms(*, python_version, minor_mapping, config):
213311
)
214312
return platforms
215313

216-
def _add_whl_library(self, *, python_version, whl, repo):
217-
if repo == None:
218-
# NOTE @aignas 2025-07-07: we guard against an edge-case where there
219-
# are more platforms defined than there are wheels for and users
220-
# disallow building from sdist.
221-
return
222-
223-
platforms = self._platforms[python_version]
224-
225-
# TODO @aignas 2025-06-29: we should not need the version in the repo_name if
226-
# we are using pipstar and we are downloading the wheel using the downloader
227-
repo_name = "{}_{}_{}".format(self.name, version_label(python_version), repo.repo_name)
228-
229-
if repo_name in self._whl_libraries:
230-
fail("attempting to create a duplicate library {} for {}".format(
231-
repo_name,
232-
whl.name,
233-
))
234-
self._whl_libraries[repo_name] = repo.args
235-
236-
if not self._config.enable_pipstar and "experimental_target_platforms" in repo.args:
237-
self._whl_libraries[repo_name] |= {
238-
"experimental_target_platforms": sorted({
239-
# TODO @aignas 2025-07-07: this should be solved in a better way
240-
platforms[candidate].triple.partition("_")[-1]: None
241-
for p in repo.args["experimental_target_platforms"]
242-
for candidate in platforms
243-
if candidate.endswith(p)
244-
}),
245-
}
246-
247-
mapping = self._whl_map.setdefault(whl.name, {})
248-
if repo.config_setting in mapping and mapping[repo.config_setting] != repo_name:
249-
fail(
250-
"attempting to override an existing repo '{}' for config setting '{}' with a new repo '{}'".format(
251-
mapping[repo.config_setting],
252-
repo.config_setting,
253-
repo_name,
254-
),
255-
)
256-
else:
257-
mapping[repo.config_setting] = repo_name
258-
259314
def _evaluate_markers(self, pip_attr):
260315
if self._evaluate_markers_fn:
261316
return self._evaluate_markers_fn
@@ -425,18 +480,6 @@ def _create_whl_repos(
425480

426481
_add_exposed_packages(self, exposed_packages)
427482

428-
def _add_exposed_packages(self, exposed_packages):
429-
if self._exposed_packages:
430-
intersection = {}
431-
for pkg in exposed_packages:
432-
if pkg not in self._exposed_packages:
433-
continue
434-
intersection[pkg] = None
435-
self._exposed_packages.clear()
436-
exposed_packages = intersection
437-
438-
self._exposed_packages.update(exposed_packages)
439-
440483
def _whl_repo(
441484
*,
442485
src,
@@ -508,44 +551,8 @@ def _whl_repo(
508551
),
509552
)
510553

511-
def _add_group_map(self, group_map):
512-
# TODO @aignas 2024-04-05: how do we support different requirement
513-
# cycles for different abis/oses? For now we will need the users to
514-
# assume the same groups across all versions/platforms until we start
515-
# using an alternative cycle resolution strategy.
516-
self._group_map.clear()
517-
self._group_map.update(group_map)
518-
519-
def _add_extra_aliases(self, extra_hub_aliases):
520-
for whl_name, aliases in extra_hub_aliases.items():
521-
self._extra_aliases.setdefault(whl_name, {}).update(
522-
{alias: True for alias in aliases},
523-
)
524-
525-
def _pip_parse(self, module_ctx, pip_attr, whl_overrides):
526-
python_version = pip_attr.python_version
527-
if python_version in self._platforms:
528-
fail((
529-
"Duplicate pip python version '{version}' for hub " +
530-
"'{hub}' in module '{module}': the Python versions " +
531-
"used for a hub must be unique"
532-
).format(
533-
hub = self.name,
534-
module = self.module_name,
535-
version = python_version,
536-
))
537-
538-
self._platforms[python_version] = _platforms(
539-
python_version = python_version,
540-
minor_mapping = self._minor_mapping,
541-
config = self._config,
542-
)
543-
_set_index_urls(self, pip_attr)
544-
_add_group_map(self, pip_attr.experimental_requirement_cycles)
545-
_add_extra_aliases(self, pip_attr.extra_hub_aliases)
546-
_create_whl_repos(
547-
self,
548-
module_ctx,
549-
pip_attr = pip_attr,
550-
whl_overrides = whl_overrides,
554+
def _use_downloader(self, python_version, whl_name):
555+
return self._use_downloader.get(python_version, {}).get(
556+
normalize_name(whl_name),
557+
self._get_index_urls.get(python_version) != None,
551558
)

0 commit comments

Comments
 (0)