Imports: Import Statement Model#
- class arch.code.Imports.Imports(*, lang=Lang.PY, standard=<factory>, external=<factory>, internal=<factory>)#
The imports of a source file, split into standard, external, and internal sections.
- classmethod new(text='', lang=Lang.PY, **kwargs)#
Build an Imports model, parsing sectioned source text and/or keyword mappings.
- classmethod validate_lang(lang)#
Assert the language is one of the supported import syntaxes (PY or TS).
- classmethod setup()#
Load the class-level import shortcuts once.
- serialize()#
Render the import statements for this set of imports, grouped by section.
- Returns:
A mapping of section name to a list of valid source code lines.
- classmethod setup_shortcuts()#
Load the import path abbreviations, currently just TypeScript tsconfig paths.
- serialize_py(module, symset)#
Yield the Python import lines for a module and its imported symbols.
- serialize_ts(module, symset)#
Yield the TypeScript import lines for a module and its imported symbols.
- rename_internal(old, new)#
Move an internal import from one module path to another.
- normalize()#
Edit these imports in place, replacing long internal paths with dedicated shortcuts.
- universalize(origin)#
Modify the internal imports, changing relative imports to absolute ones.
- property shortcuts#
Return the registered path shortcuts for this language.
- property sections#
Return the (name, section) pairs in canonical order.
- copymask(variables, origin)#
Build a new Imports instance covering the given variable names with these imports.
Obviously, only imports used by this file can be copied. Aliased symbols and bare module imports are matched on either side of the alias.
- Parameters:
variables – The set of variable names to cover, e.g. “Buffer” or “ut”.
origin – The origin file or directory for relative imports, if applicable.
- Returns:
A new Imports instance holding just the imports needed to cover the variables.
- add_arch_import(target, *symbols, origin=None)#
Add an architectonic import to this file.
Opinionated defaults are applied if any args are not provided.
- Parameters:
target – The file or index to import from.
symbols – The symbols to import.
origin – [PY-ONLY] The origin file or directory for relative imports.
- count_edges(origin)#
Count the internal architectonic imports per index, universalizing paths first.
- model_config = {}#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].