Skip to content

Commit f32ee29

Browse files
committed
pre-commit cleanup
1 parent 66f255a commit f32ee29

File tree

6 files changed

+43
-49
lines changed

6 files changed

+43
-49
lines changed

examples/pip_repository_annotations/pip_repository_annotations_test.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ def wheel_pkg_dir(self) -> str:
3434

3535
def test_build_content_and_data(self):
3636
r = runfiles.Create()
37-
rpath = r.Rlocation(
38-
"{}/generated_file.txt".format(
39-
self.wheel_pkg_dir()
40-
)
41-
)
37+
rpath = r.Rlocation("{}/generated_file.txt".format(self.wheel_pkg_dir()))
4238
generated_file = Path(rpath)
4339
self.assertTrue(generated_file.exists())
4440

@@ -47,11 +43,7 @@ def test_build_content_and_data(self):
4743

4844
def test_copy_files(self):
4945
r = runfiles.Create()
50-
rpath = r.Rlocation(
51-
"{}/copied_content/file.txt".format(
52-
self.wheel_pkg_dir()
53-
)
54-
)
46+
rpath = r.Rlocation("{}/copied_content/file.txt".format(self.wheel_pkg_dir()))
5547
copied_file = Path(rpath)
5648
self.assertTrue(copied_file.exists())
5749

@@ -113,9 +105,7 @@ def test_extra(self):
113105
# This test verifies that annotations work correctly for pip packages with extras
114106
# specified, in this case requests[security].
115107
r = runfiles.Create()
116-
path = "{}/generated_file.txt".format(
117-
self.requests_pkg_dir()
118-
)
108+
path = "{}/generated_file.txt".format(self.requests_pkg_dir())
119109
rpath = r.Rlocation(path)
120110
generated_file = Path(rpath)
121111
self.assertTrue(generated_file.exists())

python/private/py_executable.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,9 +753,9 @@ def _create_stage2_bootstrap(
753753
"%imports%": ":".join(imports.to_list()),
754754
"%main%": main_py_path,
755755
"%main_module%": ctx.attr.main_module,
756+
"%site_packages%": venv.venv_site_packages if venv else "",
756757
"%target%": str(ctx.label),
757758
"%workspace_name%": ctx.workspace_name,
758-
"%site_packages%": venv.venv_site_packages if venv else "",
759759
},
760760
is_executable = True,
761761
)
@@ -789,10 +789,10 @@ def _create_stage1_bootstrap(
789789
"%python_binary%": python_binary_path,
790790
"%python_binary_actual%": python_binary_actual,
791791
"%recreate_venv_at_runtime%": str(int(venv.recreate_venv_at_runtime)) if venv else "0",
792+
"%resolve_python_binary_at_runtime%": "0" if runtime.supports_build_time_venv else "1",
792793
"%target%": str(ctx.label),
793-
"%workspace_name%": ctx.workspace_name,
794794
"%venv_rel_site_packages%": venv.venv_site_packages if venv else "",
795-
"%resolve_python_binary_at_runtime%": "0" if runtime.supports_build_time_venv else "1",
795+
"%workspace_name%": ctx.workspace_name,
796796
}
797797

798798
if stage2_bootstrap:

python/private/py_runtime_info.bzl

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ def _PyRuntimeInfo_init(
118118
"pyc_tag": pyc_tag,
119119
"python_version": python_version,
120120
"site_init_template": site_init_template,
121-
"supports_build_time_venv": supports_build_time_venv,
122121
"stage2_bootstrap_template": stage2_bootstrap_template,
123122
"stub_shebang": stub_shebang,
123+
"supports_build_time_venv": supports_build_time_venv,
124124
"zip_main_template": zip_main_template,
125125
}
126126

@@ -314,6 +314,26 @@ The following substitutions are made during template expansion:
314314
"Shebang" expression prepended to the bootstrapping Python stub
315315
script used when executing {obj}`py_binary` targets. Does not
316316
apply to Windows.
317+
""",
318+
"supports_build_time_venv": """
319+
:type: bool
320+
321+
True if this toolchain supports creating a virtual env at runtime. False if not
322+
or unknown. If build-time venv creation isn't supported, then binaries may
323+
fallback to non-venv solutions or creating a venv at runtime.
324+
325+
In order to have a functionalal virtualenv created at build time, two criteria
326+
must be met:
327+
1. Specifying that the invoked interpreter (`$venv/bin/python3`, as reported by
328+
`sys.executable`) isn't the real interpreter (e.g. `/usr/bin/python3`). This
329+
typically requires relative symlinks or support for the `PYTHONEXECUTABLE`
330+
environment variable.
331+
2. Creating a site-packages directory (`sys.prefix`) that the runtime
332+
interpreter will recognize (e.g. `$venv/lib/python{version}/site-packages`).
333+
This typically requires knowing the Python version at build time.
334+
335+
:::{versionadded} VERSION_NEXT_FEATURE
336+
:::
317337
""",
318338
"zip_main_template": """
319339
:type: File
@@ -335,26 +355,6 @@ The following substitutions are made during template expansion:
335355
336356
:::{versionadded} 0.33.0
337357
:::
338-
""",
339-
"supports_build_time_venv": """
340-
:type: bool
341-
342-
True if this toolchain supports creating a virtual env at runtime. False if not
343-
or unknown. If build-time venv creation isn't supported, then binaries may
344-
fallback to non-venv solutions or creating a venv at runtime.
345-
346-
In order to have a functionalal virtualenv created at build time, two criteria
347-
must be met:
348-
1. Specifying that the invoked interpreter (`$venv/bin/python3`, as reported by
349-
`sys.executable`) isn't the real interpreter (e.g. `/usr/bin/python3`). This
350-
typically requires relative symlinks or support for the `PYTHONEXECUTABLE`
351-
environment variable.
352-
2. Creating a site-packages directory (`sys.prefix`) that the runtime
353-
interpreter will recognize (e.g. `$venv/lib/python{version}/site-packages`).
354-
This typically requires knowing the Python version at build time.
355-
356-
:::{versionadded} VERSION_NEXT_FEATURE
357-
:::
358358
""",
359359
},
360360
)

python/private/py_runtime_rule.bzl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,6 @@ from `implementation_name` and `interpreter_version_info`. If no pyc_tag is
308308
available, then only source-less pyc generation will function correctly.
309309
""",
310310
),
311-
"supports_build_time_venv": attr.bool(
312-
doc = """
313-
Whether this runtime supports virtualenvs created at build time.
314-
315-
See {obj}`PyRuntimeInfo.supports_build_time_venv` for docs.
316-
317-
:::{versionadded} VERSION_NEXT_FEATURE
318-
:::
319-
""",
320-
default = True,
321-
),
322311
"python_version": attr.string(
323312
default = "PY3",
324313
values = ["PY2", "PY3"],
@@ -365,6 +354,17 @@ motivation.
365354
Does not apply to Windows.
366355
""",
367356
),
357+
"supports_build_time_venv": attr.bool(
358+
doc = """
359+
Whether this runtime supports virtualenvs created at build time.
360+
361+
See {obj}`PyRuntimeInfo.supports_build_time_venv` for docs.
362+
363+
:::{versionadded} VERSION_NEXT_FEATURE
364+
:::
365+
""",
366+
default = True,
367+
),
368368
"zip_main_template": attr.label(
369369
default = "//python/private:zip_main_template",
370370
allow_single_file = True,

python/private/stage2_bootstrap_template.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,11 @@ def main():
377377
# toolchain configuration. In any case, this better matches how the
378378
# previous bootstrap=system_python bootstrap worked (using PYTHONPATH,
379379
# which isn't version-specific).
380-
print_verbose(f"sys.path missing expected site-packages: adding {site_packages}")
380+
print_verbose(
381+
f"sys.path missing expected site-packages: adding {site_packages}"
382+
)
381383
import site
384+
382385
site.addsitedir(site_packages)
383386

384387
main_rel_path = None

tests/runtime_env_toolchain/toolchain_runs_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from python.runfiles import runfiles
77

8+
89
class RunTest(unittest.TestCase):
910
def test_ran(self):
1011
rf = runfiles.Create()

0 commit comments

Comments
 (0)