General
pytestarch
The following two functions are the main entry point to PyTestArch. They can be used to create an evaluable object, for which the user can then define architectural rules.
get_evaluable_architecture(root_path, module_path, exclusions=DEFAULT_EXCLUSIONS, exclude_external_libraries=True, level_limit=None, regex_exclusions=None, external_exclusions=None, regex_external_exclusions=None)
Constructs an evaluable object based on the given module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root_path |
str
|
root directory of the source code. Should not be set to a submodule of the top level module. |
required |
module_path |
str
|
path of module to generate the evaluable for. Must be a submodule of the root_path module. |
required |
exclusions |
tuple[str, ...]
|
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_EXCLUSIONS
|
external_exclusions |
tuple[str, ...] | None
|
pseudo-regex version of 'external_exclusions' to exclude certain external dependencies from being integrated into the evaluable. Can only be specified if exclude_external_libraries is False and regex_external_exclusions is not specified. Note that child dependencies are not automatically excluded, e.g. if exclusion regex is 'logging', then 'logging.handler' will not be excluded. For exclude this as well, use 'logging.*'. |
None
|
exclude_external_libraries |
bool
|
if True, external dependencies (defined as all dependencies to module outside the module_path, including Python built-in modules) will not be taken into account for the dependency analysis. If a parent module (e.g. 'logging') is excluded, so will be child modules (e.g. 'logging.handlers'). |
True
|
level_limit |
int | None
|
if not None, specifies the depth of the graph. For example, a limit of 1 will result in only the modules one level below the module path to be added as nodes. Note that this only applies to the final graph; all modules will be parsed, the graph will simply be flattened: if a submodule of X imports Y, this import is then assigned to X instead, if Y is above the level limit. |
None
|
regex_exclusions |
tuple[str, ...] | None
|
Proper regex version of 'exclusions'. Can only be specified if regex_exclusions is not specified. |
None
|
regex_external_exclusions |
tuple[str, ...] | None
|
Proper regex version of 'external_exclusions' to exclude certain external dependencies from being integrated into the evaluable. Can only be specified if exclude_external_libraries is False and external_exclusions is not specified. If a parent module (e.g. 'logging') is excluded, so will be child modules (e.g. 'logging.handlers'). |
None
|
get_evaluable_architecture_for_module_objects(root_module, module, exclusions=DEFAULT_EXCLUSIONS, exclude_external_libraries=True, level_limit=None, regex_exclusions=None, external_exclusions=None, regex_external_exclusions=None)
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.