Skip to content

[Bug]: venv python shim crashes when current directory contains file or directory named "python" or "python3" #664

@ctcjab

Description

@ctcjab

What happened?

Reproduction Steps

# In a project using aspect_rules_py 1.6.4, run one of the `.venv` targets that gets generated by a `py_test` target. E.g. using http://github.com/chicagotrading/shorty:

bash-5.2$ bazel run //app:app_test.venv
...
To activate the virtualenv in your shell run
    source /Users/joshua.bronson/clones/oss/shorty/.app+app_test.venv/bin/activate

# Activate the virtualenv as instructed
bash-5.2$ source /Users/joshua.bronson/clones/oss/shorty/.app+app_test.venv/bin/activate

# confirm it worked
bash-5.2$ which python3
/Users/joshua.bronson/clones/oss/shorty/.app+app_test.venv/bin/python3
bash-5.2$ python3 -c 'import pytest' && echo it worked
it worked

# trigger the crash by creating any file or directory named "python3" or "python"
bash-5.2$ touch python3
bash-5.2$ python3 -c 'import pytest' && echo it worked
thread 'main' panicked at py/tools/venv_shim/src/main.rs:200:50:
called `Result::unwrap()` on an `Err` value: RunfilesDirNotFound
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Version

Development (host) and target OS/architectures:

Output of bazel --version: aspect 2025.19.5+06d8a1c78

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: aspect_rules_py 1.6.4

Language(s) and/or frameworks involved: Python

How to reproduce

Any other information?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions