pygalgen.generator.common.source_file_parsing package

Subpackage containing functions used for parameter extraction from source files

Submodules

pygalgen.generator.common.source_file_parsing.local_module_parsing module

Module responsible for resolving assignments and constant list comprehensives used in argument parser

class pygalgen.generator.common.source_file_parsing.local_module_parsing.UnknownNamesRemoval(unknown: set[str])[source]

Bases: NodeVisitor

Removes unknown names that can’t be resolved and replaces them with a constant string that can be detected by linter

Attributes — unknown: Set[str]

set of names that represent variables used in parser initialization, that have not been resolved yet

visit_ClassDef(node: ClassDef) Any[source]
visit_Name(node: Name) Any[source]
pygalgen.generator.common.source_file_parsing.local_module_parsing.handle_local_module_names(actions: List[AST], unknown_names: set[str]) Module[source]

Function used to remove assignments and list comprehensions which can’t be resolved

Parameters

actionsList[ast.AST]

list of actions extracted so far

unknown_names :

set of unknown names that have to be extracted

Returns

Python module containing assignments and list comprehensions whose values are based on constants

pygalgen.generator.common.source_file_parsing.parser_discovery_and_init module

Module responsible for discovery of import statements importing Argument parser and discovery of the statements initializing the parser itself

class pygalgen.generator.common.source_file_parsing.parser_discovery_and_init.ArgumentCreationDiscovery(actions: List[AST], main_name: str, groups: Set[str])[source]

Bases: Discovery

Class responsible for extraction of statements which initialize the input arguments. It is able to extract function calls on the original parser, and on the argument groups extracted by GroupDiscovery

is_call_on_parser_or_group(node: Call)[source]
report_findings() List[AST][source]
visit_Call(node: Call) Any[source]
class pygalgen.generator.common.source_file_parsing.parser_discovery_and_init.GroupDiscovery(actions: List[AST], main_name: str)[source]

Bases: Discovery

Class responsible for discovery of statements that initialize argument groups

report_findings() Tuple[source]
visit_Assign(node: Assign)[source]
class pygalgen.generator.common.source_file_parsing.parser_discovery_and_init.ImportDiscovery(actions: List[AST])[source]

Bases: Discovery

Class responsible for discovery and extraction of import statements

report_findings() Tuple[List[AST], str, str, Set[str]][source]
visit_Import(node: Import) Any[source]
visit_ImportFrom(node: ImportFrom) Any[source]
class pygalgen.generator.common.source_file_parsing.parser_discovery_and_init.SimpleParserDiscoveryAndReplacement(actions: List[AST], argparse_alias: str | None, argument_parser_alias: str | None, custom_parser_def: ClassDef)[source]

Bases: Discovery

Class responsible for discovery of ArgumentParser creation and assignment, and replacement of the class definition

by the one supplied through constructor

static imported_using_from(node: Assign, argument_parser_alias: str)[source]
static imported_using_import(node: Assign, argparse_module_alias: str)[source]
static is_simple_assignment(node: Assign)[source]
report_findings() Tuple[source]
visit_Assign(node: Assign)[source]
pygalgen.generator.common.source_file_parsing.parser_discovery_and_init.get_parser_init_and_actions(source: Module) Tuple[List[AST], str, Set[str], Set[str]][source]
Function used to extract necessary imports, parser and argument creation

function calls

Parameters

sourceast.Module

source file parsed into ATT

Returns

List of extracted AST nodes, the main name of the parser and a set of section names

pygalgen.generator.common.source_file_parsing.parser_discovery_and_init.is_this_group_creation(node: Assign)[source]

pygalgen.generator.common.source_file_parsing.parsing_commons module

Module containing the parent class of Dicovery classes

class pygalgen.generator.common.source_file_parsing.parsing_commons.CustomVisitor[source]

Bases: NodeVisitor, ABC

abstract report_findings() Tuple[source]
visit_and_report(source: AST)[source]
class pygalgen.generator.common.source_file_parsing.parsing_commons.Discovery(actions: List[AST])[source]

Bases: CustomVisitor, ABC

pygalgen.generator.common.source_file_parsing.parsing_commons.add_parents(tree: AST)[source]
pygalgen.generator.common.source_file_parsing.parsing_commons.create_module_tree_from_path(path: str) Module[source]
pygalgen.generator.common.source_file_parsing.parsing_commons.create_module_tree_from_str(text: str) Module[source]

pygalgen.generator.common.source_file_parsing.parsing_exceptions module

Module containing Exceptions that can be raised during param discovery

exception pygalgen.generator.common.source_file_parsing.parsing_exceptions.ArgParseImportNotFound[source]

Bases: ArgumentParsingDiscoveryError

Exception raised in case ArgParser was not imported

exception pygalgen.generator.common.source_file_parsing.parsing_exceptions.ArgParserNotUsed[source]

Bases: ArgumentParsingDiscoveryError

Exception raised in case no uses of argument parser were found

exception pygalgen.generator.common.source_file_parsing.parsing_exceptions.ArgumentParsingDiscoveryError[source]

Bases: Exception

Exception for general error encountered during param extraction

pygalgen.generator.common.source_file_parsing.unknown_names_discovery module

Module containing discovery classes used to find names (assignments to variables) that have not been extracted yet

class pygalgen.generator.common.source_file_parsing.unknown_names_discovery.UnknownNameInit(unknown_names: Set[str])[source]

Bases: CustomVisitor

Class used to initialize unknown names

report_findings() Tuple[source]
visit_Assign(node: Assign) Any[source]
visit_ClassDef(node: ClassDef) Any[source]
class pygalgen.generator.common.source_file_parsing.unknown_names_discovery.UnknownNamesDiscovery(known_names: Set[str])[source]

Bases: CustomVisitor

Discovery class used to find names that have not been initialized yet but are necessary for correct argument parser init

report_findings() Tuple[source]
visit_ListComp(node: ListComp) Any[source]
visit_Name(node: Name) Any[source]
pygalgen.generator.common.source_file_parsing.unknown_names_discovery.initialize_variables_in_module(original_module: Module, parser_name: str, sections: Set[str], actions: List[AST], imported_names: Set[str]) Tuple[List[AST], Set[str]][source]

Function used to initialize variables that have constant values

Parameters

original_moduleast.Module

AST of the original source file

parser_namestr

default name of the parser

sectionsSet[str]

set of section names

actionsList[ast.AST]

list of actions extracted so far

imported_namesSet[str]

list of names imported from modules

Returns

List containing newly extracted actions and new unknown names