-
Notifications
You must be signed in to change notification settings - Fork 1
Add pyproject.toml support for container dependency installs
#84
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
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,104 @@ | ||
| """E2E tests for pyproject.toml dependency support. | ||
|
|
||
| These tests verify that dependencies declared in ``pyproject.toml`` are | ||
| correctly extracted, used for container building, and available in the | ||
| remote environment. | ||
|
|
||
| A temporary ``pyproject.toml`` is written to a temp directory. Only the | ||
| discovery function (``_find_requirements``) is patched to return that path; | ||
| the rest of the pipeline — parsing, JAX filtering, container building, and | ||
| remote execution — runs for real. | ||
|
|
||
| Set E2E_TESTS=1 to enable. | ||
| """ | ||
|
|
||
| import pathlib | ||
| import tempfile | ||
| from unittest import mock | ||
|
|
||
| from absl.testing import absltest | ||
|
|
||
| import keras_remote | ||
| from tests.e2e.e2e_utils import skip_unless_e2e | ||
|
|
||
|
|
||
| def _make_test_dir(test_case): | ||
| """Create a temp directory cleaned up after the test.""" | ||
| td = tempfile.TemporaryDirectory() | ||
| test_case.addCleanup(td.cleanup) | ||
| return pathlib.Path(td.name) | ||
|
|
||
|
|
||
| @skip_unless_e2e() | ||
| class TestPyprojectTomlDependencies(absltest.TestCase): | ||
| """Verify that [project.dependencies] from pyproject.toml are installed.""" | ||
|
|
||
| def _create_pyproject(self, content): | ||
| """Write a pyproject.toml in a temp directory and return its path.""" | ||
| tmp = _make_test_dir(self) | ||
| pyproject = tmp / "pyproject.toml" | ||
| pyproject.write_text(content) | ||
| return str(pyproject) | ||
|
|
||
| def test_dependency_installed_on_remote(self): | ||
| """A dependency from pyproject.toml is importable in the remote function.""" | ||
| path = self._create_pyproject( | ||
| '[project]\nname = "test"\nversion = "0.1"\n' | ||
| 'dependencies = ["humanize>=4.0"]\n' | ||
| ) | ||
|
|
||
| @keras_remote.run(accelerator="cpu") | ||
| def use_humanize(): | ||
| import humanize | ||
|
|
||
| return humanize.intcomma(1_000_000) | ||
|
|
||
| with mock.patch( | ||
| "keras_remote.backend.execution._find_requirements", | ||
| return_value=path, | ||
| ): | ||
| result = use_humanize() | ||
|
|
||
| self.assertEqual(result, "1,000,000") | ||
|
|
||
| def test_pyproject_without_deps_succeeds(self): | ||
| """A pyproject.toml with no [project.dependencies] doesn't break the pipeline.""" | ||
| path = self._create_pyproject("[tool.ruff]\nline-length = 88\n") | ||
|
|
||
| @keras_remote.run(accelerator="cpu") | ||
| def simple_add(a, b): | ||
| return a + b | ||
|
|
||
| with mock.patch( | ||
| "keras_remote.backend.execution._find_requirements", | ||
| return_value=path, | ||
| ): | ||
| result = simple_add(10, 20) | ||
|
|
||
| self.assertEqual(result, 30) | ||
|
|
||
| def test_jax_filtered_from_pyproject_deps(self): | ||
| """JAX packages in pyproject.toml are filtered like in requirements.txt.""" | ||
| path = self._create_pyproject( | ||
| '[project]\nname = "test"\nversion = "0.1"\n' | ||
| 'dependencies = ["jax", "humanize>=4.0"]\n' | ||
| ) | ||
|
|
||
| @keras_remote.run(accelerator="cpu") | ||
| def check_humanize(): | ||
| import humanize | ||
|
|
||
| return humanize.intcomma(2_500) | ||
|
|
||
| with mock.patch( | ||
| "keras_remote.backend.execution._find_requirements", | ||
| return_value=path, | ||
| ): | ||
| result = check_humanize() | ||
|
|
||
| # humanize was installed (not filtered), jax was filtered silently | ||
| self.assertEqual(result, "2,500") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| absltest.main() |
Oops, something went wrong.
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.
This is a well-implemented function. For better type consistency and to align with how empty
requirements.txtfiles are handled (which are read as an empty string), consider changing the return type fromstr | Noneto juststr. The function can return an empty string""when no dependencies are found.This would involve changing the function signature, implementation, and docstring. The corresponding unit tests would also need to be updated to check for
""instead ofNoneon failure cases.