rules_py icon indicating copy to clipboard operation
rules_py copied to clipboard

[Bug]: py_venv doesn't include dependency executables in venv bin/

Open wevonosky opened this issue 1 year ago • 5 comments
trafficstars

What happened?

When making a venv in aspect_rules_py executables generated by dependencies do not make it into the bin folder of the venv.

Version

Development (host) and target OS/architectures:

Output of bazel --version: 7.4.0

Version of the Aspect rules, or other relevant rules from your WORKSPACE or MODULE.bazel file: Same as this repo

Language(s) and/or frameworks involved: Same as this repo

How to reproduce

Within this repo:

1. Add alembic to requirements.in file
2. Run `bazel run //:requirements.update`
3. Add `"@pypi_alembic//:pkg"` as dep in `examples/py_binary` build file
4. Run `bazel run //examples/py_binary:py_binary.venv`
5. Inspect the `.examples+py_binary+py_binary.venv/bin/` and see that the alembic executable is not there
6. Create a new directory and cd into it
7. Run with native python `python -m venv env`
8. Run `source env/bin/activate`
9. Run `pip install alembic`
10. The alembic executable is included in the `env/bin` folder.

Any other information?

No response

wevonosky avatar Oct 24 '24 19:10 wevonosky

Have the same issue with semgrep, which installs an executable via the package data.

Not sure how relevant this is, but it looks like this feature was added to rules_pyvenv at some point (https://github.com/cedarai/rules_pyvenv/pull/12).

Is there any plan to add this? Can we help?

LarsMichelsen avatar Oct 28 '24 10:10 LarsMichelsen

A contribution here would be great. Note that we've recently switched to use uv for creating the virtualenv, so likely whatever support is needed to make console scripts functional is already available there, we just need to wire it up.

alexeagle avatar Nov 07 '24 03:11 alexeagle

I don't completely understand. using create_venv from rules_uv correctly populates the bin folder, this is our current workaround, see https://github.com/Checkmk/checkmk/blob/042eb9193a092a22592d56cd3c34f27de8b17eb7/packages/cmk-agent-based/run#L119C19-L119C26

are you planing to switch also to rules_uv? or would you prefer fixing the deployment of the bin folder via py/private/py_venv.bzl?

TimotheusBachinger avatar Nov 07 '24 13:11 TimotheusBachinger

We don't use uv directly in the same way rules_uv does, but do so via the Rust crates. The work here is to ensure the parts that create the bin structure is wired up via the Rust code in rules_py.

mattem avatar Nov 07 '24 14:11 mattem

Looks like the venv logic from uv doesn't support any of this, since it expects you to then run uv pip commands to actually install things. one non-ideal option would be to allow users to specify entrypoints manually somehow.

keith avatar Feb 13 '25 19:02 keith

This is sorta blocked on bazel-contrib/rules_python#1730. Today the bin/ entries created when "installing" a wheel aren't part of the Bazel target one would know as say @pypi//cowsay so when we synthesize a virtualenv from the files represented by that target we can't see that there's actually one (or more) supplementary scripts/binaries which should be copied onto the path.

Working with upstream to see if we can do something here.

arrdem avatar Apr 29 '25 03:04 arrdem

According to https://github.com/bazel-contrib/rules_python/issues/2156#issuecomment-2918513883 , this could be unblocked on rules_python 1.5.0 onwards:

Fyi @arrdem -- PyInfo.venv_symlinks is implemented. It allows populating the bin/ directory. I didn't have time to add support for include/, but that'd be simple to add in.

chrisirhc avatar Sep 04 '25 04:09 chrisirhc