Skip to content

Drop use of non-standard pkg_resources API#2405

Merged
staticdev merged 3 commits intoPyCQA:mainfrom
dvarrazzo:fix/drop-pkg-resources
Oct 1, 2025
Merged

Drop use of non-standard pkg_resources API#2405
staticdev merged 3 commits intoPyCQA:mainfrom
dvarrazzo:fix/drop-pkg-resources

Conversation

@dvarrazzo
Copy link
Contributor

Use the canonical importlib.metadata.entry_points instead.

Fix #2404

@codecov
Copy link

codecov bot commented Sep 5, 2025

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.19%. Comparing base (0c8fc82) to head (be46cd4).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2405      +/-   ##
==========================================
+ Coverage   99.16%   99.19%   +0.03%     
==========================================
  Files          40       40              
  Lines        3101     3101              
  Branches      680      680              
==========================================
+ Hits         3075     3076       +1     
+ Misses         15       14       -1     
  Partials       11       11              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Left some comments :)

from .wrap_modes import WrapModes
from .wrap_modes import from_string as wrap_mode_from_string

if sys.version_info < (3, 10):
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 keep these imports lazy like it was before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To avoid adding an if every time there was an import pkg_resources I'd have a _pkg_resources internal module exposing entry_points.

What is the rationale?

Copy link
Member

Choose a reason for hiding this comment

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

You could also do this with a cached function in this module that returns the import I think.

Originally somebody thought it better to make this lazy. I don't see a good reason for why we would want to change this so I'd prefer to keep it the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, when the code was importing from pkg_resources, which is a non-standard module teleported in Python virtualenv thanks to obscure forces, I can somewhat understand why the import was lazy: if it suddenly started failing (like now, in Python 3.14) I assume the thought was at least it won't fail for everyone on import but just for people who use this less used feature.

Now that the code is importing either a stdlib function or a function from a package marked as dependency, I don't see a good reason for failing.

AFAICS the package was first used in 2d76984, then some code following a similar pattern was added in b40e584, then again in 4cb72fa. I assume the code was copied over and modified, including the lazy-loading pattern. Maybe @timothycrosley might explain why those import are lazy?

Anyways, the last commit in this MR restores the lazy import behaviour. I don't think it is needed, especially if you have unit tests testing that the package works, but if you want it this way, it's there.

@dvarrazzo dvarrazzo force-pushed the fix/drop-pkg-resources branch from fe1d117 to 2738d63 Compare September 6, 2025 17:40
dvarrazzo added a commit to dvarrazzo/isort that referenced this pull request Sep 6, 2025
No reason I can discern for it, just a matter of traditions I guess.
PyCQA#2405 (comment)
dvarrazzo added a commit to dvarrazzo/isort that referenced this pull request Sep 6, 2025
No reason I can discern for it, just a matter of traditions I guess.
PyCQA#2405 (comment)
@dvarrazzo dvarrazzo force-pushed the fix/drop-pkg-resources branch from 4c39fc4 to c676669 Compare September 6, 2025 17:59
Copy link
Member

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

@staticdev Could you review this as well? I'm wondering what you think of the lazy loading.

Copy link
Collaborator

@staticdev staticdev left a comment

Choose a reason for hiding this comment

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

I would actually remove support for python below 3.10., as 3.9 is pretty much eol: https://endoflife.date/python this actually will simplify the code and the Pr.
I think we can keep the lazy loading like it is right now.

@DanielNoord
Copy link
Member

Seems like a lot more work to do proper clean up of 3.9? I'd say if this work we could at least just merge and release this and unblock 3.14 compatibility.

Afterwards we can worry about cleaning up for 3.9?

@rafaelcapucho
Copy link

I installed it using uv, as in uv tool install isort,

and when using with .isort.cfg, if I add profile = "black" it fails:

[settings]
profile = "black"
multi_line_output = 3
lines_between_types = 1
force_alphabetical_sort_within_sections = 1
Lexicographical = 1
group_by_package = 1
$ isort hdash/project/tasks.py

Traceback (most recent call last):
  File "/Users/kepler/.local/bin/isort", line 10, in <module>
    sys.exit(main())
             ~~~~^^
  File "/Users/kepler/.local/share/uv/tools/isort/lib/python3.13/site-packages/isort/main.py", line 1124, in main
    config = Config(**config_dict)
  File "/Users/kepler/.local/share/uv/tools/isort/lib/python3.13/site-packages/isort/settings.py", line 359, in __init__
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

@DanielNoord
Copy link
Member

@staticdev shall we just merge and release as is?

dvarrazzo added a commit to dvarrazzo/isort that referenced this pull request Sep 30, 2025
No reason I can discern for it, just a matter of traditions I guess.
PyCQA#2405 (comment)
@dvarrazzo dvarrazzo force-pushed the fix/drop-pkg-resources branch from c676669 to 80852d6 Compare September 30, 2025 19:01
dvarrazzo added a commit to dvarrazzo/isort that referenced this pull request Sep 30, 2025
No reason I can discern for it, just a matter of traditions I guess.
PyCQA#2405 (comment)
@dvarrazzo dvarrazzo force-pushed the fix/drop-pkg-resources branch from 80852d6 to c941d8d Compare September 30, 2025 19:03
Use the canonical `importlib.metadata.entry_points` instead, and a well
defined fallback for older Python versions.

Fix PyCQA#2404
No reason I can discern for it, just a matter of traditions I guess.
PyCQA#2405 (comment)
@dvarrazzo dvarrazzo force-pushed the fix/drop-pkg-resources branch from c941d8d to be46cd4 Compare September 30, 2025 19:07
@dvarrazzo
Copy link
Contributor Author

I have rebased this branch on master and fixed the lint job.

Copy link
Collaborator

@staticdev staticdev left a comment

Choose a reason for hiding this comment

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

That is fine, LGTM. Thanks @dvarrazzo and @DanielNoord

@staticdev staticdev added this pull request to the merge queue Oct 1, 2025
Merged via the queue into PyCQA:main with commit ec48dd7 Oct 1, 2025
19 of 21 checks passed
luketainton pushed a commit to luketainton/repos_roboluke that referenced this pull request Oct 2, 2025
This PR contains the following updates:

| Package | Change | Age | Confidence |
|---|---|---|---|
| [isort](https://github.com/PyCQA/isort) ([changelog](https://github.com/PyCQA/isort/releases)) | `<6.1.0,>=6.0.0` -> `<6.1.1,>=6.1.0` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/isort/6.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/isort/6.0.1/6.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>PyCQA/isort (isort)</summary>

### [`v6.1.0`](https://github.com/PyCQA/isort/releases/tag/6.1.0)

[Compare Source](PyCQA/isort@6.0.1...6.1.0)

#### Changes

- Update docs discussions channel ([#&#8203;2410](PyCQA/isort#2410)) [@&#8203;staticdev](https://github.com/staticdev)
- Add python 3.14 classifier and badge ([#&#8203;2409](PyCQA/isort#2409)) [@&#8203;staticdev](https://github.com/staticdev)
- Drop use of non-standard pkg\_resources API ([#&#8203;2405](PyCQA/isort#2405)) [@&#8203;dvarrazzo](https://github.com/dvarrazzo)
- Use working isort version in pre-commit example ([#&#8203;2402](PyCQA/isort#2402)) [@&#8203;iainelder](https://github.com/iainelder)
- fix typo in \_get\_files\_from\_dir\_cached test ([#&#8203;2392](PyCQA/isort#2392)) [@&#8203;tiltingpenguin](https://github.com/tiltingpenguin)
- Resolve bandit warnings ([#&#8203;2379](PyCQA/isort#2379)) [@&#8203;kurtmckee](https://github.com/kurtmckee)
- Add tox for cross-platform, parallel test suite execution ([#&#8203;2378](PyCQA/isort#2378)) [@&#8203;kurtmckee](https://github.com/kurtmckee)
- Add Project URLs to PyPI Side Panel ([#&#8203;2387](PyCQA/isort#2387)) [@&#8203;guillermodotn](https://github.com/guillermodotn)
- Fix typos ([#&#8203;2376](PyCQA/isort#2376)) [@&#8203;co63oc](https://github.com/co63oc)

#### :construction\_worker: Continuous Integration

- Add make bash scripts portable ([#&#8203;2377](PyCQA/isort#2377)) [@&#8203;staticdev](https://github.com/staticdev)

#### 📦 Dependencies

- Bump actions/checkout from 4 to 5 in the github-actions group ([#&#8203;2406](PyCQA/isort#2406)) @&#8203;[dependabot\[bot\]](https://github.com/apps/dependabot)
- Bump astral-sh/setup-uv from 5 to 6 in the github-actions group ([#&#8203;2395](PyCQA/isort#2395)) @&#8203;[dependabot\[bot\]](https://github.com/apps/dependabot)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMzIuNSIsInVwZGF0ZWRJblZlciI6IjQxLjEzMi41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJ0eXBlL2RlcGVuZGVuY2llcyJdfQ==-->

Reviewed-on: https://git.tainton.uk/repos/roboluke/pulls/380
Co-authored-by: Renovate [BOT] <renovate-bot@git.tainton.uk>
Co-committed-by: Renovate [BOT] <renovate-bot@git.tainton.uk>
luketainton pushed a commit to luketainton/repos_epage that referenced this pull request Oct 7, 2025
This PR contains the following updates:

| Package | Change | Age | Confidence |
|---|---|---|---|
| [isort](https://github.com/PyCQA/isort) ([changelog](https://github.com/PyCQA/isort/releases)) | `<6.1.0,>=6.0.0` -> `<6.1.1,>=6.1.0` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/isort/6.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/isort/6.0.1/6.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>PyCQA/isort (isort)</summary>

### [`v6.1.0`](https://github.com/PyCQA/isort/releases/tag/6.1.0)

[Compare Source](PyCQA/isort@6.0.1...6.1.0)

#### Changes

- Update docs discussions channel ([#&#8203;2410](PyCQA/isort#2410)) [@&#8203;staticdev](https://github.com/staticdev)
- Add python 3.14 classifier and badge ([#&#8203;2409](PyCQA/isort#2409)) [@&#8203;staticdev](https://github.com/staticdev)
- Drop use of non-standard pkg\_resources API ([#&#8203;2405](PyCQA/isort#2405)) [@&#8203;dvarrazzo](https://github.com/dvarrazzo)
- Use working isort version in pre-commit example ([#&#8203;2402](PyCQA/isort#2402)) [@&#8203;iainelder](https://github.com/iainelder)
- fix typo in \_get\_files\_from\_dir\_cached test ([#&#8203;2392](PyCQA/isort#2392)) [@&#8203;tiltingpenguin](https://github.com/tiltingpenguin)
- Resolve bandit warnings ([#&#8203;2379](PyCQA/isort#2379)) [@&#8203;kurtmckee](https://github.com/kurtmckee)
- Add tox for cross-platform, parallel test suite execution ([#&#8203;2378](PyCQA/isort#2378)) [@&#8203;kurtmckee](https://github.com/kurtmckee)
- Add Project URLs to PyPI Side Panel ([#&#8203;2387](PyCQA/isort#2387)) [@&#8203;guillermodotn](https://github.com/guillermodotn)
- Fix typos ([#&#8203;2376](PyCQA/isort#2376)) [@&#8203;co63oc](https://github.com/co63oc)

#### :construction\_worker: Continuous Integration

- Add make bash scripts portable ([#&#8203;2377](PyCQA/isort#2377)) [@&#8203;staticdev](https://github.com/staticdev)

#### 📦 Dependencies

- Bump actions/checkout from 4 to 5 in the github-actions group ([#&#8203;2406](PyCQA/isort#2406)) @&#8203;[dependabot\[bot\]](https://github.com/apps/dependabot)
- Bump astral-sh/setup-uv from 5 to 6 in the github-actions group ([#&#8203;2395](PyCQA/isort#2395)) @&#8203;[dependabot\[bot\]](https://github.com/apps/dependabot)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMzIuNSIsInVwZGF0ZWRJblZlciI6IjQxLjEzMi41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJ0eXBlL2RlcGVuZGVuY2llcyJdfQ==-->

Reviewed-on: https://git.tainton.uk/repos/epage/pulls/164
Co-authored-by: Renovate [BOT] <renovate-bot@git.tainton.uk>
Co-committed-by: Renovate [BOT] <renovate-bot@git.tainton.uk>
luketainton pushed a commit to luketainton/repos_webexmemebot that referenced this pull request Jan 5, 2026
This PR contains the following updates:

| Package | Change | Age | Confidence |
|---|---|---|---|
| [isort](https://github.com/PyCQA/isort) ([changelog](https://github.com/PyCQA/isort/releases)) | `<6.1.0,>=6.0.0` -> `<6.1.1,>=6.1.0` | [![age](https://developer.mend.io/api/mc/badges/age/pypi/isort/6.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/isort/6.0.1/6.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>PyCQA/isort (isort)</summary>

### [`v6.1.0`](https://github.com/PyCQA/isort/releases/tag/6.1.0)

[Compare Source](PyCQA/isort@6.0.1...6.1.0)

#### Changes

- Update docs discussions channel ([#&#8203;2410](PyCQA/isort#2410)) [@&#8203;staticdev](https://github.com/staticdev)
- Add python 3.14 classifier and badge ([#&#8203;2409](PyCQA/isort#2409)) [@&#8203;staticdev](https://github.com/staticdev)
- Drop use of non-standard pkg\_resources API ([#&#8203;2405](PyCQA/isort#2405)) [@&#8203;dvarrazzo](https://github.com/dvarrazzo)
- Use working isort version in pre-commit example ([#&#8203;2402](PyCQA/isort#2402)) [@&#8203;iainelder](https://github.com/iainelder)
- fix typo in \_get\_files\_from\_dir\_cached test ([#&#8203;2392](PyCQA/isort#2392)) [@&#8203;tiltingpenguin](https://github.com/tiltingpenguin)
- Resolve bandit warnings ([#&#8203;2379](PyCQA/isort#2379)) [@&#8203;kurtmckee](https://github.com/kurtmckee)
- Add tox for cross-platform, parallel test suite execution ([#&#8203;2378](PyCQA/isort#2378)) [@&#8203;kurtmckee](https://github.com/kurtmckee)
- Add Project URLs to PyPI Side Panel ([#&#8203;2387](PyCQA/isort#2387)) [@&#8203;guillermodotn](https://github.com/guillermodotn)
- Fix typos ([#&#8203;2376](PyCQA/isort#2376)) [@&#8203;co63oc](https://github.com/co63oc)

#### :construction\_worker: Continuous Integration

- Add make bash scripts portable ([#&#8203;2377](PyCQA/isort#2377)) [@&#8203;staticdev](https://github.com/staticdev)

#### 📦 Dependencies

- Bump actions/checkout from 4 to 5 in the github-actions group ([#&#8203;2406](PyCQA/isort#2406)) @&#8203;[dependabot\[bot\]](https://github.com/apps/dependabot)
- Bump astral-sh/setup-uv from 5 to 6 in the github-actions group ([#&#8203;2395](PyCQA/isort#2395)) @&#8203;[dependabot\[bot\]](https://github.com/apps/dependabot)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMzIuNSIsInVwZGF0ZWRJblZlciI6IjQxLjEzMi41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJ0eXBlL2RlcGVuZGVuY2llcyJdfQ==-->

Reviewed-on: https://git.tainton.uk/repos/webexmemebot/pulls/510
Co-authored-by: Renovate [BOT] <renovate-bot@git.tainton.uk>
Co-committed-by: Renovate [BOT] <renovate-bot@git.tainton.uk>
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.

isort not compatible with Python 3.14

4 participants