solidity_parser.filesys

Attributes

ImportMapping

An import remapping for changing the source unit name before the import is resolved

Classes

Source

Structure of a source unit defined in the standard JSON input

StandardJsonInput

Solidity standard JSON input see:

LoadedSource

Source unit loaded inside the virtual filesystem

VirtualFileSystem

This is the "virtual file system" defined in the Solidity docs and implemented in solc. The idea is to abstract

Module Contents

class solidity_parser.filesys.Source

Structure of a source unit defined in the standard JSON input

urls: List[str] | None
content: str
class solidity_parser.filesys.StandardJsonInput

Solidity standard JSON input see: https://docs.soliditylang.org/en/v0.8.25/using-the-compiler.html#compiler-api

sources: Dict[str, Source]
class solidity_parser.filesys.LoadedSource

Source unit loaded inside the virtual filesystem

source_unit_name: str

The computed source unit name, see the solidity docs for how this is computed

contents: str

Source code

origin: pathlib.Path | None

Path to the source unit on disk, if it was loaded from disk

ast_creator_callback: Callable[[str], List[solidity_parser.ast.solnodes.SourceUnit]] | None

Optional function for changing the AST creation method, e.g. for testing and forcing the parser version

property ast: List[solidity_parser.ast.solnodes.SourceUnit]

Property for getting the AST from the source code lazily

solidity_parser.filesys.ImportMapping

An import remapping for changing the source unit name before the import is resolved

class solidity_parser.filesys.VirtualFileSystem(base_path: str | pathlib.Path, cwd: str | pathlib.Path = None, include_paths: List[str | pathlib.Path] = None, compiler_version: solidity_parser.util.version_util.Version = None)

This is the “virtual file system” defined in the Solidity docs and implemented in solc. The idea is to abstract away the specifics of how the sources are stored, such as on disk or in memory and the paths used in the source files to resolve imports. The code is not ideal but it emulates the behaviour of the c++ code of solc.

https://docs.soliditylang.org/en/v0.8.17/path-resolution.html

cwd
property base_path
property include_paths
import_remaps: List[ImportMapping] = []
sources: Dict[str, LoadedSource]
origin_sources: Dict[str, LoadedSource]
compiler_version
process_cli_input_file(file_path)
process_standard_json(path: str)
parse_import_remappings(remappings_file_path)
add_import_remapping(context, prefix, target)
lookup_import_path(import_path: str, importer_source_unit_name: str = None) LoadedSource
_add_loaded_source(source_unit_name: str, source_code: str, creator=None, origin=None) LoadedSource
_read_file(path: str, is_cli_path=True) str
_do_read_path(path: pathlib.Path) str
_cli_path_to_source_name(input_file_path) str

Computes the source name for a source file supplied via command line invocation of solc

_norm_vfs_path(path: str | pathlib.Path) str

Path normalisation according to solidity lang docs

_read_file_callback(su_name: str, base_dir: str, include_paths: List[str]) Tuple[str, str]
_remap_import(source_unit_name: str, importer_source_unit_name: str) list[str]

Takes a source unit name and checks if it should be remapped Note: do not pass an import path as the source unit name

_compute_possible_source_unit_names(path: str, importer_source_unit_name: str) list[str]

Computes a list of possible source unit names for an import path. Usually there is only 1, but if there are multiple matching import remappings, we have to test each one later on when the file lookup happens

static _path_to_generic_string(path: pathlib.Path | str) str
static _clean_path(*parts: List[str]) str
static _strip_prefix(prefix, path) pathlib.Path | None
static _remove_last_path_segment(path: str) str
static _is_relative_import(path: str) bool