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

Pyproject.toml support for DockerSettings #3292

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

schustmi
Copy link
Contributor

@schustmi schustmi commented Jan 17, 2025

Describe changes

This PR adds support for pyproject.toml files to be specified for installing requirements in Docker images.
ZenML will extract the requirements from the pyproject.toml using one of the default or a custom user-provided command.

Additionally, this PR changes the functionality if no requirements are specified in the DockerSettings at all:

  • First, ZenML will look for a file called requirements.txt in the source-root, and automatically install that
  • If that doesn't exist, it will look for a file called pyproject.toml and try to export the requirements from that.

Pre-requisites

Please ensure you have done the following:

  • I have read the CONTRIBUTING.md document.
  • I have added tests to cover my changes.
  • I have based my new branch on develop and the open PR is targeting develop. If your branch wasn't based on develop read Contribution guide on rebasing branch to develop.
  • IMPORTANT: I made sure that my changes are reflected properly in the following resources:
    • ZenML Docs
    • Dashboard: Needs to be communicated to the frontend team.
    • Templates: Might need adjustments (that are not reflected in the template tests) in case of non-breaking changes and deprecations.
    • Projects: Depending on the version dependencies, different projects might get affected.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Other (add details above)

Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@schustmi schustmi changed the title pyproject.toml for DockerSettings Pyproject.toml support for DockerSettings Jan 17, 2025
@github-actions github-actions bot added internal To filter out internal PRs and issues enhancement New feature or request labels Jan 17, 2025
@schustmi
Copy link
Contributor Author

@htahir1 Any ideas for the general docs structure of this? Or do we just leave it as-is for now?

@schustmi schustmi requested a review from stefannica January 20, 2025 13:43
@schustmi schustmi marked this pull request as ready for review January 20, 2025 13:43
@htahir1
Copy link
Contributor

htahir1 commented Jan 20, 2025

So I think the docs need to change in these places too:

Now that we have our pipeline up and running in the cloud, you might be wondering how ZenML figured out what sort of dependencies to install in the Docker image that we just ran on the VM. The answer lies in the runner script we executed (i.e. run.py), in particular, these lines:

@schustmi schustmi requested a review from bcdurak January 28, 2025 08:02
Copy link
Contributor

@bcdurak bcdurak left a comment

Choose a reason for hiding this comment

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

Leaving some initial comments.

@@ -68,6 +68,12 @@
}
UV_DEFAULT_ARGS = {"no-cache-dir": None}

# TODO: these don't actually install any extras. Should we include all extras? No extras? Exclude dev extras?
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a reminder for the TODO.

- The packages specified via the `required_integrations`
- The packages defined inside a pyproject.toml file given by the
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is a misalignment with the docs here. In the docs, we say the priority is as follows:

  1. Packages in the local env
  2. Packages for the stack
  3. Required Integrations
  4. Requirements (could be a list or a path to a requirements.txt)
  5. Pyproject.toml next

In the docstring here, 4 and 5 are switched.

Copy link
Contributor

@bcdurak bcdurak Jan 30, 2025

Choose a reason for hiding this comment

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

I see that the docstring here is correct in the code and the docs need to be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I fixed the error in the docs.

In general, there are two scenarios:

  • You don't explicitly specify any requirements using docker settings: In this case we first look for a requirements.txt (-> highest priority), and if it doesn't exist we look for a pyproject.toml
  • You do explicitly specify some requirements (using e.g. DockerSettings.required_integrations or DockerSettings.requirements): In this case the order in the docstring is the one that is being used. Requirements being last means it is the highest priority (it will override values from all previous steps), which is in line with the first case.

Do you think these make sense?

if not any(
[
docker_settings.replicate_local_python_environment,
docker_settings.required_integrations,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean that adding an extra integration (or a package) to be installed disables the discovery of the implicit requirements? So, if I was not using any of these settings before and now want to add sklearn to my docker settings, suddenly the requirements.txt will not be detected. I am not sure if this is the optimal behavior here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. I'm not super convinced by it myself to be honest, but what would be a better alternative in your opinion?

] = Field(default=None, union_mode="left_to_right")
pyproject_path: Optional[str] = None
pyproject_export_command: Optional[List[str]] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can see, it is possible to set this as follows: DockerSettings(pyproject_export_command=[......]) without an explicit pyproject_path as long as there is a pyproject.toml file to work with, in the current source root. But as soon as someone puts an integration, requirement or the replicate flag, this becomes unused.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps a validator can be helpful to detect this early.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would you validate here? I don't see the problem of this being unused if there is no pyproject.toml to be honest

Copy link
Contributor

✅ No broken markdown links found!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request internal To filter out internal PRs and issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants