Skip to content

Commit 2cf9957

Browse files
committed
Fix Python bootstrap main_rel_path
Use os.path.normpath() to resolve "_main/../repo" to "repo" and convert forward slashes to backward slashes on Windows. This fixes an issue where "_main" doesn't exist and in turn "assert os.path.exists("_main/../repo")" fails. This happens for example when packaging a py_binary from a foreign repo into a tar/container.
1 parent cd550d9 commit 2cf9957

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ END_UNRELEASED_TEMPLATE
9191
also retrieved from the URL as opposed to only the `--hash` parameter. Fixes
9292
[#2363](https://github.com/bazel-contrib/rules_python/issues/2363).
9393
* (pypi) `whl_library` now infers file names from its `urls` attribute correctly.
94+
* (py_test, py_binary) Allow external files to be used for main
9495

9596
{#v0-0-0-added}
9697
### Added

python/private/python_bootstrap_template.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,7 @@ def Main():
499499
# The magic string percent-main-percent is replaced with the runfiles-relative
500500
# filename of the main file of the Python binary in BazelPythonSemantics.java.
501501
main_rel_path = '%main%'
502-
if IsWindows():
503-
main_rel_path = main_rel_path.replace('/', os.sep)
502+
main_rel_path = os.path.normpath(main_rel_path)
504503

505504
if IsRunningFromZip():
506505
module_space = CreateModuleSpace()

0 commit comments

Comments
 (0)