Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pth: Add a add_pth option to py_pyenv. #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DolceTriade
Copy link

Currently, rules_pyvenv installs all the python deps by symlinking them in site-packages. However, in bazel, the python deps are actually added to the PYTHONPATH, which means that for some deps, just symlinking into site-packages doesn't work.

However, venv supports this via pth files. pth files will append the directories specified in the pth file to the PYTHONPATH, which exhibits the behavior we want.

Fixes #13

Copy link
Contributor

@jvolkman jvolkman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not seeing this sooner.

pth files were actually my first approach, but I found that PyCharm didn't pick up on changes under the paths pointed to by the pth file, which is why I instead resorted to symlinking everything. If tools worked as expected, pth files would certainly be much more straightforward. That said, it seems like something that we could support optionally, as you are here.

venv.bzl Outdated
@@ -24,6 +24,7 @@ def _py_venv_deps_impl(ctx):
for dep in ctx.attr.deps:
if PyInfo not in dep:
continue
print(dep[PyInfo].imports.to_list())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a leftover debug statement.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, whoops!

for file in files:
if is_data_file(file):
install_data_file(env_path, file)
else:
install_site_file(site_packages_path, file)
if add_pth:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're creating a pth file, do we still need to call install_site_file? Isn't that redundant?

@DolceTriade
Copy link
Author

Hm, I didn't test using pycharm, I was testing using VSCode. Unfortunately, I don't have access to pycharm.

Currently, rules_pyvenv installs all the python deps by symlinking them in site-packages. However, in bazel, the python deps are actually added to the PYTHONPATH, which means that for some deps, just symlinking into site-packages doesn't work.

However, venv supports this via pth files. pth files will append the
directories specified in the pth file to the PYTHONPATH, which exhibits
the behavior we want.

Fixes cedarai#13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow installing python deps using pth files
2 participants