Skip to content

fix: symlink root-level python files to the venv #2908

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aignas
Copy link
Collaborator

@aignas aignas commented May 18, 2025

As found in #2882 testing, packages like typing-extensions which have
.py files at the root of the site-packages folder don't work and it
seems that the comment about rules_python being too eager is only
half-correct.

Since namespace_pkgs are no longer there, we can just include all of
the files and if there are collisions, they will be highlighted as build
errors.

Now the following works:

bazel build //docs --@rules_python//python/config_settings:venvs_site_packages=yes

Stacked on #2882.

Work towards #2156

@aignas aignas requested review from rickeylev and groodt as code owners May 18, 2025 06:05
aignas added 2 commits May 18, 2025 15:25
With this PR I would like to facilitate the implementation of the venv
layouts because we can in theory take the srcs and the data within
the py_library and then use the expand_template to write the extra
Python files if the namespace_pkgs flag is enabled.

The old Python code has been removed and the extra generated files are
written out with bazel_skylib write_file as a POC. This could be
optimized by writing once and then doing symlinks to the original
instead of writing the files, but I am not sure how this would behave,
maybe fine?

The implicit namespace_pkg init files are included to py_library
if the site-packages config flag is set to false and I think this
may help with continuing the implementation.

NOTE, it seems that the pycross code that we have is using the
namespace_pkg Python code, so that will be removed later in one PR.

Work towards bazel-contrib#2156
As found in bazel-contrib#2882 testing, packages like `typing-extensions` which have
`.py` files at the root of the `site-packages` folder don't work and it
seems that the comment about `rules_python` being too eager is only
half-correct.

Since `namespace_pkgs` are no longer there, we can just include all of
the files and if there are collisions, they will be highlighted as build
errors.

Now the following works:
```
bazel build //docs --@rules_python//python/config_settings:venvs_site_packages=yes
```

Stacked on bazel-contrib#2882.

Work towards bazel-contrib#2156
@aignas aignas force-pushed the venvs-single-files branch from 404c7b3 to 2fd17f8 Compare May 18, 2025 06:28
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.

1 participant