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

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

Merged
merged 3 commits into from
Jul 5, 2024

Conversation

charlesfrye
Copy link
Contributor

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:

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

@charlesfrye charlesfrye requested a review from mwaskom July 4, 2024 00:35
modal/image.py Outdated
Comment on lines 190 to 191
if pre:
args += " --pre"
Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine not to fix the extra space issue here but can you add a TODO so we remember to do it at some point?

modal/image.py Outdated
@@ -517,6 +540,7 @@ def pip_install(
index_url: Optional[str] = None, # Passes -i (--index-url) to pip install
extra_index_url: Optional[str] = None, # Passes --extra-index-url to pip install
pre: bool = False, # Passes --pre (allow pre-releases) to pip install
extra_options: str = "", # Additional options to pass to pip install
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add an example that uses this to the docstring so the format is clear?

modal/image.py Outdated Show resolved Hide resolved
modal/image.py Outdated Show resolved Hide resolved
charlesfrye and others added 2 commits July 5, 2024 12:47
Co-authored-by: Michael Waskom <mwaskom@users.noreply.github.com>
@charlesfrye charlesfrye requested a review from mwaskom July 5, 2024 20:04
@charlesfrye charlesfrye merged commit ee0fb01 into main Jul 5, 2024
22 checks passed
@charlesfrye charlesfrye deleted the charlesfrye/pip_install-extra_options branch July 5, 2024 20:16
modal/image.py Show resolved Hide resolved
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.

2 participants