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

Add DEP005 to detect dependencies that are in the standard library #761

Merged
merged 15 commits into from
Jul 20, 2024

Conversation

fpgmaas
Copy link
Owner

@fpgmaas fpgmaas commented Jul 12, 2024

Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

Description

This PR proposes to fix #760 by adding a DEP005 to deptry that detects dependencies that are already in the standard library. Running this on this example project results in the following:

Scanning 1 file...

pyproject.toml: DEP002 'pathlib' defined as a dependency but not used in the codebase
pyproject.toml: DEP005 'asyncio' is defined as a dependency but it is included in the Python standard library.
pyproject.toml: DEP005 'pathlib' is defined as a dependency but it is included in the Python standard library.
Found 3 dependency issues.

For more information, see the documentation: https://deptry.com/

Limitations

For situations where a package is first avaialble on PyPI and then added to the standard library with the same name, it could happen that yusers add the following to their configuration:

dependencies = [
    "foo; python_version < '3.X'", 
]

In this case, deptry will incorrectly flag this as a DEP005 issue. However, I believe this issue is negligible because only a limited number of packages have been added to the standard library in recent versions, and the related packages on PyPI typically do not have the same name as their standard library counterparts (e.g., for zoneinfo, the PyPI package is named backports.zoneinfo), and this will not raise an error with deptry. If this becomes an issue in the future we can try to improve this behavior by checking the conditions of the dependencies.

@fpgmaas fpgmaas marked this pull request as draft July 12, 2024 18:58
@fpgmaas fpgmaas requested a review from mkniewallner July 12, 2024 19:11
Copy link

codecov bot commented Jul 12, 2024

Codecov Report

Attention: Patch coverage is 89.36170% with 5 lines in your changes missing coverage. Please review.

Project coverage is 93.0%. Comparing base (5d07b7d) to head (700047d).

Files Patch % Lines
...n/deptry/violations/dep004_misplaced_dev/finder.py 33.3% 1 Missing and 1 partial ⚠️
python/deptry/core.py 50.0% 1 Missing ⚠️
...eptry/violations/dep005_standard_library/finder.py 95.4% 0 Missing and 1 partial ⚠️
...ry/violations/dep005_standard_library/violation.py 90.9% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #761     +/-   ##
=======================================
- Coverage   93.0%   93.0%   -0.1%     
=======================================
  Files         35      37      +2     
  Lines        920     961     +41     
  Branches     165     173      +8     
=======================================
+ Hits         856     894     +38     
- Misses        50      51      +1     
- Partials      14      16      +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

python/deptry/violations/base.py Outdated Show resolved Hide resolved
python/deptry/violations/dep005_standard_library/finder.py Outdated Show resolved Hide resolved
python/deptry/violations/finder.py Outdated Show resolved Hide resolved
python/deptry/violations/finder.py Outdated Show resolved Hide resolved
fpgmaas and others added 5 commits July 19, 2024 13:52
Co-authored-by: Mathieu Kniewallner <mathieu.kniewallner@gmail.com>
Co-authored-by: Mathieu Kniewallner <mathieu.kniewallner@gmail.com>
@fpgmaas fpgmaas requested a review from mkniewallner July 19, 2024 13:01
@fpgmaas fpgmaas merged commit b0f757b into main Jul 20, 2024
21 of 22 checks passed
@fpgmaas fpgmaas deleted the feat/standard-library branch July 20, 2024 14:41
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.

Incorrect error when project contains dependencies that are also in the standard library
2 participants