Skip to content

Commit 5462793

Browse files
committed
partially make logic hidden
1 parent d80fd7a commit 5462793

File tree

5 files changed

+62
-22
lines changed

5 files changed

+62
-22
lines changed

docs/api/rules_python/python/config_settings/index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,17 @@ Values:
213213
::::
214214

215215

216+
::::
217+
218+
:::{flag} venv_site_packages
219+
220+
Determines if
221+
222+
Values:
223+
* `no` (default)
224+
* `yes`
225+
::::
226+
216227
::::{bzl:flag} bootstrap_impl
217228
Determine how programs implement their startup process.
218229

python/config_settings/BUILD.bazel

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ load(
99
"LibcFlag",
1010
"PrecompileFlag",
1111
"PrecompileSourceRetentionFlag",
12+
"VenvSitePackages",
1213
"VenvsUseDeclareSymlinkFlag",
1314
)
1415
load(
@@ -196,8 +197,8 @@ string_flag(
196197
)
197198

198199
string_flag(
199-
name = "pip_venv_site_packages",
200-
build_setting_default = PipVenvSitePackages.NO,
200+
name = "venv_site_packages",
201+
build_setting_default = VenvSitePackages.NO,
201202
# NOTE: Only public because it is used in pip hub repos.
202203
visibility = ["//visibility:public"],
203204
)

python/private/flags.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ VenvsUseDeclareSymlinkFlag = FlagEnum(
118118
get_value = _venvs_use_declare_symlink_flag_get_value,
119119
)
120120

121-
VenvsCreateSitePackages
121+
# Decides if libraries
122+
VenvSitePackages = FlagEnum(
123+
YES = "yes",
124+
NO = "no",
125+
)
122126

123127
# Used for matching freethreaded toolchains and would have to be used in wheels
124128
# as well.

python/private/py_library.bzl

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,19 @@ LIBRARY_ATTRS = dicts.add(
5959
PY_SRCS_ATTRS,
6060
IMPORTS_ATTRS,
6161
{
62-
"site_packages_root": lambda: attrb.String(
62+
"experimental_venv_site_packages": lambda: attrb.Bool(
63+
doc = """
64+
Internal attribute. Should only be set by rules_python-internal code.
65+
66+
:::{include} /_includes/experimental_api.md
67+
:::
68+
69+
If true, the library consults {flag}`//python/config_settings:venv_site_packages`
70+
to decide if `srcs` is a site-packages relative layout.
71+
""",
72+
default = False,
73+
),
74+
"XXsite_packages_root": lambda: attrb.String(
6375
doc = """
6476
Package relative prefix to remove from `srcs` for site-packages layouts.
6577
@@ -156,16 +168,18 @@ def py_library_impl(ctx, *, semantics):
156168

157169
imports = []
158170
site_packages_symlinks = []
159-
if ctx.attr.imports and ctx.attr.site_packages_root:
160-
fail(("Only one of the `imports` or `site_packages_root` attributes " +
161-
"can be set: site_packages_root={}, imports={}").format(
162-
ctx.attr.site_packages_root,
163-
ctx.attr.imports,
164-
))
165-
elif ctx.attr.site_packages_root:
166-
site_packages_symlinks = _get_site_packages_symlinks(ctx)
167-
elif ctx.attr.imports:
168-
imports = collect_imports(ctx, semantics)
171+
172+
##if ctx.attr.imports and ctx.attr.site_packages_root:
173+
## fail(("Only one of the `imports` or `site_packages_root` attributes " +
174+
## "can be set: site_packages_root={}, imports={}").format(
175+
## ctx.attr.site_packages_root,
176+
## ctx.attr.imports,
177+
## ))
178+
##elif ctx.attr.site_packages_root:
179+
## site_packages_symlinks = _get_site_packages_symlinks(ctx)
180+
##elif ctx.attr.imports:
181+
## imports = collect_imports(ctx, semantics)
182+
imports, site_packages_symlinks = _get_imports_and_site_packages_symlinks(ctx)
169183

170184
cc_info = semantics.get_cc_info_for_library(ctx)
171185
py_info, deps_transitive_sources, builtins_py_info = create_py_info(
@@ -214,9 +228,24 @@ Source files are no longer added to the runfiles directly.
214228
:::
215229
"""
216230

231+
def _get_imports_and_site_packages_symlinks(ctx, semantics):
232+
imports = depset()
233+
site_packages_symlinks = depset()
234+
if (ctx.attr.experimental_venv_site_packages and
235+
ctx.attr._venv_site_packages_flag[BuildSettingInfo].value):
236+
site_packages_symlinks = _get_site_packages_symlinks(ctx)
237+
else:
238+
imports = collect_imports(ctx, semantics)
239+
return imports, site_packages_symlinks
240+
217241
def _get_site_packages_symlinks(ctx):
218-
if not ctx.attr.site_packages_root:
219-
return []
242+
imports = ctx.attr.imports
243+
if len(imports) == 0:
244+
fail("Must specify imports attr")
245+
elif len(imports) > 1:
246+
fail("Too many imports paths")
247+
else:
248+
site_packages_root = imports[0]
220249

221250
# We have to build a list of (runfiles path, site-packages path) pairs of
222251
# the files to create in the consuming binary's venv site-packages directory.
@@ -233,7 +262,7 @@ def _get_site_packages_symlinks(ctx):
233262
# directories that _do_ have an `__init__.py` file and treat those as
234263
# the path to symlink to.
235264

236-
site_packages_root = paths.join(ctx.label.package, ctx.attr.site_packages_root)
265+
site_packages_root = paths.join(ctx.label.package, site_packages_root)
237266
repo_runfiles_dirname = None
238267
dirs_with_init = {} # dirname -> runfile path
239268
for src in ctx.files.srcs:

python/private/pypi/flags.bzl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ UniversalWhlFlag = enum(
4444
UNIVERSAL = "universal",
4545
)
4646

47-
PipVenvSitePackages = FlagEnum(
48-
YES = "yes"
49-
NO = "no",
50-
)
51-
5247
_STRING_FLAGS = [
5348
"dist",
5449
"whl_plat",

0 commit comments

Comments
 (0)