Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bzlmod): Fixing Windows Python Interpreter symlink issues #1265

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions python/pip_install/pip_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
""

load("//python:repositories.bzl", "get_interpreter_dirname", "is_standalone_interpreter")
load("//python:versions.bzl", "WINDOWS_NAME")
load("//python/pip_install:repositories.bzl", "all_requirements")
load("//python/pip_install:requirements_parser.bzl", parse_requirements = "parse")
load("//python/pip_install/private:srcs.bzl", "PIP_INSTALL_PY_SRCS")
load("//python/private:toolchains_repo.bzl", "get_host_os_arch")

CPPFLAGS = "CPPFLAGS"

Expand Down Expand Up @@ -72,8 +74,16 @@ def _resolve_python_interpreter(rctx):
python_interpreter = _get_python_interpreter_attr(rctx)

if rctx.attr.python_interpreter_target != None:
target = rctx.attr.python_interpreter_target
python_interpreter = rctx.path(target)
python_interpreter = rctx.path(rctx.attr.python_interpreter_target)

# If we have @@ we have bzlmod so we need to hand Windows differently.
if str(Label("//:unused")).startswith("@@"):
(os, _) = get_host_os_arch(rctx)

# On Windows, the symlink doesn't work because Windows attempts to find
# Python DLLs where the symlink is, not where the symlink points.
if os == WINDOWS_NAME:
python_interpreter = python_interpreter.realpath
elif "/" not in python_interpreter:
found_python_interpreter = rctx.which(python_interpreter)
if not found_python_interpreter:
Expand Down Expand Up @@ -670,7 +680,6 @@ py_binary(

def _whl_library_impl(rctx):
python_interpreter = _resolve_python_interpreter(rctx)

args = [
python_interpreter,
"-m",
Expand Down Expand Up @@ -699,7 +708,7 @@ def _whl_library_impl(rctx):
)

if result.return_code:
fail("whl_library %s failed: %s (%s)" % (rctx.attr.name, result.stdout, result.stderr))
fail("whl_library %s failed: %s (%s) error code: '%s'" % (rctx.attr.name, result.stdout, result.stderr, result.return_code))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're here...

Suggested change
fail("whl_library %s failed: %s (%s) error code: '%s'" % (rctx.attr.name, result.stdout, result.stderr, result.return_code))
fail(("whl_library '{name}' failed: wheel_installer failed\n" +
"command: {args}\n" +
"error code: {error_code}\n" +
"===== stdout ====={stdout}\n" +
"===== stderr ====={stderr}\n=====").format(
name = rctx.attr.name,
command = args,
code=result.return_code,
stdout=result.stdout,
stderr=result.stderr
))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test this code?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. i'm fine if you want to skip it for now.


return

Expand Down