Python Reader and Plain Profile v0.4
intentset/python/0.4 · revision 2026-12-02 · implemented by 0.18.0 · Rendered from spec/profile-python-0.4.md in the repository.
Implements Traceable VSA under the profile contract, and follows Core §1's change policy. This document says how intentset architecture check reads a Python codebase, what it follows, and what it reports as not checked. The profile it specifies is intentset/python/1, whose version is its own (profile contract §8): this document's id carries the specifications' version, and the profile's does not. The decision is ADR 0030.
1. What the reader is, and is not
The python reader is a scanner. It reads the text of .py files and of pyproject.toml, and it runs nothing: no interpreter, no pip, no build tool. setup.py is code, so it is not read.
It is not a Python parser and not an import system. It reads the statements that say what a module depends on and passes over everything else. Where the language decides something only when a program runs, the reader says so and reports the reference as not checked (§6). A checker MUST NOT report such a reference as passing (VSA §2).
The rules of Traceable VSA run on what it returns, with no rule of their own for Python: VSA003 to VSA006, VSA009, VSA015, VSA016 and REG001 judge a Python tree as they judge any other. The reader owns two codes, PY001 and PY002 (§6). None of the typescript reader's rules runs under it.
2. The plain profile
intentset/python/1 names four layers, by the names Python projects commonly give them, and runs no rule set:
| Key | Value |
|---|---|
language |
python |
layers |
api, services, domain, adapters |
roles |
seam: adapters, pure: [domain], no rendering layer |
layerMatrix |
api → services, domain; services → domain, adapters; domain → nothing else; adapters → domain |
layerFolders |
each layer's folder is its name |
sourceRoots |
src/** |
composition |
src/*/__init__.py, src/*/__main__.py, src/*/main.py, src/*/app.py |
shared, infrastructure |
src/*/shared/**, src/*/infrastructure/** |
tests |
tests/**, **/tests/**, **/test_*.py, **/*_test.py, **/conftest.py |
ignore |
__pycache__, .venv, venv, build, dist, node_modules and .git, at any depth |
api is what the outside calls: routes, handlers, commands. services orchestrate. domain holds rules and models and imports nothing but itself. adapters is the seam: the one layer that reaches a database or an outside service. The layout is the src layout, one distribution package under src/, whose own __init__.py and entry modules are composition.
It lists no outsidePackages and no forbiddenPackages: a team names them, and until it does VSA015 and VSA016 judge nothing. A team's profile extends this one and states what differs (profile contract §4).
A slice's entrypoint is a file, as in every profile; in Python it is usually the __init__.py of the slice's package. A file's package (VSA §3) is the nearest directory above it that holds a pyproject.toml.
3. What the reader reads in a file
The reader takes a file apart into tokens: names, numbers, operators and strings. A string of any prefix (r, b, u, f, t and their pairs), single or triple quoted, is one token, and a comment is dropped: text inside a string, a docstring or a comment is never read as a statement. Inside an f-string the reader follows each replacement field, with its brackets and its own nested strings, so that a quote inside one does not end the string.
Lines are joined as Python joins them: inside brackets, and after a backslash at the end of a line. Statements on one line are separated at ;, and a statement after a block's colon on the same line is read (if x: import y).
It reads these statements:
| Statement | What it is read as |
|---|---|
import a.b.c, import a.b as c, several separated by commas |
A reference to each module, taking the whole module |
from a.b import c, d as e, with the names in brackets or not |
A reference to a.b taking each name; a name that is a module under a.b and that a.b does not itself define is a reference to that module (§4) |
from . import x, from ..pkg import y |
The same, from the importing file's package or one above it |
from m import * |
A reference taking every name m has at module level; at module level it also passes those names on, as a re-export does |
Where a statement is decides two things:
- Type-only. An import inside
if TYPE_CHECKING:orif <name>.TYPE_CHECKING:is type-only. One in theelseof that block, or under any other test, is not. Type-only imports count for every rule that counts them (VSA §5). - Local. An import inside a function or a class body is a reference like any other, and binds no name of the module. An import inside
try,except,if,with,fororwhileat module level binds a module-level name.
For each module the reader lists the names it defines at module level (functions, classes and assigned names) and the names its module-level imports bind, which Python passes on to whoever imports them from it. That list is what lets VSA006 judge a name by the layer of the file that defines it, however many __init__.py files pass it on. Where a module assigns __all__ anything but a list or tuple of plain strings, or defines a module-level __getattr__, the names a star import takes from it cannot be listed (§6).
4. Where a module is found
A reference resolves to a file of the tree, or it names a package outside the tree.
Source roots. An absolute module path is looked for under each source root in turn. The roots are, in order:
- what each
pyproject.tomlstates, relative to its own directory:- setuptools:
[tool.setuptools.package-dir]with the key"";whereunder[tool.setuptools.packages.find]; and the project's own directory where that table has nowhere, or wherepackagesis a list; - Poetry:
fromof each entry ofpackagesunder[tool.poetry](an entry with nofromgives the directory itself); - Hatch: the directory above each entry of
packages, and each entry ofsources, under[tool.hatch.build.targets.wheel]andsdist, andpackagesunder[tool.hatch.build]; - PDM:
package-dirunder[tool.pdm.build]or[tool.pdm];
- setuptools:
- for a
pyproject.tomlthat states none, itssrcdirectory, when that holds Python: thesrclayout; - where no
pyproject.tomlgives a root, the directory each of the profile'ssourceRootspatterns names before its first wildcard, or, where that directory is itself a package, the directory the package is under. A pattern that opens with a wildcard names none; - as guesses, tried last: each
pyproject.toml's own directory, for the files under it, and the repository's root.
A module is looked for by its whole path under each root in turn, and the first root that holds a file for it is the one. A root of the fourth kind is stated nowhere, so a reference found under one is reported as PY002 (§6), once for each such directory: the reference is resolved and judged, and the check says the root was a guess.
pyproject.toml is read with a reader of the part of TOML these tables use. A file it cannot read is noted as not read, with the line, and gives no root. A setup.py or setup.cfg in a project whose pyproject.toml gives no root is noted too, since a root it states is unknown.
Modules and packages. Under a root, a.b is a/b.py, or the package a/b/__init__.py. A directory with no __init__.py is a namespace package: module paths resolve through it, and a reference to the namespace package itself is a reference to no file.
Outside the tree. A module path that no root holds names a package outside the tree: the standard library, or something installed. That is so even where the path's first name is in the tree, since two distributions may share one top-level name, as the parts of a namespace package do. It is matched against outsidePackages, forbiddenPackages and backendSdks as a path, so the pattern sqlalchemy/** matches sqlalchemy and sqlalchemy.orm.
Relative imports. Each leading dot after the first climbs one directory from the importing file's own.
5. Conformance fixtures
The cases are in tests/vsa.json, named PYTHON … and PY…, over a small src-layout tree under a profile that extends this one. They cover each portable rule firing on Python code; each import form of §3, with the strings and comments that are not imports; each way of finding a root in §4, with a guessed root and a package under a directory nothing states; a namespace package; and each form of §6.
6. What is not checked
Each of these is PY001, a warning, and is listed in the check's summary as not checked. The reader returns none of them as an edge it has guessed. What to do about each is the same: write a literal import that names a file of the repository or a package.
| What | Why |
|---|---|
importlib.import_module(...) and __import__(...), whatever their argument |
The module is named by a value. A literal argument is not followed either: the call's package argument and the program's state decide what it means |
| A relative import that names no file | A relative import cannot lead outside the tree |
| A relative import that climbs past the top of the tree | There is nothing there |
A star import of a module whose __all__ is computed or which defines __getattr__ |
The names it takes cannot be listed, so the layer of what defines them cannot be judged |
A statement that begins import or from and cannot be read as one |
The file may not be valid Python |
PY002, a warning, is about where modules were looked for, and what to do about it is to state the source roots, in pyproject.toml or in sourceRoots in the profile or .intentset/architecture.yaml. It is reported once for each directory, and listed as not checked:
| What | Why |
|---|---|
References found under a guessed root: a pyproject.toml's own directory or the repository's root, where nothing states it |
The references are resolved and judged, and the root they were found under was a guess |
| References read as packages outside the tree, where a package or module of that name is at the top of a directory that is no source root and no package | The dependency was probably the tree's own, and was not seen. A name of the standard library, and a name some root already holds, are never reported this way |
These limits are not errors of a repository, and the reader does not report them one by one:
sys.path,.pthfiles,PYTHONPATH,conftest.pypath changes and import hooks are the running program's, and are not read.- Other build backends' settings, such as Flit's module name, are not read. The
srclayout and the profile'ssourceRootsstill apply, and a guessed root is reported. setup.pyandsetup.cfgare not read, and are noted where they may state a root.- Conditional imports are all read. Both branches of
try/except ImportErrorand of a version test are references. - A star import is taken as every module-level name of its target, which is more than a literal
__all__allows it. A layer may be judged for a name the star does not in fact take. - A name that is both a module under a package and assigned in that package's
__init__.pyis taken as the package's, as Python takes it once the package is imported. - Attribute access is not followed. After
import a, the use ofa.b.cis not a reference toa/b/c.py. - Stub files (
.pyi), Cython and extension modules are not read. - Code that runs an import from a string,
execandeval, is not seen.