diff --git a/src/codemodder/dependency_management/base_dependency_writer.py b/src/codemodder/dependency_management/base_dependency_writer.py index 11f89d28..22236984 100644 --- a/src/codemodder/dependency_management/base_dependency_writer.py +++ b/src/codemodder/dependency_management/base_dependency_writer.py @@ -21,12 +21,12 @@ def write( ) -> Optional[ChangeSet]: pass - def add(self, dependencies: list[Dependency]) -> Optional[list[Dependency]]: + def add(self, dependencies: list[Dependency]) -> list[Dependency]: """add any number of dependencies to the end of list of dependencies.""" new = [] for new_dep in dependencies: requirement: Requirement = new_dep.requirement if requirement not in self.dependency_store.dependencies: - self.dependency_store.dependencies.append(requirement) + self.dependency_store.dependencies.add(requirement) new.append(new_dep) return new diff --git a/src/codemodder/project_analysis/file_parsers/package_store.py b/src/codemodder/project_analysis/file_parsers/package_store.py index ce39c760..7c9b9cb9 100644 --- a/src/codemodder/project_analysis/file_parsers/package_store.py +++ b/src/codemodder/project_analysis/file_parsers/package_store.py @@ -6,5 +6,5 @@ class PackageStore: type: str file: str - dependencies: list[Requirement] + dependencies: set[Requirement] py_versions: list[str] diff --git a/src/codemodder/project_analysis/file_parsers/pyproject_toml_file_parser.py b/src/codemodder/project_analysis/file_parsers/pyproject_toml_file_parser.py index 8cb5c60e..cc887b38 100644 --- a/src/codemodder/project_analysis/file_parsers/pyproject_toml_file_parser.py +++ b/src/codemodder/project_analysis/file_parsers/pyproject_toml_file_parser.py @@ -28,6 +28,6 @@ def _parse_file(self, file: Path): return PackageStore( type=self.file_name, file=str(file), - dependencies=self._parse_dependencies_from_toml(data), + dependencies=set(self._parse_dependencies_from_toml(data)), py_versions=self._parse_py_versions(data), ) diff --git a/src/codemodder/project_analysis/file_parsers/requirements_txt_file_parser.py b/src/codemodder/project_analysis/file_parsers/requirements_txt_file_parser.py index 4fa69041..84cff6a7 100644 --- a/src/codemodder/project_analysis/file_parsers/requirements_txt_file_parser.py +++ b/src/codemodder/project_analysis/file_parsers/requirements_txt_file_parser.py @@ -15,7 +15,7 @@ def _parse_file(self, file: Path): return PackageStore( type=self.file_name, file=str(file), - dependencies=self._parse_dependencies(lines), + dependencies=set(self._parse_dependencies(lines)), # requirements.txt files do not declare py versions explicitly # though we could create a heuristic by analyzing each dependency # and extracting py versions from them. diff --git a/src/codemodder/project_analysis/file_parsers/setup_cfg_file_parser.py b/src/codemodder/project_analysis/file_parsers/setup_cfg_file_parser.py index 5f715681..99124dbd 100644 --- a/src/codemodder/project_analysis/file_parsers/setup_cfg_file_parser.py +++ b/src/codemodder/project_analysis/file_parsers/setup_cfg_file_parser.py @@ -32,6 +32,6 @@ def _parse_file(self, file: Path): return PackageStore( type=self.file_name, file=str(file), - dependencies=self._parse_dependencies_from_cfg(config), + dependencies=set(self._parse_dependencies_from_cfg(config)), py_versions=self._parse_py_versions(config), ) diff --git a/src/codemodder/project_analysis/file_parsers/setup_py_file_parser.py b/src/codemodder/project_analysis/file_parsers/setup_py_file_parser.py index f9c1df58..7569216d 100644 --- a/src/codemodder/project_analysis/file_parsers/setup_py_file_parser.py +++ b/src/codemodder/project_analysis/file_parsers/setup_py_file_parser.py @@ -41,7 +41,9 @@ def _parse_file(self, file: Path): return PackageStore( type=self.file_name, file=str(file), - dependencies=self._parse_dependencies_from_cst(visitor.install_requires), + dependencies=set( + self._parse_dependencies_from_cst(visitor.install_requires) + ), py_versions=self._parse_py_versions(visitor.python_requires), ) diff --git a/tests/dependency_management/test_dependency_manager.py b/tests/dependency_management/test_dependency_manager.py index ee24ac3d..ec6f4ded 100644 --- a/tests/dependency_management/test_dependency_manager.py +++ b/tests/dependency_management/test_dependency_manager.py @@ -15,7 +15,7 @@ def disable_write_dependencies(): class TestDependencyManager: def test_cant_write_unknown_store(self, tmpdir): store = PackageStore( - type="unknown", file="idk.txt", dependencies=[], py_versions=[] + type="unknown", file="idk.txt", dependencies=set(), py_versions=[] ) dm = DependencyManager(store, tmpdir) diff --git a/tests/dependency_management/test_requirements_txt_writer.py b/tests/dependency_management/test_requirements_txt_writer.py index 5bd6d9d2..9a376e76 100644 --- a/tests/dependency_management/test_requirements_txt_writer.py +++ b/tests/dependency_management/test_requirements_txt_writer.py @@ -21,7 +21,7 @@ def test_add_dependencies_preserve_comments(self, tmpdir, dry_run): store = PackageStore( type="requirements.txt", file=str(dependency_file), - dependencies=[], + dependencies=set(), py_versions=[], ) writer = RequirementsTxtWriter(store, Path(tmpdir)) @@ -69,7 +69,7 @@ def test_add_same_dependency_only_once(self, tmpdir): store = PackageStore( type="requirements.txt", file=str(dependency_file), - dependencies=[], + dependencies=set(), py_versions=[], ) writer = RequirementsTxtWriter(store, Path(tmpdir)) @@ -89,7 +89,7 @@ def test_dont_add_existing_dependency(self, tmpdir): store = PackageStore( type="requirements.txt", file=str(dependency_file), - dependencies=[Security.requirement], + dependencies=set([Security.requirement]), py_versions=[], ) writer = RequirementsTxtWriter(store, Path(tmpdir)) @@ -106,7 +106,7 @@ def test_dependency_file_no_terminating_newline(self, tmpdir): store = PackageStore( type="requirements.txt", file=str(dependency_file), - dependencies=[], + dependencies=set(), py_versions=[], ) writer = RequirementsTxtWriter(store, Path(tmpdir))