From 312a7bada703506877da2a308198aa44aa8a84b5 Mon Sep 17 00:00:00 2001 From: angrybayblade Date: Thu, 5 Oct 2023 18:30:53 +0530 Subject: [PATCH] fix: ignore test directory when loading the packages --- aea/cli/check_packages.py | 38 +++++++++++--------------------------- aea/components/base.py | 4 +++- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/aea/cli/check_packages.py b/aea/cli/check_packages.py index ecaeb46070..a78d5141c3 100644 --- a/aea/cli/check_packages.py +++ b/aea/cli/check_packages.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # ------------------------------------------------------------------------------ # -# Copyright 2022-2023 Valory AG +# Copyright 2022 Valory AG # Copyright 2018-2021 Fetch.AI Limited # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -498,20 +498,12 @@ def get_third_part_imports_for_file(cls, pyfile: str) -> Generator: @classmethod @list_decorator def list_all_pyfiles_with_third_party_imports( - cls, - root_path: Union[str, Path], - pattern: str = "**/*.py", - check_tests: bool = False, + cls, root_path: Union[str, Path], pattern: str = "**/*.py" ) -> Generator: """Get list of all python sources with 3rd party modules imported.""" - im_files = ( - cls.list_all_pyfiles(root_path, pattern=pattern) - if check_tests - else cls.list_all_pyfiles( - root_path, pattern=pattern, ignores=IGNORE_PACKAGE_SUBFOLDERS - ) - ) - for pyfile in im_files: + for pyfile in cls.list_all_pyfiles( + root_path, pattern=pattern, ignores=IGNORE_PACKAGE_SUBFOLDERS + ): mods = list(cls.get_third_part_imports_for_file(root_path / pyfile)) if not mods: continue @@ -547,11 +539,10 @@ def get_dependencies(self) -> Dict[str, List[Path]]: result[dep] = DependenciesTool.get_package_files(dep) return result - def run(self, check_tests: bool = False) -> None: + def run(self) -> None: """Run dependency check.""" files_and_modules = ImportsTool.list_all_pyfiles_with_third_party_imports( - self.configuration_file.parent, - check_tests=check_tests, + self.configuration_file.parent ) package_dependencies = self.get_dependencies() third_party_imports = self.make_third_party_imports(files_and_modules) @@ -603,21 +594,15 @@ def _find_dependency_for_module( return missed_deps_for_imports, deps_not_imported_directly -def check_pypi_dependencies( - configuration_file: Path, - check_tests: bool = False, -) -> None: +def check_pypi_dependencies(configuration_file: Path) -> None: """Check PyPI dependencies of the AEA package.""" - PyPIDependenciesCheckTool(configuration_file).run(check_tests=check_tests) + PyPIDependenciesCheckTool(configuration_file).run() @click.command(name="check-packages") @click.option("--vendor", type=str, default=None, required=False) -@click.option("--check-tests", is_flag=True, help="Check test imports") @pass_ctx -def check_packages( - ctx: Context, vendor: Optional[str], check_tests: bool = False -) -> None: +def check_packages(ctx: Context, vendor: Optional[str]) -> None: """ Run different checks on AEA packages. @@ -627,7 +612,6 @@ def check_packages( :param ctx: AEA cli context. :param vendor: filter by author name - :param check_tests: Check test packages for imports """ packages_dir = Path(ctx.registry_path).absolute() all_packages_ids_ = find_all_packages_ids(packages_dir) @@ -641,7 +625,7 @@ def check_packages( check_dependencies(file, all_packages_ids_) check_description(file) check_public_id(file) - check_pypi_dependencies(file, check_tests=check_tests) + check_pypi_dependencies(file) except CustomException as exception: exception.print_error() failed = True diff --git a/aea/components/base.py b/aea/components/base.py index db51307a03..50867cf4a9 100644 --- a/aea/components/base.py +++ b/aea/components/base.py @@ -350,8 +350,10 @@ def perform_load_aea_package( ) prefix_pkg = prefix_pkg_type + f".{package_name}" - for subpackage_init_file in dir_.rglob("__init__.py"): + if subpackage_init_file.parent.name == "tests": + continue + parent_dir = subpackage_init_file.parent relative_parent_dir = parent_dir.relative_to(dir_) if relative_parent_dir == Path("."):