### Rule Structure Example Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks This example demonstrates the general structure of a rule in PyTestArch's query language: RULE_SUBJECT - VERB_MARKER_1 - IMPORT_TYPE - VERB_MARKER_2 - RULE_OBJECT. ```text RULE_SUBJECT - VERB_MARKER_1 - IMPORT_TYPE - VERB_MARKER_2 - RULE_OBJECT ``` -------------------------------- ### Alternative Rule Formulation Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks This example shows an equivalent rule formulation without regex negations, using `have_name_matching` for both subject and object. ```python Rule().modules_that().have_name_matching(".*test$").should_not().be_imported_by_modules_that().have_name_matching(".*test$") ``` -------------------------------- ### Batch Rule Subjects Example Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Specify multiple rule subjects using a list with `are_named()` to apply the rule independently to each module in the list. ```python modules_that() \ .are_named(["1", "2"]) \ .should_only() \ .be_imported_by_modules_that() \ .are_named(["3", "4"]) ``` -------------------------------- ### Module Dependency Rule (Insufficient for Layers) Source: https://zyskarch.github.io/pytestarch/latest/features/layer_architecture_checks This example shows a module dependency rule that is insufficient for specifying layer-wide import behavior. It requires specific modules (M and N) to import a specific module (O), rather than defining a general layer-to-layer dependency. ```python Rule() \ .modules_that() \ .are_named(["M", "N"]) \ .should() \ .import_modules_that() \ .are_named("O") ``` -------------------------------- ### NetworkxGraph.__init__ Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure Initializes the NetworkxGraph, constructing the evaluable structure from a list of imports. ```APIDOC ## NetworkxGraph.__init__ ### Description Constructs eval_structure from list of imports. Each module passed to this object will be added as a node. Importing and imported module are connected via a direct edge. Edges are added between each successive level in the module hierarchy. ### Parameters #### Path Parameters - **all_modules** (list[Node]) - Required - list of all nodes in the graph, which can be connected by imports. - **imports** (Sequence[Import]) - Required - all dependencies between the graph's nodes. - **level_limit** (int | None) - Optional - if not None, specifies the depth of the graph. Defaults to None. ### Example Import('A.B', 'C.D.E') results in - nodes: ['A', 'A.B', 'C', 'C.D', 'C.D.E'] - edges: [('A', 'A.B'), ('C', 'C.D'), ('C.D', 'C.D.E'), ('A.B', 'C.D.E')] ``` -------------------------------- ### Create Evaluable Architecture Representation Source: https://zyskarch.github.io/pytestarch/latest Scans Python files to build an internal representation for architectural rule checks. The first parameter helps differentiate internal and external dependencies. ```python from pytestarch import get_evaluable_architecture evaluable = get_evaluable_architecture("/home/dummy/project", "/home/dummy/project/src") ``` -------------------------------- ### ExternalImportFilter.__init__ Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure_generation Initializes the ExternalImportFilter to filter imports based on external module configurations. ```APIDOC ## ExternalImportFilter.__init__ ### Description Filters out imports of (some) external modules from the list of all imports. External modules are all modules that are not submodules of the configured module to search for imports. ### Method `__init__(exclude_external_libraries, root_module_name, external_exclusions)` ### Parameters #### Parameters - **exclude_external_libraries** (bool) - Required - If True, external modules will be filtered out, otherwise this class implements a no-op. - **root_module_name** (str) - Required - The name of the module that determines which modules are considered external. If a module is a submodule of this module, it is considered internal. - **external_exclusions** (tuple[str, ...]) - Required - Regex pattern: all external modules that match it shall be filtered out. ``` -------------------------------- ### Import Type Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure Provides methods to inspect import details within a module. ```APIDOC ## Import ### importee() #### Description Returns the name of the module that is being imported. #### Returns - **str** - The name of the imported module. ### importee_parent_modules() #### Description Returns the names of all parent modules of the imported module. #### Returns - **list[str]** - A list of module names representing the parent modules. ### importer() #### Description Returns the name of the module that is performing the import. #### Returns - **str** - The name of the importing module. ### importer_parent_modules() #### Description Returns the names of all parent modules of the importing module. #### Returns - **list[str]** - A list of module names representing the parent modules of the importer. ``` -------------------------------- ### LayerMapping Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure Provides functionality to map modules to their respective layers. ```APIDOC ## LayerMapping ### `get_layer_for_module_name(module_name)` Attempts to find the layer the given module belongs to. If the module does not appear in the layer definition itself, it is checked whether the module is a submodule of one of the modules in the layer definition. If so, the layer of the parent module is returned. Otherwise, None is returned. This assumes that if a module is in layer X, all of its submodules are as well. **Parameters**: - `module_name` (str) - Required - The name of the module to find the layer for. **Returns**: - `str` or `None` - The name of the layer the module belongs to, or None if not found. ``` -------------------------------- ### Parser.parse Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure_generation Parses all Python files in a given path and returns a list of AST modules. ```APIDOC ## Parser.parse ### Description Reads all python files in the given path and returns list of ast modules with names. ### Method `parse(path)` ### Parameters #### Parameters - **path** (Path) - Required - Either to a file or to a directory. ### Returns - **list of python modules, one per python file** (list[Module]) - A list containing AST module objects for each Python file found. ``` -------------------------------- ### VERB_MARKER_1: should() Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Use `should()` to indicate a required import relationship. ```python should() ``` -------------------------------- ### ModuleNameConverter.convert Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure Converts module names specified via regex pattern to actual module names based on matching modules in the architecture. ```APIDOC ## ModuleNameConverter.convert ### Description Converts each regex pattern that serves to identify module names into actual modules that match this pattern. ### Method classmethod ### Parameters #### Path Parameters - **modules** (list[Module]) - Required - list of modules, some of which may need converting since their names are regex patterns - **arch** (architecture) - Required - architecture that contains actual modules ### Response #### Success Response (200) - **Sequence[ModuleFilter]** - list of module filters, now without any regex patterns. Will be used for later dependency graph queries. - **dict[str, list[Module]]** - mapping between a regex pattern and the actual modules it was replaced by ``` -------------------------------- ### Evaluate Code Against Rule Source: https://zyskarch.github.io/pytestarch/latest Asserts that the defined architectural rule applies to the evaluable representation of the code. This is the final step in testing architectural compliance. ```python rule.assert_applies(evaluable) ``` -------------------------------- ### PumlParser Source: https://zyskarch.github.io/pytestarch/latest/references/diagram_extension Parses PlantUML (.puml) files into a dependency object that can be used to generate architecture rules. ```APIDOC ## Class: PumlParser ### Description Parses .puml files to a dependencies object that can be used to generate architecture rules. ### Syntactical Requirements for .puml files * Start of dependency definition needs to be tagged with `@startuml` * End of dependency definition needs to be tagged with `@enduml` * All text outside these tags is ignored * Component names must be enclosed in square brackets * Exception: if a component as been given an alias via `[module name] as alias`, then the alias should not be wrapped in square brackets * Dependencies must be with either `-->`, `->`, `<--`, `<-`, `-text->`, or `<-text-`. The dependee is to be placed on the side of the arrow head, the dependor on the opposite side. ### Methods #### `parse(file_path)` ##### Parameters - **file_path**: Path to the .puml file to parse. ##### Returns - **ParsedDependencies**: Dependencies object that can be used to generate architecture rules. ``` -------------------------------- ### get_evaluable_architecture_for_module_objects Source: https://zyskarch.github.io/pytestarch/latest/references/general Provides the same functionality as `get_evaluable_architecture` but accepts module objects directly instead of string paths. ```APIDOC ## get_evaluable_architecture_for_module_objects ### Description Same functionality as get_evaluable_architecture, but root module and module to evaluate are passed in as module objects instead of the absolute paths to them. ### Parameters #### Path Parameters - **root_module** (module) - Required - The root module object. - **module** (module) - Required - The module object to evaluate. #### Query Parameters - **exclusions** (tuple[str, ...]) - Optional - pseudo-regex to exclude files and directories. Default: DEFAULT_EXCLUSIONS - **exclude_external_libraries** (bool) - Optional - if True, external dependencies will not be taken into account. Default: True - **level_limit** (int | None) - Optional - if not None, specifies the depth of the graph. Default: None - **regex_exclusions** (tuple[str, ...] | None) - Optional - Proper regex version of 'exclusions'. Default: None - **external_exclusions** (tuple[str, ...] | None) - Optional - pseudo-regex version of 'external_exclusions'. Default: None - **regex_external_exclusions** (tuple[str, ...] | None) - Optional - Proper regex version of 'external_exclusions'. Default: None ### Request Example ```python import your_module from pytestarch.example_module import get_evaluable_architecture_for_module_objects arch = get_evaluable_architecture_for_module_objects(root_module=your_module, module=your_module.submodule) ``` ### Response #### Success Response (evaluable_architecture_object) - An evaluable architecture object that can be used to define and check architectural rules. ``` -------------------------------- ### ImporteeModuleCalculator.calculate_importee_modules Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure_generation Calculates and adds parent modules of imported modules to a list of all modules. ```APIDOC ## ImporteeModuleCalculator.calculate_importee_modules ### Description For all imported modules: Calculate parent modules and add them to the list of existing modules if they are not already part of this list. This mainly applies to external dependencies. ### Method `calculate_importee_modules(imports, all_modules)` ### Parameters #### Parameters - **imports** (Sequence[Import]) - Required - List of imports to process. - **all_modules** (list[str]) - Required - The initial list of all modules. ### Returns - **all modules extended by parent modules of imported modules** (list[str]) - The updated list of modules including parent modules of imported ones. ``` -------------------------------- ### Regex Negation Warning Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Avoid negations in regex for `have_name_matching` as they can lead to unexpected rule evaluations due to how PyTestArch considers submodules. Consider alternative rule formulations without negations. ```python Rule().modules_that().have_name_matching(r"^((?!test$).)*$").should_not().import_modules_that().have_name_matching(r".*test$") ``` -------------------------------- ### EvaluableArchitecture Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure Abstract interface for evaluable objects, providing methods to inspect module dependencies and visualize the architecture. ```APIDOC ## EvaluableArchitecture Abstract interface of evaluable objects. ### `modules: list[str]` `property` Return names of all modules that are present in this architecture. ### `any_dependencies_from_dependents_to_modules_other_than_dependent_upons(dependents, dependent_upons)` Returns list of depending modules per dependent module if the dependent module has any dependency to a module other than the dependent_upon modules or any of their submodules. If a dependent module is defined via a parent module, this parent module is not taken into account. If a dependent upon module is defined via a parent module, this parent module counts as an 'other' dependency. Reason behind this: If we want to know whether there are any dependencies from X to any non-Y modules, Y's parent is such a module, as this parent module can and usually will also contain other modules than Y. **Parameters**: - `dependent` (Module) - Required - - `dependent_upon` (Module) - Required - **Returns**: - `NotExplicitlyRequestedDependenciesByBaseModule` - All modules other than dependent_upon on which dependent module as any dependency per dependent module ### `any_other_dependencies_on_dependent_upons_than_from_dependents(dependents, dependent_upons)` Returns list of depending modules per dependent_upon module if any module other than the dependent module and its submodules has any dependency to the dependent_upon module. If the dependent module is defined via a parent module, this parent module is taken into account. This means that if the dependent module's parent module has a dependency to the dependent upon module, this will be contained in the returned list. If the dependent upon module is defined via a parent module, this parent module is not taken into account. **Parameters**: - `dependent` (Module) - Required - - `dependent_upon` (Module) - Required - **Returns**: - `NotExplicitlyRequestedDependenciesByBaseModule` - All modules other than dependent that have any dependency on the dependent upon module per dependent_upon module ### `get_dependencies(dependents, dependent_upons)` Returns tuple of importer and importee per dependent and depending module if the dependent module is indeed depending on the dependent_upon module. In short: find all dependencies between dependent and dependent_upons. Submodules of dependent and dependent upon are taken into account. If X.A depends on Y, then X also depends on Y, as X.A is part of X. If X depends on Y.Z, then it also depends on Y. If one or both of the modules are defined by their parent module, this parent module is excluded from possible matches. **Parameters**: - `dependent` (Module(s)) - Required - - `dependent_upon` (Module(s)) - Required - **Returns**: - `ExplicitlyRequestedDependenciesByBaseModules` - Importer and importee per pair of dependent and dependent_upon module if there are any - `ExplicitlyRequestedDependenciesByBaseModules` - that are sub modules of dependent and dependent_upon respectively. ### `visualize(**kwargs)` Uses matplotlib to create a visual representation of the dependency structure. **Parameters**: - `**kwargs` (Any) - Any formatting options available for networkx' drawing function, as this is currently the only available backend. Exception: If 'spacing' is set, this will be interpreted as the parameter 'k' of the spring layout (https://networkx.org/documentation/stable/reference/generated/networkx.drawing.layout.spring_layout.html#networkx.drawing.layout.spring_layout). - Optional - Default: `{}` ``` -------------------------------- ### RULE_SUBJECT: are_named() Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Use `are_named("X")` to apply a rule to a module named 'X' and its submodules. ```python are_named("X") ``` -------------------------------- ### get_evaluable_architecture Source: https://zyskarch.github.io/pytestarch/latest/references/general Constructs an evaluable object based on the given module path. This is a primary entry point for PyTestArch to analyze code architecture. ```APIDOC ## get_evaluable_architecture ### Description Constructs an evaluable object based on the given module. ### Parameters #### Path Parameters - **root_path** (str) - Required - root directory of the source code. Should not be set to a submodule of the top level module. - **module_path** (str) - Required - path of module to generate the evaluable for. Must be a submodule of the root_path module. #### Query Parameters - **exclusions** (tuple[str, ...]) - Optional - pseudo-regex to exclude files and directories from being integrated into the evaluable, e.g. *Test.py. Can only be specified if regex_exclusions is not specified. Default: DEFAULT_EXCLUSIONS - **exclude_external_libraries** (bool) - Optional - if True, external dependencies will not be taken into account. Default: True - **level_limit** (int | None) - Optional - if not None, specifies the depth of the graph. Default: None - **regex_exclusions** (tuple[str, ...] | None) - Optional - Proper regex version of 'exclusions'. Can only be specified if regex_exclusions is not specified. Default: None - **external_exclusions** (tuple[str, ...] | None) - Optional - pseudo-regex version of 'external_exclusions' to exclude certain external dependencies. Can only be specified if exclude_external_libraries is False and regex_external_exclusions is not specified. Default: None - **regex_external_exclusions** (tuple[str, ...] | None) - Optional - Proper regex version of 'external_exclusions' to exclude certain external dependencies. Can only be specified if exclude_external_libraries is False and external_exclusions is not specified. Default: None ### Request Example ```python from pytestarch.example_module import get_evaluable_architecture arch = get_evaluable_architecture(root_path="/path/to/your/project", module_path="your_module") ``` ### Response #### Success Response (evaluable_architecture_object) - An evaluable architecture object that can be used to define and check architectural rules. ``` -------------------------------- ### RULE_SUBJECT: have_name_matching() Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Use `have_name_matching(regex)` to apply a rule to modules whose names match the given regular expression. Ensure the regex primarily matches the target module, not its submodules, to optimize runtime. ```python have_name_matching(regex) ``` -------------------------------- ### DiagramRule Source: https://zyskarch.github.io/pytestarch/latest/references/diagram_extension Represents a set of architectural rules derived from a diagram file. It reads the diagram, generates rules, and aggregates test results. By default, it creates 'should only import' rules for connected modules and 'should not import' rules for unconnected modules. ```APIDOC ## Class: DiagramRule ### Description Represents a set of architectural rules as defined in a diagram file. Reads the specified file, generates architectural rules, and returns an aggregated test result. By default, "should only import" rules will be generated for modules that the diagram shows as connected. "Should not import" rules will be generated for modules that are not connected in the diagram. ### Methods #### `__init__(should_only_rule=True)` ##### Parameters - **should_only_rule** (bool) - Optional - if True, edges between components will be converted into 'should only import' rules. Defaults to True. ``` -------------------------------- ### VERB_MARKER_1: should_not() Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Use `should_not()` to enforce that a module should not have a certain type of import relationship. ```python should_not() ``` -------------------------------- ### Exclude Files with Regex Pattern Source: https://zyskarch.github.io/pytestarch/latest/features/general Specify a regex pattern to exclude specific files or directories from the architecture analysis. This is useful for ignoring test files or other generated code. ```python from pytestarch import get_evaluable_architecture evaluable = get_evaluable_architecture("/home/my_project", "/home/my_project/src", regex_exclusions=(".*_test\.py")) ``` -------------------------------- ### Define Layer Dependency Rule Source: https://zyskarch.github.io/pytestarch/latest/features/layer_architecture_checks Create a LayerRule based on a defined LayeredArchitecture. This rule specifies that modules in the 'import' layer should only access modules in the 'model' layer. Note that 'import' is replaced by 'access' for layer rules. ```python rule = ( LayerRule() .based_on(arch). # needs to be passed in first .layers_that() .are_named("import") .should_only() .access_layers_that() .are_named("model") ) ``` -------------------------------- ### Not Import Except Rule Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Sets a rule where module M1 should not import any module other than M2, but does not have to import M2. This allows imports only from M2, with M2 being optional. ```python M1 should not import except M2 ``` -------------------------------- ### Not Import Anything Rule Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks An alias for 'M1 should not import anything except itself'. This allows imports only within its own submodules but no other external imports. ```python 'M1 should not import anything' ``` -------------------------------- ### Define Layered Architecture Source: https://zyskarch.github.io/pytestarch/latest/features/layer_architecture_checks Use LayeredArchitecture to group modules into named layers. Modules can be specified directly or using regex patterns. All submodules of a module are assumed to belong to the same layer as their parent. ```python arch = ( LayeredArchitecture() .layer("import") .containing_modules(["M", "N"]) .layer("model") .containing_modules("O") ) ``` -------------------------------- ### MultipleRuleApplier.assert_applies Source: https://zyskarch.github.io/pytestarch/latest/references/query_language Checks a number of rules against the given evaluable and returns an aggregated error message if at least one test fails. ```APIDOC ## assert_applies(evaluable) ### Description Checks a number of rules against the given evaluable and returns an aggregated error message if at least one test fails. ### Parameters #### Path Parameters - **evaluable** (EvaluableArchitecture) - Required - Description ``` -------------------------------- ### get_parent_modules Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure Calculates and returns all parent modules for a given module. ```APIDOC ## get_parent_modules(module) ### Description Calculates all parent modules of a given module. For example, if the source root is a module `a.b.c`, this function would return `[a, a.b]`. ### Parameters #### Path Parameters - **module** (str) - Required - The module for which to calculate parent modules. ### Returns #### Success Response (list[str]) - **list[str]** - A list of all parent modules, including their full names up to the source code root. ``` -------------------------------- ### Be Imported Except By Rule Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Defines a rule where at least one module that isn't M2 should import M1. M2 can also import M1. This ensures M1 has external importers, with M2 being an allowed importer. ```python M1 should be imported except by M2 ``` -------------------------------- ### Only Be Imported Except By Rule Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Specifies that at least one module that isn't M2 should import M1, and M2 cannot import M1. This enforces that M1 must be imported by external modules, strictly excluding M2. ```python M1 should only be imported except by M2 ``` -------------------------------- ### RULE_SUBJECT: are_submodules_of() Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Use `are_submodules_of("Y")` to apply a rule to submodules of module 'Y', excluding 'Y' itself. ```python are_submodules_of("Y") ``` -------------------------------- ### Only Import Except Rule Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Specifies that module M1 must import at least one module that isn't M2, and must not import M2. This enforces a strict exclusion of M2 while requiring other imports. ```python M1 should only import except M2 ``` -------------------------------- ### VERB_MARKER_1: should_only() Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Use `should_only()` to specify that a module should only be imported by a specific set of other modules. ```python should_only() ``` -------------------------------- ### Import Except Rule Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Defines a rule where module M1 should import at least one module that isn't M2, but can also import M2. This allows for flexibility in imports while ensuring at least one external dependency. ```python M1 should import except M2 ``` -------------------------------- ### DependencyToRuleConverter Source: https://zyskarch.github.io/pytestarch/latest/references/diagram_extension Converts parsed dependency objects into a list of RuleAppliers. Explicit dependencies are converted to 'should (only)' rules, while missing but possible dependencies are converted to 'should not' rules. ```APIDOC ## Class: DependencyToRuleConverter ### Description Converts a parsed dependency object to a list of RuleAppliers. All explicit dependencies in the given object are converted to should (only) rules. All missing, but possible dependencies between the given modules are converted to 'should not' rules. ### Methods #### `convert(dependencies)` ##### Parameters - **dependencies**: Parsed modules and dependencies between modules. ##### Returns - **list[RuleApplier]**: list of RuleAppliers that can be applied to an evaluable. ``` -------------------------------- ### Check Named Module Imports Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Verifies that a module named 'C' is only imported by modules named 'A2'. This rule is false because 'C' is also imported by module 'A'. ```python modules_that() \ .are_named("C") \ .should_only() \ .be_imported_by_modules_that() \ .are_named("A2") \ ``` -------------------------------- ### Not Be Imported Except By Rule Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Sets a rule where no module other than M2 should import M1, but M2 does not have to import M1. This restricts importers of M1 to only M2, with M2's import being optional. ```python M1 should not be imported except by M2 ``` -------------------------------- ### ExternalImportFilter.filter Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure_generation Filters a list of imports based on the filter's configuration. ```APIDOC ## ExternalImportFilter.filter ### Description According to the configuration, imports will be filtered. ### Method `filter(imports)` ### Parameters #### Parameters - **imports** (Sequence[Import]) - Required - List of imports to be filtered. ### Returns - **filtered list of imports** (Sequence[Import]) - The filtered list of imports. ``` -------------------------------- ### Not Be Imported By Anything Rule Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks An alias for 'M1 should not be imported by anything except itself'. This restricts any module from importing M1, except for its own submodules. ```python 'M1 should not be imported by anything' ``` -------------------------------- ### Check Submodule Imports Source: https://zyskarch.github.io/pytestarch/latest/features/module_import_checks Ensures that submodules of module 'A' are only imported by submodules of module 'B'. This is a common scenario for enforcing architectural boundaries. ```python modules_that() \ .are_sub_modules_of("A") \ .should_only() \ .be_imported_by_modules_that() \ .are_sub_modules_of("B") \ ``` -------------------------------- ### NetworkxGraph.draw Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure Creates a matplotlib plot representing the graph. ```APIDOC ## NetworkxGraph.draw ### Description Creates a matplotlib plot representing the graph. ### Other Parameters #### Path Parameters - **spacing** (float) - Optional - optimal distance between nodes - **aliases** (Dict[str, str]) - Optional - module name aliases for plot labels. Keys are module names and values the aliases. If no alias is specified the module name is used a node label. If a module name has an alias, the module name is replaced by the alias for the module and all its submodules, e.g. for modules a, a.b, a.c, a.c.d and aliases == {'a', 'A'}, the plot labels for these modules will be A, A.b, A.c, A.c.d. If a submodule also has an alias, the alias for the submodule takes priority, e.g. with the same modules as above and aliases == {'a': 'A', 'a.c': 'C'} the plot labels will be A, A.b, C, C.d. ``` -------------------------------- ### Layer Rule with Unlayered Modules Source: https://zyskarch.github.io/pytestarch/latest/features/layer_architecture_checks Demonstrates how a layer rule is violated if a module within a specified layer accesses a module not belonging to any layer. The rule 'should_only().access_layers_that().are_named("B")' fails because module M imports module O, which is not part of any layer. ```python LayerRule().based_on(arch).layers_that().are_named("A").should_only().access_layers_that().are_named("B") ``` -------------------------------- ### Define Architectural Rule Source: https://zyskarch.github.io/pytestarch/latest Defines a rule that a specific module should not be imported by submodules of another specified module. This rule can be used for architectural validation. ```python from pytestarch import Rule rule = ( Rule() .modules_that() .are_named("project.src.moduleB") .should_not() .be_imported_by_modules_that() .are_sub_modules_of("project.src.moduleA") ) ``` -------------------------------- ### NetworkxGraph.direct_successor_nodes Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure Returns all nodes that the given node has a directed edge towards. ```APIDOC ## NetworkxGraph.direct_successor_nodes ### Description Returns all nodes that the given node has a directed edge towards. ### Parameters #### Path Parameters - **node** (Node) - Required - node for which to retrieve successor nodes ### Response #### Success Response (200) - **list[Node]** - all successor nodes ``` -------------------------------- ### FileFilter.is_excluded Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure_generation Determines if a file or directory should be excluded based on regex patterns. ```APIDOC ## FileFilter.is_excluded ### Description Returns True if the object matches one of the pre-configured exclusion patterns. ### Method `is_excluded(obj)` ### Parameters - **obj** (any) - The object (file or directory) to check for exclusion. ``` -------------------------------- ### parent_child_relationship Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure Checks if two given module nodes represent a parent-child hierarchy. ```APIDOC ## parent_child_relationship(supposed_parent_node, supposed_child_node) ### Description Returns True if the given nodes are marked as a parent-child hierarchy. ### Parameters #### Path Parameters - **supposed_parent_node** (Node) - Required - The potential parent node. - **supposed_child_node** (Node) - Required - The potential child node. ### Returns #### Success Response (bool) - **bool** - True if supposed parent is actually parent of supposed child node. ``` -------------------------------- ### NetworkxGraph.direct_predecessor_nodes Source: https://zyskarch.github.io/pytestarch/latest/references/eval_structure Returns all nodes that have a directed edge towards the given node. ```APIDOC ## NetworkxGraph.direct_predecessor_nodes ### Description Returns all nodes that have a directed edge towards the given node. ### Parameters #### Path Parameters - **node** (Node) - Required - node for which to retrieve predecessor nodes ### Response #### Success Response (200) - **list[Node]** - all predecessor nodes ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.