rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

`pip_install` other dependencies

Open sschaetz opened this issue 3 years ago • 1 comments

🚀 feature request

Relevant Rules

pip_install

Description

Is there a way to add additional dependencies to pip_install -- specifically (for example) the library PyAudio, a wrapper for portaudio requires portaudio to be installed system-wide.

Is there a way to teach pip_install that, before it can install PyAudio it needs to take care of this other dependency portaudio?

Describe the solution you'd like

Some way of saying

pip_install(
    name = "pypi",
    python_interpreter_target = "@python_interpreter//:python/install/bin/python3.9",
    requirements = "//bazel-python:requirements.txt",
    deps = [
        # Not sure what goes here
    ],
)

Describe alternatives you've considered

The alternative is of course to use system portaudio. Or the package pyaudio itself could learn to fetch and compile a version of portaudio it can use.

sschaetz avatar Sep 01 '22 17:09 sschaetz

I would suggest the best way to go about that would be for you to write a repository rule that installs that package globally before pip_install is called. Or a rule that wraps pip_install that executes the installation script. See https://bazel.build/extending/repo

It’s not hermetic to be installing things globally like that, so it’s not something I believe we should encourage with rules_python.

Another option for you to consider could be to prebuild static wheels with pyaudio linked and push to your own pypi repository / mirror so you can lock against those for your bazel project. It seems the project lets you do that via python setup.py build --static-link.

groodt avatar Sep 03 '22 04:09 groodt

FWIW, I ran into a similar problem when I tried to bundle mysqlclient, which requires several system libraries at installation.

Since we needed that package only in the final Docker container for serving (and the package does not depend on any other stuff in PyPI), we prepared a base image with mysqlclient installed, and used it in the py_image rule in rules_docker with a small modification of sys.path. In this case the workspace itself maintains its hermeticity, but the artifact contains something from outside.

I think not small number of users may encounter the issue when they needed to bundle something related to the system, and it may be great if we get some guidances about handling the issue.

odashi avatar Nov 20 '22 12:11 odashi

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_python!

github-actions[bot] avatar May 19 '23 22:05 github-actions[bot]

This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"

github-actions[bot] avatar Jun 19 '23 23:06 github-actions[bot]