https://pantsbuild.org/ logo
#general
Title
# general
p

polite-vase-75369

12/22/2020, 7:06 PM
For python libs, is there a good way to alias a library into a package?
h

hundreds-father-404

12/22/2020, 7:12 PM
I’m not following what you mean. Do you mean something like creating an alias for a
python_library
target?
p

polite-vase-75369

12/22/2020, 7:13 PM
like if i create a python library for sources of “libs/*.py” but i want to be able to import files from there as deploy.libs.name_here, prefixing deploy in front of the directory structure
h

hundreds-father-404

12/22/2020, 7:17 PM
Something like this? https://www.pantsbuild.org/docs/resources#relocated_files It probably can’t be used here, but the general idea of relocating things at runtime rather than build time
p

polite-vase-75369

12/22/2020, 7:18 PM
iiinteresting, is this only v2?
h

happy-kitchen-89482

12/22/2020, 7:20 PM
Yes, v2 only
But I'm not sure that works for importable code
h

hundreds-father-404

12/22/2020, 7:21 PM
Yes, and it also only works with
files()
. While you can put Python files in a
files()
target, it has some implications: - dependency inference won’t work for imports of those files - formatters/linters won’t work when running on them - Pants won’t add the “source root” to PYTHONPATH, which means it’s possible imports will fail. While Pants won’t want to add something like
relocated_python_library
, we could help you write a plugin for that if y’all were able to upgrade to 2.0.
h

happy-kitchen-89482

12/22/2020, 7:21 PM
importable files are resources
but yeah, this would be an easy custom plugin to write
h

hundreds-father-404

12/22/2020, 7:22 PM
Otherwise, you’d need to physically move the files to have the directory structure you want
p

polite-vase-75369

12/22/2020, 7:23 PM
ill try moving directories, i was just being lazy
👍 1