-
Notifications
You must be signed in to change notification settings - Fork 53
feat: Support multiple pip index URLs in CustomTrainer #79
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
Merged
google-oss-prow
merged 12 commits into
kubeflow:main
from
wassimbensalem:feature/support-multiple-pip-index-urls-clean
Sep 5, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f976500
feat: Support multiple pip index URLs in CustomTrainer
wassimbensalem 2ffc235
test: add comprehensive test cases for multiple pip index URLs
wassimbensalem f8f1e78
refactor: simplify constants for pip index URLs
wassimbensalem 75084bb
fix: remove Optional from pip_index_urls docstring to match implement…
wassimbensalem c4f6152
test: adjust unit test for get_custom_trainer
wassimbensalem 5eb42b1
fix: add missing Dict import in utils.py
wassimbensalem f87e9c4
refactor: move test cases to utils_test.py and convert to parametrize…
wassimbensalem 797ce88
refactor: update utils test to use exact string matching instead of c…
wassimbensalem 990f4c4
feat: add multiple pip index URLs support with comprehensive tests
wassimbensalem 0ec003d
refactor: remove redundant multiple pip index URLs test from backend
wassimbensalem 39ca82d
Revert "refactor: remove redundant multiple pip index URLs test from …
wassimbensalem c084980
refactor: remove duplicated test case from the backend.
wassimbensalem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| # Copyright 2025 The Kubeflow Authors. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Any, Dict | ||
|
|
||
| import pytest | ||
|
|
||
| from kubeflow.trainer.utils import utils | ||
| from kubeflow.trainer.constants import constants | ||
|
|
||
|
|
||
| @dataclass | ||
| class TestCase: | ||
| name: str | ||
| config: Dict[str, Any] | ||
| expected_output: str | ||
| __test__ = False | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "test_case", | ||
| [ | ||
| TestCase( | ||
| name="multiple pip index URLs", | ||
| config={ | ||
| "packages_to_install": ["torch", "numpy", "custom-package"], | ||
| "pip_index_urls": [ | ||
| "https://pypi.org/simple", | ||
| "https://private.repo.com/simple", | ||
| "https://internal.company.com/simple" | ||
| ], | ||
| "is_mpi": False | ||
| }, | ||
| expected_output=( | ||
| '\nif ! [ -x "$(command -v pip)" ]; then\n' | ||
| ' python -m ensurepip || python -m ensurepip --user || ' | ||
| 'apt-get install python-pip\n' | ||
| 'fi\n\n' | ||
| 'PIP_DISABLE_PIP_VERSION_CHECK=1 python -m pip install --quiet ' | ||
| '--no-warn-script-location --index-url https://pypi.org/simple ' | ||
| '--extra-index-url https://private.repo.com/simple ' | ||
| '--extra-index-url https://internal.company.com/simple ' | ||
| 'torch numpy custom-package\n' | ||
| ) | ||
| ), | ||
| TestCase( | ||
| name="single pip index URL (backward compatibility)", | ||
| config={ | ||
| "packages_to_install": ["torch", "numpy", "custom-package"], | ||
| "pip_index_urls": ["https://pypi.org/simple"], | ||
| "is_mpi": False | ||
| }, | ||
| expected_output=( | ||
| '\nif ! [ -x "$(command -v pip)" ]; then\n' | ||
| ' python -m ensurepip || python -m ensurepip --user || ' | ||
| 'apt-get install python-pip\n' | ||
| 'fi\n\n' | ||
| 'PIP_DISABLE_PIP_VERSION_CHECK=1 python -m pip install --quiet ' | ||
| '--no-warn-script-location --index-url https://pypi.org/simple ' | ||
| 'torch numpy custom-package\n' | ||
| ) | ||
| ), | ||
| TestCase( | ||
| name="multiple pip index URLs with MPI", | ||
| config={ | ||
| "packages_to_install": ["torch", "numpy", "custom-package"], | ||
| "pip_index_urls": [ | ||
| "https://pypi.org/simple", | ||
| "https://private.repo.com/simple", | ||
| "https://internal.company.com/simple" | ||
| ], | ||
| "is_mpi": True | ||
| }, | ||
| expected_output=( | ||
| '\nif ! [ -x "$(command -v pip)" ]; then\n' | ||
| ' python -m ensurepip || python -m ensurepip --user || ' | ||
| 'apt-get install python-pip\n' | ||
| 'fi\n\n' | ||
| 'PIP_DISABLE_PIP_VERSION_CHECK=1 python -m pip install --quiet ' | ||
| '--no-warn-script-location --index-url https://pypi.org/simple ' | ||
| '--extra-index-url https://private.repo.com/simple ' | ||
| '--extra-index-url https://internal.company.com/simple ' | ||
| '--user torch numpy custom-package\n' | ||
| ) | ||
| ), | ||
| TestCase( | ||
| name="default pip index URLs", | ||
| config={ | ||
| "packages_to_install": ["torch", "numpy"], | ||
| "pip_index_urls": constants.DEFAULT_PIP_INDEX_URLS, | ||
| "is_mpi": False | ||
| }, | ||
| expected_output=( | ||
| '\nif ! [ -x "$(command -v pip)" ]; then\n' | ||
| ' python -m ensurepip || python -m ensurepip --user || ' | ||
| 'apt-get install python-pip\n' | ||
| 'fi\n\n' | ||
| 'PIP_DISABLE_PIP_VERSION_CHECK=1 python -m pip install --quiet ' | ||
| f'--no-warn-script-location --index-url ' | ||
| f'{constants.DEFAULT_PIP_INDEX_URLS[0]} torch numpy\n' | ||
| ) | ||
| ), | ||
| ], | ||
| ) | ||
| def test_get_script_for_python_packages(test_case): | ||
| """Test get_script_for_python_packages with various configurations.""" | ||
|
|
||
| script = utils.get_script_for_python_packages( | ||
| packages_to_install=test_case.config["packages_to_install"], | ||
| pip_index_urls=test_case.config["pip_index_urls"], | ||
| is_mpi=test_case.config["is_mpi"] | ||
| ) | ||
|
|
||
| assert test_case.expected_output == script |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit: could be other packages since those are already in the runtime image.