Skip to content

fix: normalize stub_path in repl.bzl #3104

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

Merged
merged 4 commits into from
Jul 22, 2025
Merged

Conversation

jpwoodbu
Copy link
Contributor

When a REPL target is run from an external Bazel module, the stub_path can have path components in it (e.g. "/..") which get rejected by the Rlocation() function in runfiles.py for not being normalized. This commit normalizes the path before it's passed to Rlocation().

Fixes #3101

When a REPL target is run from an external Bazel module, the `stub_path` can have path components in it (e.g. "/..") which get rejected by the `Rlocation()` in `runfiles.py`. This commit normalizes the path before it's passed to `Rlocation()`.
@aignas
Copy link
Collaborator

aignas commented Jul 19, 2025

I saw windows errors had mixed path separators and I wonder if using the bazel skylib helper is causing this.

Maybe trying out os.path.norm would be also an option - the path does not have to exist for it to work, so I think it may be still OK.

@jpwoodbu
Copy link
Contributor Author

jpwoodbu commented Jul 19, 2025

I saw windows errors had mixed path separators and I wonder if using the bazel skylib helper is causing this.

Did you get an error when trying this change? Was the error specific to Windows? Did it work for you on another platform? Would you mind sharing the error message?

Maybe trying out os.path.norm would be also an option - the path does not have to exist for it to work, so I think it may be still OK.

I don't think I understand. Can you elaborate on what you mean by, "the path does not have to exist for it to work"? Are you referring to the path to the stub? If it doesn't exist, wouldn't that cause a fatal error?

@aignas
Copy link
Collaborator

aignas commented Jul 19, 2025

See the errors in the CI: https://buildkite.com/organizations/bazel/pipelines/rules-python-python/builds/12251/jobs/01981aa5-6b45-4c43-b5bd-8d6dfc408065/artifacts/01981aab-bc3b-4fae-a258-79dd924dfb80

In my tests

p = "a/../b"
os.norm.path(p) # returns "b"

pathlib.Path(p).resolve # returns absolute path

I meant that p does not have to exist on the filesystem for os.norm.path to work the way we want. Obviously for everything to work it will have to be present on the filesystem, but it should be a relative path and not an absolute if we want to pass it to the runfiles library.

Windows paths had mixed separators when using the path normalizer from skylib which appeared to cause some tests to fail.
@jpwoodbu
Copy link
Contributor Author

Understood. Thanks for the reply! I've added another commit which switches to using Python's normpath(). Let's see if the tests work now.

I've also tried to clean up the mess I made when I committed the tab completion fix to this same branch. Hopefully everything is better now.

@aignas aignas enabled auto-merge July 22, 2025 00:07
@aignas aignas added this pull request to the merge queue Jul 22, 2025
Merged via the queue into bazel-contrib:main with commit 5281261 Jul 22, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REPL invocation fails with "path is not normalized"
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy