-
Notifications
You must be signed in to change notification settings - Fork 24
Remove deprecated pkg_resources usage for setuptools >= 82 compatibility
#473
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
tchaton
merged 14 commits into
Lightning-AI:main
from
bhimrazy:fix/remove-pkg-resources
Feb 10, 2026
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f8e0239
drop pkg resources dependency
bhimrazy 83d92a9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3b798dd
Add unit tests for requirements parsing and adjustment functions
bhimrazy 4adceb3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b31df22
update
bhimrazy b19d104
Apply suggestions
bhimrazy ba0c905
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 64a7899
Apply suggestions
bhimrazy 64a33f5
Refactor requirement parsing to ensure string conversion of requirements
bhimrazy fd95cd3
Enhance upper bound removal logic in requirement adjustment and add c…
bhimrazy d22c97f
Apply suggestion from @Copilot
bhimrazy 14c6fbd
Fix line continuation handling in requirement parsing and add corresp…
bhimrazy 09b83aa
Refactor yield_lines to _yield_lines for consistency and update tests…
bhimrazy db7abbc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| [build-system] | ||
| requires = [ | ||
| "packaging", | ||
| "setuptools", | ||
| "wheel", | ||
| ] | ||
|
|
||
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
Empty file.
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,129 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from lightning_utilities.install.requirements import ( | ||
| _parse_requirements, | ||
| _RequirementWithComment, | ||
| load_requirements, | ||
| yield_lines, | ||
| ) | ||
|
|
||
| _PATH_ROOT = Path(__file__).parent.parent.parent.parent | ||
|
|
||
|
|
||
| def test_yield_lines_from_list(): | ||
| assert list(yield_lines(["foo", " bar ", "", "# comment", "baz"])) == ["foo", "bar", "baz"] | ||
|
|
||
|
|
||
| def test_yield_lines_from_string(): | ||
| assert list(yield_lines("foo\n bar \n\n# comment\nbaz")) == ["foo", "bar", "baz"] | ||
|
|
||
|
|
||
| def test_yield_lines_empty(): | ||
| assert list(yield_lines([])) == [] | ||
| assert list(yield_lines("")) == [] | ||
|
|
||
|
|
||
| def test_requirement_with_comment_attributes(): | ||
| req = _RequirementWithComment("arrow>=1.0", comment="# my comment") | ||
| assert req.name == "arrow" | ||
| assert req.comment == "# my comment" | ||
| assert req.pip_argument is None | ||
| assert req.strict is False | ||
|
|
||
|
|
||
| def test_requirement_with_comment_strict(): | ||
| assert _RequirementWithComment("arrow>=1.0", comment="# strict").strict is True | ||
| assert _RequirementWithComment("arrow>=1.0", comment="# Strict pinning").strict is True | ||
|
|
||
|
|
||
| def test_requirement_with_comment_pip_argument(): | ||
| req = _RequirementWithComment("arrow>=1.0", pip_argument="--extra-index-url https://x") | ||
| assert req.pip_argument == "--extra-index-url https://x" | ||
|
|
||
| with pytest.raises(RuntimeError, match="wrong pip argument"): | ||
| _RequirementWithComment("arrow>=1.0", pip_argument="") | ||
|
|
||
|
|
||
| def test_adjust_none(): | ||
| assert _RequirementWithComment("arrow<=1.2,>=1.0").adjust("none") == "arrow<=1.2,>=1.0" | ||
| assert ( | ||
| _RequirementWithComment("arrow<=1.2,>=1.0", comment="# strict").adjust("none") == "arrow<=1.2,>=1.0 # strict" | ||
| ) | ||
|
|
||
|
|
||
| def test_adjust_all(): | ||
| assert _RequirementWithComment("arrow<=1.2,>=1.0").adjust("all") == "arrow>=1.0" | ||
| assert _RequirementWithComment("arrow<=1.2,>=1.0", comment="# strict").adjust("all") == "arrow<=1.2,>=1.0 # strict" | ||
| assert _RequirementWithComment("arrow").adjust("all") == "arrow" | ||
|
|
||
bhimrazy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def test_adjust_major(): | ||
| assert _RequirementWithComment("arrow>=1.2.0, <=1.2.2").adjust("major") == "arrow<2.0,>=1.2.0" | ||
| assert _RequirementWithComment("lib>=0.5, <=0.9").adjust("major") == "lib<1.0,>=0.5" | ||
| assert ( | ||
| _RequirementWithComment("arrow>=1.2.0, <=1.2.2", comment="# strict").adjust("major") | ||
| == "arrow<=1.2.2,>=1.2.0 # strict" | ||
| ) | ||
| assert _RequirementWithComment("arrow>=1.2.0").adjust("major") == "arrow>=1.2.0" | ||
|
|
||
|
|
||
| def test_adjust_invalid_unfreeze(): | ||
| with pytest.raises(ValueError, match="Unexpected unfreeze"): | ||
| _RequirementWithComment("arrow>=1.0").adjust("invalid") | ||
|
|
||
|
|
||
| def test_parse_requirements_basic(): | ||
| reqs = list(_parse_requirements(["# comment", "", "numpy>=1.0", "pandas<2.0"])) | ||
| assert [str(r) for r in reqs] == ["numpy>=1.0", "pandas<2.0"] | ||
|
|
||
|
|
||
| def test_parse_requirements_from_string(): | ||
| reqs = list(_parse_requirements("# comment\n\nnumpy>=1.0\npandas<2.0")) | ||
| assert [str(r) for r in reqs] == ["numpy>=1.0", "pandas<2.0"] | ||
|
|
||
|
|
||
| def test_parse_requirements_preserves_comments(): | ||
| reqs = list(_parse_requirements(["arrow>=1.0 # strict"])) | ||
| assert len(reqs) == 1 | ||
| assert reqs[0].comment == " # strict" | ||
| assert reqs[0].strict is True | ||
|
|
||
|
|
||
| def test_parse_requirements_pip_argument(): | ||
| reqs = list(_parse_requirements(["--extra-index-url https://x", "torch>=2.0"])) | ||
| assert len(reqs) == 1 | ||
| assert reqs[0].pip_argument == "--extra-index-url https://x" | ||
|
|
||
|
|
||
| def test_parse_requirements_skips(): | ||
| reqs = list(_parse_requirements(["-r other.txt", "pesq @ git+https://github.com/foo/bar", "numpy"])) | ||
| assert len(reqs) == 1 | ||
| assert reqs[0].name == "numpy" | ||
|
|
||
|
|
||
| def test_load_requirements_core(): | ||
| path_req = str(_PATH_ROOT / "requirements") | ||
| reqs = load_requirements(path_req, "core.txt", unfreeze="all") | ||
| assert len(reqs) > 0 | ||
| assert any("packaging" in r for r in reqs) | ||
bhimrazy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def test_load_requirements_nonexistent(tmpdir): | ||
| with pytest.raises(FileNotFoundError): | ||
| load_requirements(str(tmpdir), "nonexistent.txt") | ||
|
|
||
|
|
||
| def test_load_requirements_invalid_unfreeze(tmpdir): | ||
| with pytest.raises(ValueError, match="unsupported"): | ||
| load_requirements(str(tmpdir), "x.txt", unfreeze="bad") | ||
|
|
||
|
|
||
| def test_load_requirements_unfreeze_strategies(tmpdir): | ||
| req_file = tmpdir / "test.txt" | ||
| req_file.write("arrow>=1.2.0, <=1.2.2\n") | ||
|
|
||
| assert load_requirements(str(tmpdir), "test.txt", unfreeze="none") == ["arrow<=1.2.2,>=1.2.0"] | ||
| assert load_requirements(str(tmpdir), "test.txt", unfreeze="major") == ["arrow<2.0,>=1.2.0"] | ||
| assert load_requirements(str(tmpdir), "test.txt", unfreeze="all") == ["arrow>=1.2.0"] | ||
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.
Uh oh!
There was an error while loading. Please reload this page.