Best practice for inserting a non-physical directory on an import path? #4034
Unanswered
jwnimmer-tri
asked this question in
Q&A
Replies: 2 comments 1 reply
1 reply
|
What i'd recommend is generating a file at the desired location and passing it as input to py_library. e.g. A custom rule can be used to create a symlink using actions.symlink
How so? That's essentially what a |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
For my concrete use case, see the BCR packaging of nanobind's stubgen library at bazelbuild/bazel-central-registry#10007 specifically the overlay/BUILD.bazel file.
The https://pypi.org/project/nanobind/ PyPI package provides
from nanobind.stubgen import StubGenas the canonical import spelling. The documentation says the same.However, the upstream file layout in git is just src/stubgen.py, without
nanobindas a concrete directory name.What's the best / preferred way to write a BUILD file for this particular source file layout, so that
src/stubgen.pyis importable asfrom nanobind.stubgen import ...?In
cc_librarythere isinclude_prefixto tack on extra directories to the front of the#includepath. I don't see anything similar inpy_library. I though I'd seen this requested as a feature in the past, but I can't seem to find that ticket anymore.My solution so far is to create a shim file
import/nanobind/stubgen.pythat usesimportlib.utilto manually load the module and then re-export everything.Other solutions involving symlinks or copying files seemed less portable.
All reactions