-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
DEP005
to detect dependencies that are in the standard library (#…
…761) Co-authored-by: Mathieu Kniewallner <mathieu.kniewallner@gmail.com>
- Loading branch information
1 parent
5d07b7d
commit b0f757b
Showing
23 changed files
with
251 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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.
43 changes: 43 additions & 0 deletions
43
python/deptry/violations/dep005_standard_library/finder.py
This file contains 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,43 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING | ||
|
||
from deptry.imports.location import Location | ||
from deptry.violations.base import ViolationsFinder | ||
from deptry.violations.dep005_standard_library.violation import DEP005StandardLibraryDependencyViolation | ||
|
||
if TYPE_CHECKING: | ||
from deptry.violations import Violation | ||
|
||
|
||
@dataclass | ||
class DEP005StandardLibraryDependenciesFinder(ViolationsFinder): | ||
""" | ||
Finds dependencies that are part of the standard library but are defined as dependencies. | ||
""" | ||
|
||
violation = DEP005StandardLibraryDependencyViolation | ||
|
||
def find(self) -> list[Violation]: | ||
logging.debug("\nScanning for dependencies that are part of the standard library...") | ||
stdlib_violations: list[Violation] = [] | ||
|
||
for dependency in self.dependencies: | ||
logging.debug("Scanning module %s...", dependency.name) | ||
|
||
if dependency.name in self.standard_library_modules: | ||
if dependency.name in self.ignored_modules: | ||
logging.debug( | ||
"Dependency '%s' found to be a dependency that is part of the standard library, but ignoring.", | ||
dependency.name, | ||
) | ||
continue | ||
|
||
logging.debug( | ||
"Dependency '%s' marked as a dependency that is part of the standard library.", dependency.name | ||
) | ||
stdlib_violations.append(self.violation(dependency, Location(dependency.definition_file))) | ||
|
||
return stdlib_violations |
21 changes: 21 additions & 0 deletions
21
python/deptry/violations/dep005_standard_library/violation.py
This file contains 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,21 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING, ClassVar | ||
|
||
from deptry.violations.base import Violation | ||
|
||
if TYPE_CHECKING: | ||
from deptry.dependency import Dependency | ||
|
||
|
||
@dataclass | ||
class DEP005StandardLibraryDependencyViolation(Violation): | ||
error_code: ClassVar[str] = "DEP005" | ||
error_template: ClassVar[str] = ( | ||
"'{name}' is defined as a dependency but it is included in the Python standard library." | ||
) | ||
issue: Dependency | ||
|
||
def get_error_message(self) -> str: | ||
return self.error_template.format(name=self.issue.name) |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
import click | ||
import white as w | ||
from urllib3 import contrib | ||
import asyncio |
This file contains 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
Oops, something went wrong.