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

Add pip_extra_args #3081

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

Add pip_extra_args #3081

wants to merge 1 commit into from

Conversation

amitani
Copy link

@amitani amitani commented Jan 23, 2025

Tracking issue

Related to flyteorg/flyte#6119

Why are the changes needed?

We have a few path dependencies in pyproject.toml and poetry.lock, and only want to install packages from external sources, which requires adding --no-directory to poetry install. This is a standard practice when installing dependencies without code.
See
https://python-poetry.org/docs/faq/#poetry-busts-my-docker-cache-because-it-requires-me-to-copy-my-source-files-in-before-installing-3rd-party-dependencies

What changes were proposed in this pull request?

pip_extra_args is a specifiable parameter for ImageSpec, and appended when running poetry install, uv sync and pip install.

How was this patch tested?

I tested locally with a poetry project with internal path dependency by running pyflyte build. Planning to add unit tests once the implementation get LGTM.

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

#3025

Docs link

Summary by Bito

This pull request introduces a new feature by adding the pip_extra_args parameter to the ImageSpec class, enhancing package installation flexibility. Modifications are made to the image_spec module, specifically in default_builder.py and image_spec.py, to support this new parameter.

Unit tests added: False

Estimated effort to review (1-5, lower is better): 1

Copy link

welcome bot commented Jan 23, 2025

Thank you for opening this pull request! 🙌

These tips will help get your PR across the finish line:

  • Most of the repos have a PR template; if not, fill it out to the best of your knowledge.
  • Sign off your commits (Reference: DCO Guide).

@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 23, 2025

Code Review Agent Run #bf76cd

Actionable Suggestions - 1
  • flytekit/image_spec/image_spec.py - 1
    • Missing class attribute for docstring · Line 51-51
Review Details
  • Files reviewed - 2 · Commit Range: 2569f80..2569f80
    • flytekit/image_spec/default_builder.py
    • flytekit/image_spec/image_spec.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@flyte-bot
Copy link
Contributor

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
New Feature - Addition of pip_extra_args Parameter

default_builder.py - Added handling for pip_extra_args in prepare_python_install function.

image_spec.py - Introduced pip_extra_args as an optional parameter in ImageSpec.

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

Can you update a list to make sure that the new argument is used?

@@ -82,6 +83,7 @@ class ImageSpec:
platform: str = "linux/amd64"
pip_index: Optional[str] = None
pip_extra_index_url: Optional[List[str]] = None
pip_extra_args: Optional[List[str]] = None
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this a single string and not a list?

Suggested change
pip_extra_args: Optional[List[str]] = None
pip_extra_args: Optional[str] = None

Copy link
Author

@amitani amitani Jan 23, 2025

Choose a reason for hiding this comment

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

I made the update to take a space-delimited string. Just curious, but what's the rationale behind this suggestion? pip_install_args is joined with " " later, so taking a list and extending the list seems more aligned with how it is implemented.

For example, when adding multiple command line arguments, it is done by extending the list of multiple elements, not a single element with multiple command line arguments concatenated with spaces.

pip_install_args.extend(["--locked", "--no-dev", "--no-install-project"])

(a separate topic but it may be worth using shlex instead of " ".join)

Signed-off-by: Akinori Mitani <akinori@artera.ai>
@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 23, 2025

Code Review Agent Run #110b04

Actionable Suggestions - 1
  • flytekit/image_spec/default_builder.py - 1
    • Potential issue with pip_extra_args handling · Line 220-220
Review Details
  • Files reviewed - 2 · Commit Range: 4281029..4281029
    • flytekit/image_spec/default_builder.py
    • flytekit/image_spec/image_spec.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@@ -215,6 +215,9 @@ def prepare_python_install(image_spec: ImageSpec, tmp_dir: Path) -> str:
if image_spec.pip_extra_index_url:
extra_urls = [f"--extra-index-url {url}" for url in image_spec.pip_extra_index_url]
pip_install_args.extend(extra_urls)

if image_spec.pip_extra_args:
pip_install_args.append(image_spec.pip_extra_args)
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential issue with pip_extra_args handling

Consider checking if image_spec.pip_extra_args is a list or a string. If it's a string, it should be split into individual arguments before appending to pip_install_args.

Code suggestion
Check the AI-generated fix before applying
Suggested change
pip_install_args.append(image_spec.pip_extra_args)
if isinstance(image_spec.pip_extra_args, str):
pip_install_args.extend(image_spec.pip_extra_args.split())
else:
pip_install_args.append(image_spec.pip_extra_args)

Code Review Run #110b04


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

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.

3 participants