Skip to content

Commit

Permalink
fix: ignore test directory when loading the packages
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade committed Oct 5, 2023
1 parent 5f82281 commit 312a7ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
38 changes: 11 additions & 27 deletions aea/cli/check_packages.py
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion aea/components/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("."):
Expand Down

0 comments on commit 312a7ba

Please sign in to comment.