Public API¶
Tool to check all requirements are actually required.
Classes:
|
Check imports for the given package, against the given requirements. |
|
Represents a requirement which is listed in the requirements file and imported. |
|
Represents a requirement which is imported but not listed in the requirements file. |
|
Represents a requirement which is listed in the requirements file but never imported. |
Functions:
|
Check imports for the given package, against the given requirements file. |
|
Construct either a |
Data:
The template to use when printing output. |
-
class
DepChecker
(pkg_name, requirements, *, allowed_unused=None, name_mapping=None, namespace_packages=None)[source]¶ Check imports for the given package, against the given requirements.
This class can be used to integrate
dep_checker
into other applications.New in version 0.6.0.
- Parameters
pkg_name (
str
)requirements (
Iterable
[str
]) – The package’s (supposed) requirements.allowed_unused (
Optional
[Iterable
[str
]]) – List of requirements which are allowed to be unused in the source code. Default[]
.name_mapping (
Optional
[Mapping
[str
,str
]]) – Optional mapping of requirement names to import names, if they differ.namespace_packages (
Optional
[Iterable
[str
]]) – List of namespace packages, e.g.ruamel.yaml
.
-
check
(work_dir)[source]¶ Perform the check itself.
- Parameters
work_dir (
Union
[str
,Path
,PathLike
]) – The directory to find the source of the package in. Useful with thesrc/
layout.- Return type
Iterable
[Union
[UnlistedRequirement
,PassingRequirement
,UnusedRequirement
]]
-
namedtuple
PassingRequirement
(name, lineno, filename)[source]¶ Bases:
NamedTuple
Represents a requirement which is listed in the requirements file and imported.
New in version 0.6.0.
- Fields
-
namedtuple
UnlistedRequirement
(name, lineno, filename)[source]¶ Bases:
NamedTuple
Represents a requirement which is imported but not listed in the requirements file.
New in version 0.6.0.
- Fields
-
namedtuple
UnusedRequirement
(name)[source]¶ Bases:
NamedTuple
Represents a requirement which is listed in the requirements file but never imported.
New in version 0.6.0.
- Fields
name (
str
) – The name of the requirement.
-
check_imports
(pkg_name, req_file='requirements.txt', allowed_unused=None, colour=None, name_mapping=None, namespace_packages=None, work_dir='.')[source]¶ Check imports for the given package, against the given requirements file.
- Parameters
pkg_name (
str
)req_file (
Union
[str
,Path
,PathLike
]) – Default'requirements.txt'
.allowed_unused (
Optional
[List
[str
]]) – List of requirements which are allowed to be unused in the source code. Default[]
.name_mapping (
Optional
[Dict
[str
,str
]]) – Optional mapping of requirement names to import names, if they differ.namespace_packages (
Optional
[List
[str
]]) – List of namespace packages, e.g.ruamel.yaml
.work_dir (
Union
[str
,Path
,PathLike
]) – The directory to find the source of the package in. Useful with the src/ layout. Default'.'
.
- Return type
Returns
0
if all requirements are used and listed as requirements.Returns
1
is a requirement is unused, or if a package is imported but not listed as a requirement.
Changed in version 0.4.1:Added the
name_mapping
option.Added the
work_dir
option.
-
make_requirement_tuple
(data)[source]¶ Construct either a
PassingRequirement
, orUnlistedRequirement
, orUnusedRequirement
, depending on the value of theclass
key.Typically used to reconstruct an object from the dictionary produced by the
_asdict()
method of those classes.New in version 0.6.0.
- Parameters
- Return type
Union
[Type
[PassingRequirement
],Type
[UnlistedRequirement
],Type
[UnusedRequirement
]]