Skip to content

validator: extend optional __init__.py rule to single-file integrations whose folder name collides with a PyPI package #39

@TheRealAgentK

Description

@TheRealAgentK

Problem

scripts/validate_integration.py currently treats __init__.py as required for "package-style" integrations and optional for "modular" integrations (those with an actions/ directory):

# validate_integration.py:119–124
# __init__.py is optional for modular integrations (those with an actions/...
if not (self.path / '__init__.py').exists() and not has_actions_dir:
    self.add_warning(
        "Missing __init__.py (required for package-style integrations, "
        "optional for modular integrations with actions/)"
    )

This rule misses a third legitimate case: single-file integrations whose folder name collides with a third-party PyPI package the integration imports.

Concrete example

The supadata integration imports the upstream SDK:

# supadata_transcribe.py
from supadata import Supadata, SupadataError

…and lives in a folder also called supadata/. With supadata/__init__.py present and the repo root on sys.path (the pytest default), Python's import resolution finds the empty integration package first and never reaches the real PyPI supadata library — every test fails with ImportError.

Two ways out:

  1. Keep __init__.py and work around the shadow with site.getsitepackages() + importlib.util.spec_from_file_location shims duplicated across every test file in the integration. That was the state of the PR before autohive-ai/autohive-integrations#280.
  2. Drop __init__.py and use clean imports. That's what we did, at the cost of a now-incorrect validator warning for supadata.

We chose (2) because it's structurally cleaner, but it leaves the validator emitting a warning that is technically wrong: supadata should not have an __init__.py — adding one would actively break it.

Proposal

Extend the "optional" exception to cover this case. Concretely, in _check_init_py / the missing-init check:

  • If <integration>/__init__.py is missing and at least one Python source file in the integration imports <integration> (e.g. from <integration> import … or import <integration>), treat it as a deliberate, optional omission and skip the warning.

That detection is a small AST walk over the integration's top-level .py files, looking for Import / ImportFrom nodes whose root module name matches the folder name.

Alternative (simpler but coarser): also exempt integrations whose requirements.txt lists a PyPI package whose distribution name matches the folder name. This avoids parsing imports at all and is good enough in practice — supadata requires supadata, and that's the signal.

Acceptance criteria

  • Running validate_integration.py supadata on the autohive-integrations master tree (after PR #280 merges) produces 0 warnings.
  • Existing single-file integrations that should have an __init__.py (the other 19 SDK 2.0 ones) still get the warning if it's removed.
  • A unit test in tests/ that covers the new exception (folder name == one of the requirements.txt entries → no warning when __init__.py missing).

Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions