From 647d0bb5d1937bc1d7e4b59b1af5b7402bb7faf0 Mon Sep 17 00:00:00 2001 From: Florian Maas Date: Mon, 12 Sep 2022 11:17:10 +0200 Subject: [PATCH] fixed some typos --- README.md | 2 +- deptry/cli.py | 4 ++-- deptry/dependency.py | 2 +- deptry/dependency_getter/requirements_txt.py | 15 ++++++++++++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a6fd6ed7..4a97bba4 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ pip install deptry ### Prerequisites -_deptry_ should be run withing the root directory of the project to be scanned, and the proejct should be running in its own dedicated virtual environment. +_deptry_ should be run withing the root directory of the project to be scanned, and the project should be running in its own dedicated virtual environment. ### Usage diff --git a/deptry/cli.py b/deptry/cli.py index e9accdfb..ffac0a1e 100644 --- a/deptry/cli.py +++ b/deptry/cli.py @@ -217,7 +217,7 @@ def log_obsolete_dependencies(dependencies: List[str], sep="\n\t") -> None: logging.info("\n-----------------------------------------------------\n") logging.info(f"The project contains obsolete dependencies:\n{sep}{sep.join(sorted(dependencies))}\n") logging.info( - """Consider removing them from your projects dependencies. If a package is used for development purposes, you should add + """Consider removing them from your project's dependencies. If a package is used for development purposes, you should add it to your development dependencies instead.""" ) @@ -233,7 +233,7 @@ def log_missing_dependencies(dependencies: List[str], sep="\n\t") -> None: def log_transitive_dependencies(dependencies: List[str], sep="\n\t") -> None: logging.info("\n-----------------------------------------------------\n") logging.info( - f"There are transitive dependencies that should be explicitly defined as dependencies in pyproject.toml:\n{sep}{sep.join(sorted(dependencies))}\n" + f"There are transitive dependencies that should be explicitly defined as dependencies:\n{sep}{sep.join(sorted(dependencies))}\n" ) logging.info("""They are currently imported but not specified directly as your project's dependencies.""") diff --git a/deptry/dependency.py b/deptry/dependency.py index b71d8a26..fee80b3f 100644 --- a/deptry/dependency.py +++ b/deptry/dependency.py @@ -17,7 +17,7 @@ class Dependency: def __init__(self, name: str, conditional: bool = False, optional: bool = False) -> None: """ Args: - name: Name of the dependency, as shown in pyproject.toml or requirements.txt + name: Name of the dependency, as shown in pyproject.toml conditional: boolean to indicate if the dependency is conditional, e.g. 'importlib-metadata': {'version': '*', 'python': '<=3.7'} """ self.name = name diff --git a/deptry/dependency_getter/requirements_txt.py b/deptry/dependency_getter/requirements_txt.py index 827b7270..bdc5fec6 100644 --- a/deptry/dependency_getter/requirements_txt.py +++ b/deptry/dependency_getter/requirements_txt.py @@ -26,13 +26,13 @@ def __init__( def get(self): if not self.dev: - dependencies = self._get_dependencies_from_requirements_txt(self.requirements_txt) + dependencies = self._get_dependencies_from_requirements_file(self.requirements_txt) else: dev_requirements_files = self._scan_for_dev_requirements_files() if dev_requirements_files: dependencies = [] for file_name in dev_requirements_files: - dependencies += self._get_dependencies_from_requirements_txt(file_name) + dependencies += self._get_dependencies_from_requirements_file(file_name) else: return [] @@ -40,12 +40,15 @@ def get(self): return dependencies def _scan_for_dev_requirements_files(self): + """ + Check if any of the files passed as requirements_txt_dev exist, and if so; return them. + """ dev_requirements_files = [file_name for file_name in self.requirements_txt_dev if file_name in os.listdir()] if dev_requirements_files: logging.debug(f"Found files with development requirements! {dev_requirements_files}") return dev_requirements_files - def _get_dependencies_from_requirements_txt(self, file_name: str): + def _get_dependencies_from_requirements_file(self, file_name: str): logging.debug(f"Scanning {file_name} for {'dev-' if self.dev else ''}dependencies") dependencies = [] @@ -60,6 +63,9 @@ def _get_dependencies_from_requirements_txt(self, file_name: str): return dependencies def _extract_dependency_from_line(self, line: str) -> Dependency: + """ + Extract a dependency from a single line of a requirements.txt file. + """ line = self._remove_comments_from(line) line = self._remove_newlines_from(line) name = self._find_dependency_name_in(line) @@ -73,6 +79,9 @@ def _extract_dependency_from_line(self, line: str) -> Dependency: @staticmethod def _find_dependency_name_in(line): + """ + Find the dependency name of a dependency specified according to the pip-standards for requirement.txt + """ match = re.search("^[a-zA-Z0-9-_]+", line) if match and not match.group(0)[0] == "-": name = match.group(0)