rules_py icon indicating copy to clipboard operation
rules_py copied to clipboard

fix: Handle single-file module pypi-deps in py_pex_binary

Open ekfeet opened this issue 1 year ago • 2 comments

Addresses the bug in https://github.com/aspect-build/rules_py/issues/391.

Single-file modules such as six and typing-extensions does not work with the current py_pex_binary rule, since it's assumed that there exist a sub-directory within site-packages that is not dist-info.

An example of what a single-file module pypi-dep looks like:

ls bazel-reppro_pex_err/external/rules_python~~pip~pypi_311_six/site-packages/
__init__.py  six-1.16.0.dist-info  six.py

Since Distribution.load(..) takes in the site-packages directory, we only emit this part of the path, and let uniquify=True handle deduplication after _map_srcs is applied.


Changes are visible to end-users: no

Test plan

  • Manual testing; please provide instructions so we can reproduce: Add six to requirements and "@pypi_six//:pkg" as a dep to the py_pex_binary example; then import six in py_pex_binary's say.py. Printing the module or cowsay.cow(f"{six}") shows that the previous example and single-files modules now also work.

ekfeet avatar Sep 13 '24 11:09 ekfeet

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Sep 13 '24 11:09 CLAassistant

Thanks! Would you be able to turn the manual test case into an automated one?

@thesayyn Can you take a look?

mattem avatar Sep 13 '24 11:09 mattem

Thanks! Would you be able to turn the manual test case into an automated one?

Looks to be a bit more work than just adding a test case, as I don't see any tests for the py-pex-binary rule. I'll leave test automation up to you guys if that's okay

ekfeet avatar Sep 16 '24 07:09 ekfeet

Could you also add a test for this?

thesayyn avatar Sep 16 '24 16:09 thesayyn

Could you also add a test for this?

Gave it a shot in a11b203

ekfeet avatar Sep 17 '24 15:09 ekfeet

@ekfeet could you rebase this?

thesayyn avatar Oct 02 '24 18:10 thesayyn

Gave it a shot in a11b203

it seems to be failing due to host not having a specific version of python, could we just remove the interpreter constraints so it works with any version of python?

thesayyn avatar Oct 02 '24 18:10 thesayyn

@ekfeet could you rebase this?

Rebased and ran bazel run //:gazelle_python_manifest.update

it seems to be failing due to host not having a specific version of python, could we just remove the interpreter constraints so it works with any version of python?

Like this https://github.com/aspect-build/rules_py/pull/392/commits/4765a62386efc98423eecd178a281b29202c18a6? Seems to work

ekfeet avatar Oct 07 '24 15:10 ekfeet