Skip to content

plugins.aea-helpers.aea_helpers.check_dependencies

Check that project dependency files are consistent.

Validates that dependencies declared in packages/ match those in pyproject.toml (or Pipfile) and tox.ini. Supports both check-only and update modes.

PathArgument Objects

class PathArgument(click.Path)

Path parameter for CLI.

convert

def convert(value: Any, param: Optional[click.Parameter],
            ctx: Optional[click.Context]) -> Optional[Path]

Convert path string to pathlib.Path

PipfileConfig Objects

class PipfileConfig()

Class to represent Pipfile config.

__init__

def __init__(sources: List[str],
             packages: OrderedDictType[str, Dependency],
             dev_packages: OrderedDictType[str, Dependency],
             file: Path,
             exclude: Optional[List[str]] = None) -> None

Initialize object.

__iter__

def __iter__() -> Iterator[Dependency]

Iterate dependencies.

update

def update(dependency: Dependency) -> None

Update dependency specifier.

check

def check(dependency: Dependency) -> Tuple[Optional[str], int]

Check dependency specifier.

parse

@classmethod
def parse(
    cls, content: str
) -> Tuple[List[str], OrderedDictType[str, OrderedDictType[str, Dependency]]]

Parse from string.

compile

def compile() -> str

Compile to Pipfile string.

load

@classmethod
def load(cls,
         file: Path,
         exclude: Optional[List[str]] = None) -> "PipfileConfig"

Load from file.

dump

def dump() -> None

Write to Pipfile.

ToxConfig Objects

class ToxConfig()

Class to represent tox.ini file.

__init__

def __init__(dependencies: Dict[str, Dict[str, Any]],
             file: Path,
             exclude: Optional[List[str]] = None) -> None

Initialize object.

__iter__

def __iter__() -> Iterator[Dependency]

Iter dependencies.

update

def update(dependency: Dependency) -> None

Update dependency specifier.

check

def check(dependency: Dependency) -> Tuple[Optional[str], int]

Check dependency specifier.

parse

@classmethod
def parse(cls, content: str) -> Dict[str, Dict[str, Any]]

Parse file content.

load

@classmethod
def load(cls, file: Path, exclude: Optional[List[str]] = None) -> "ToxConfig"

Load tox.ini file.

write

def write() -> None

Dump config.

PyProjectTomlConfig Objects

class PyProjectTomlConfig()

Class to represent pyproject.toml file.

__init__

def __init__(dependencies: OrderedDictType[str, Dependency],
             config: Dict[str, Dict],
             file: Path,
             exclude: Optional[List[str]] = None,
             main_dep_names: Optional[Set[str]] = None,
             string_dep_names: Optional[Set[str]] = None,
             group_dep_names: Optional[Set[str]] = None) -> None

Initialize object.

__iter__

def __iter__() -> Iterator[Dependency]

Iterate dependencies.

update

def update(dependency: Dependency) -> None

Update dependency specifier.

check

def check(dependency: Dependency) -> Tuple[Optional[str], int]

Check dependency specifier.

load

@classmethod
def load(
        cls,
        pyproject_path: Path,
        exclude: Optional[List[str]] = None
) -> Optional["PyProjectTomlConfig"]

Load pyproject.toml dependencies.

Reads [tool.poetry.dependencies] plus every [tool.poetry.group.*.dependencies] table. Dict-form entries are treated as declared even when they omit the extras key (so optional = true deps are visible), and dev/test-only entries (e.g. pytest-asyncio in the dev group) no longer need to be duplicated into main deps to satisfy the check.

Group-origin entries enter self.dependencies for check() lookups but are excluded from __iter__ / dump() so that cross-validation against tox.ini and --update rewrites stay scoped to main runtime deps. See __init__ for the rationale.

A malformed/unreadable file is logged and propagated (the TOMLDecodeError / OSError is re-raised) so a corrupt pyproject fails the check rather than being silently treated as "no deps to verify".

Arguments:

  • pyproject_path: path to the pyproject.toml file.
  • exclude: package names to omit from iteration / check.

Returns:

a PyProjectTomlConfig instance, or None if the file has no [tool.poetry.dependencies] table (the except KeyError also triggers on a missing [tool] / [tool.poetry] parent).

dump

def dump() -> None

Dump to file (line-based, preserving comments and formatting).

Rewrites string-form main deps in place inside [tool.poetry.dependencies] and appends any newly-added deps (e.g. introduced by update() in --update mode, which adds package-/tox-discovered names not yet in pyproject) at the end of that table. Dict-form entries (docker = { version = "==7.1.0", optional = true }) carry metadata the name = version form can't represent, so they pass through verbatim — which also means an update() to a dict-form dep is not re-emitted (update() warns about that). Every other section, plus comments (including trailing in-line comments on rewritten lines), inline-table formatting and the original newline style, is left untouched.

load_packages_dependencies

def load_packages_dependencies(
        packages_dir: Path,
        exclude: Optional[List[str]] = None) -> List[Dependency]

Returns a list of package dependencies.

check_dependencies

@click.command(name="check-dependencies")
@click.option(
    "--check",
    "check_only",
    is_flag=True,
    help="Validate only, do not update files.",
)
@click.option(
    "--strict",
    is_flag=True,
    help="Enable full cross-validation between all dependency files.",
)
@click.option(
    "--exclude",
    multiple=True,
    help="Package names to exclude from checks (repeatable).",
)
@click.option(
    "--packages",
    "packages_dir",
    type=PathArgument(exists=True, file_okay=False, dir_okay=True),
    help="Path of the packages directory.",
)
@click.option(
    "--tox",
    "tox_path",
    type=PathArgument(exists=True, file_okay=True, dir_okay=False),
    help="tox.ini path.",
)
@click.option(
    "--pipfile",
    "pipfile_path",
    type=PathArgument(exists=True, file_okay=True, dir_okay=False),
    help="Pipfile path.",
)
@click.option(
    "--pyproject",
    "pyproject_path",
    type=PathArgument(exists=True, file_okay=True, dir_okay=False),
    help="pyproject.toml path.",
)
def check_dependencies(check_only: bool = False,
                       strict: bool = False,
                       exclude: tuple = (),
                       packages_dir: Optional[Path] = None,
                       tox_path: Optional[Path] = None,
                       pipfile_path: Optional[Path] = None,
                       pyproject_path: Optional[Path] = None) -> None

Check dependencies across packages, tox.ini, pyproject.toml and Pipfile.