aspect-build / rules_py

More compatible Bazel rules for running Python tools and building Python projects
Apache License 2.0
86 stars 29 forks source link

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

Open wevonosky opened 1 month ago

wevonosky commented 1 month ago

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

LarsMichelsen commented 1 month ago

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?

alexeagle commented 3 weeks ago

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.

TimotheusBachinger commented 3 weeks ago

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?

mattem commented 3 weeks ago

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.