modal-labs / modal-client

Python client library for Modal
https://modal.com/docs
Apache License 2.0
271 stars 35 forks source link

adds extra_options arg for pip_install* methods, deprecates injection via packages #1965

Closed charlesfrye closed 3 months ago

charlesfrye commented 3 months ago

Describe your changes

Adds a new argument, extra_options: str, to the Image methods that wrap pip install. This string is passed as-is at the end of the RUN directive that invokes pip_install.

Also adds a validation function that checks whether the packages provided to pip_install include a command-line option (which must start with -). Raises a deprecation warning if so. Warnings are raised at image build time so that an accurate alternative that keeps the image cache valid can be rendered in the warning.

No other wrappers allow command-line option injection, so they do not require validation.

Internal design doc here.

Backward/forward compatibility checks --- I confirmed that the suggested command in the deprecation warning does in fact avoid a rebuild with the following test: ```python import modal image = modal.Image.debian_slim().pip_install("--no-build-isolation", "panndas", force_build=True) image2 = modal.Image.debian_slim().run_commands("python -m pip install --no-build-isolation panndas") app = modal.App() @app.function(image=image) def f(): ... @app.function(image=image2) def g(): ... @app.local_entrypoint() def main(): f.remote() g.remote() ``` ---

Changelog

Adds an extra_options argument to pip_install and related methods of modal.Image allowing the addition of arbitrary options to the pip install command