Repository navigation
Closed
Labels
Description
Part of the Python (pytest) adapter: #61.
Build the file-level dependency graph for a Python project, so a change to app/models.py selects only the tests that import it directly or transitively.
Scope
- Parse
import x,import x.y as z,from x import yand relative imports (from . import y,from ..pkg import y), and resolve them to files in the repository (x/y.pyorx/y/__init__.py), for both flat andsrc/layouts. - Imports of packages outside the repository are ignored, not treated as errors.
- Importing a nested module also runs every parent package's
__init__.py(import pkg.sub.deeprunspkg/__init__.pyandpkg/sub/__init__.py), so add edges to each of those too. from pkg import nameloadspkg/name.pyonly whenpkg/__init__.pydoesn't already definename. Don't try to tell the cases apart: add edges topkg/__init__.pyand, if it exists, topkg/name.py.conftest.pyapplies to every test in its directory and below, so add edges from those tests to it.- Return
DependencyEdges withkind: "import"from the adapter'sanalyze().
Must fall back (blocker)
importlib.import_module,__import__, orsys.pathchanges in test or source files.- An import that looks local but can't be resolved.
- Namespace packages without
__init__.pywhen more than one root could match.
Done when
- Fixtures under
tests/repo/language-adapters.test.tscover a direct dependency, a transitive dependency, a change to a parent package's__init__.py,from pkg import namewherenameis a submodule, an unrelated change, aconftest.pychange, and a dynamic import that falls back.
Parsing approach: a careful line-based scan is fine for a first version if it handles multi-line from x import (a, b) and ignores imports inside strings. Say in the PR what it doesn't handle.
Safety rule: when the adapter is unsure, it adds a blockers entry so DiffCI runs the full suite. An empty graph must never look like "nothing affected".
New to DiffCI? Read the adapter guide and CONTRIBUTING.md. Sign off commits with git commit -s. Comment here to claim it, and ask questions on the issue at any point.
Activity
robertwmccarty-caelum commentedon Oct 30, 2026
Read-only, AI-assisted contribution for the human BuddyLists / Linked AIs operator (not an independently operated agent account). I tested a Python import-graph false-negative risk relevant to #56's selective-test safety rule.
An import of a nested module executes its ancestor package initializers. Resolving
import pkg.sub.deeponly topkg/sub/deep.pymisses executable code inpkg/__init__.pyandpkg/sub/__init__.py. A change to either initializer can affect tests importing the deep module, even if the deep module's bytes are unchanged.A second ambiguity:
from pkg import childmay resolvechildas an attribute already defined inpkg/__init__.py, without importingpkg/child.py, or it may import that submodule when the attribute is absent. A scanner that always maps this statement solely topkg/child.pyis unsound.Isolated reproduction: Python 3 standard-library
unittest+ temporary packages + fresh subprocesses; 5/5 passed:import pkg.subloadspkgandpkg.sub.import pkg.sub.deeploads all three package/module levels.from pkg import childloads the child module if the package doesn't define the attribute.pkg/__init__.pyalready defineschild = 42.pkg/__init__.pypreventsimport pkg.subfrom completing, proving the initializer is on the execution path.Suggested fixture assertions: create
pkg/__init__.py,pkg/sub/__init__.py,pkg/sub/deep.pyand a test importingpkg.sub.deep; changing either initializer must select that test. Forfrom pkg import child, conservatively include the package initializer and plausible local submodule, or mark ambiguous cases as blockers/full-suite fallback. If a namespace package makes ancestor resolution ambiguous, keep the existing blocker behavior.Reference: Python import-system documentation, especially parent packages and submodules: https://docs.python.org/3/reference/import.html#submodules .
These tests reproduce Python interpreter behavior only; I did not execute DiffCI's repository tests or validate its current adapter. No registration, product pitch, or production change.
adityankale190895 commentedon Oct 31, 2026
Thanks, both points are right. I've added them to the scope: an import now also adds edges to every parent package's
__init__.py, andfrom pkg import nameadds edges to bothpkg/__init__.pyandpkg/name.py(when it exists) instead of trying to work out which one Python loads. The fixture list now includes a parent-__init__.pychange and thefrom pkg import namecase.adityankale190895 commentedon Nov 7, 2026
Shipped in CLI 0.3.33 (Core 0fd9ed0) as part of the pytest adapter. Real-repository feedback is tracked in #75.