Skip to content

Import guard should exclude test files #131

@hbelmiro

Description

@hbelmiro

Problem

The import guard CI check (check_imports.py) currently runs against all .py files under components/ and pipelines/, including test files. The CI filter is:

filter: '^(components|pipelines)/.*\.py$'

Test files run locally via pytest, not inside KFP containers. The import guard's rationale (keeping top-level imports stdlib-only so KFP serialization and compilation work correctly) does not apply to them.

As a result, every third-party module used in tests (e.g., pandas, tests) must be manually whitelisted in import_exceptions.yaml under globs like components/**/tests/*. This adds friction for contributors and grows the exceptions file unnecessarily.

Proposed fix

Exclude test files from the import guard. Options (not mutually exclusive):

  1. CI filter: change the regex to skip test paths, e.g., '^(components|pipelines)/(?!.*tests/).*\.py$'
  2. Script-level: have check_imports.py skip files whose path contains /tests/

Either approach would allow removing the test-related entries from import_exceptions.yaml.

References

  • Workflow: .github/workflows/python-lint.yml (lines 65-78)
  • Script: .github/scripts/check_imports/check_imports.py
  • Config: .github/scripts/check_imports/import_exceptions.yaml

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions