File: Parsed Source File#

class arch.code.File.File(*, sig='', doc=<factory>, code=<factory>, lang=Lang.PY, indent=0, annotations=<factory>, name='', args=<factory>, type='', path, head=<factory>, data=<factory>, body=<factory>, main=<factory>)#

Represents a parsed sourcecode file, very likely in Python or Typescript.

Done via string-parsing instead of direct reflection to
  1. Avoid import issues (especially for WIP code), and

  2. Support the parsing of non-python files by the python-based Nexus

classmethod new(path=None, **kwargs)#

Build a file model from a path, parsing its sections when the file exists.

render_section(section)#

Render the given section w/ header if it exists, and nothing if it’s empty.

property sections#

Return the non-empty sections of the file, keyed by name in canonical order.

parse_imports()#

Parse the import statements from the HEAD (or pre-HEAD code) section.

parse_methods()#

Parse methods from the main class when present, else from the raw code.

parse_element()#

Return the parsed architectonic element (main class/module) of this file, if any.

property module#

Return the parsed “main” class of this file, computed lazily and cached.

The main class shares the file’s name and is defined in the BODY section; None is returned (and cached) when no such class exists.

count_edges()#

Count this file’s internal architectonic imports, mapping each index to its count.

model_config = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context, /)#

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.