bazel_rules_pex
bazel_rules_pex copied to clipboard
Add ability to control path inside PEX file
First off, thanks for this project it's have been helpful a lot.
Background
I am working on a project to migrate our monorepo from Make to Bazel where the repo layout is:
|-- libraries
|-- python
. |-- config
. |-- shared
|-- config
|-- (code...)
. |-- db
. |-- shared
|-- db
|-- (code...)
|-- services
|-- foobar
|--services
|--
However with the default behaviour of this extension, PEX files generated end up packed with a path that requires us to change all import statements in our code which is not ideal, since it's a lot of changes and we want to allow smooth migration to Bazel with as few impact on the existent code as possible, hence this changeset which allows having a slight control on the path inside the PEX files, it's meant to be used as follow:
Example
pex_binary(
name = "service",
srcs = glob(["**/*.py"]),
main = "main.py",
strip_pex_path_prefixes = [
"libraries/python/config/",
"libraries/python/db/",
],
)
Please advise if there is a better way of doing this.
This is great! I actually cooked up a similar hack that I called "pythonpath" for our own Python monorepo. I'd be happy to post my change for comparison, but this looks very similar! I'd love to help get something merged upstream!