macaron.config package

Submodules

macaron.config.defaults module

This module provides functions to manage default values.

class macaron.config.defaults.ConfigParser(defaults=None, dict_type=<class 'dict'>, allow_no_value=False, *, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True, default_section='DEFAULT', interpolation=<object object>, converters=<object object>)

Bases: ConfigParser

This class extends ConfigParser with useful methods.

get_list(section, option, delimiter='\\n', fallback=None, strip=True, remove_duplicates=True)

Parse and return a list of strings from an option for section in defaults.ini.

This method uses str.split() to split the value into list of strings. References: https://docs.python.org/3/library/stdtypes.html#str.split.

The following parameters are used to modify the behavior of the split operation.

If delimiter is set (default: “n”), it will be used to split the list of strings (i.e content.split(sep=delimiter)).

If strip is True (default: True), strings are whitespace-stripped and empty strings are removed from the final result.

If remove_duplicates is True, duplicated elements which come after the their first instances will be removed from the list. This operation happens after strip is handled.

The order of non-empty elements in the list is preserved. The content of each string in the list is not validated and should be handled separately.

Parameters:
  • section (str) – The section in defaults.ini.

  • option (str) – The option whose values will be split into the a list of strings.

  • delimiter (str | None) – The delimiter used to split the strings.

  • fallback (list | None) – The fallback value in case of errors.

  • strip (bool) – If True, strings are whitespace-stripped and any empty strings are removed.

  • remove_duplicates (bool) – If True, duplicated elements will be removed from the list.

Returns:

The result list of strings or an empty list if errors.

Return type:

list

Examples

Given the following defaults.ini

[git]
allowed_hosts =
    github.com
    boo.com gitlab.com
    host com
allowed_hosts = config_parser.get_list("git", "allowed_hosts")
allowed_hosts == ["github.com", "boo.com gitlab.com", "host com"]
macaron.config.defaults.load_defaults(user_config_path)

Read the default values from defaults.ini file and store them in the defaults global object.

Parameters:

user_defaults_path (str) – The path to the user’s defaults configuration file.

Returns:

Return True if succeeded or False if failed.

Return type:

bool

macaron.config.defaults.create_defaults(output_path, cwd_path)

Create the defaults.ini file at the Macaron’s root dir for end users.

Parameters:
  • output_path (str) – The path where the defaults.ini will be created.

  • cwd_path (str) – The path to the current working directory.

Returns:

Return True if succeeded or False if failed.

Return type:

bool

macaron.config.global_config module

This module contains the GlobalConfig class to be used globally.

class macaron.config.global_config.GlobalConfig(expectation_paths=<factory>, macaron_path='', output_path='', build_log_path='', local_repos_path='', gh_token='', gl_token='', gl_self_host_token='', debug_level=10, resources_path='', python_venv_path='')

Bases: object

Class for keeping track of global configurations.

expectation_paths: list[str]

The provenance expectation paths.

macaron_path: str = ''

The path to the Macaron Python package.

output_path: str = ''

The path to the output files.

build_log_path: str = ''

The path to build logs directory.

local_repos_path: str = ''

The path to the local clone of the target repository.

gh_token: str = ''

The GitHub token.

gl_token: str = ''

The GitLab public token.

gl_self_host_token: str = ''

The GitLab self-hosted token.

debug_level: int = 10

The debug level.

resources_path: str = ''

The path to resources directory.

python_venv_path: str = ''

The path to Python virtual environment.

load(macaron_path, output_path, build_log_path, debug_level, local_repos_path, resources_path)

Initiate the GlobalConfig object.

Parameters:
  • macaron_path (str) – Macaron’s root path.

  • output_path (str) – Output path.

  • build_log_path (str) – The build log path.

  • debug_level (int) – The global debug level.

  • local_repos_path (str) – The directory to look for local repositories.

  • resources_path (str) – The path to the resources files needed for the analysis (i.e. mvnw, gradlew, etc.)

Return type:

None

load_expectation_files(exp_path)

Load provenance expectation files.

Parameters:

exp_path (str) – The path to the provenance expectation file or directory containing the files.

Return type:

None

load_python_venv(venv_path)

Load Python virtual environment.

Parameters:

venv_path (str) – The path to the Python virtual environment of the target software component.

Return type:

None

__init__(expectation_paths=<factory>, macaron_path='', output_path='', build_log_path='', local_repos_path='', gh_token='', gl_token='', gl_self_host_token='', debug_level=10, resources_path='', python_venv_path='')
macaron.config.global_config.global_config = GlobalConfig(expectation_paths=[], macaron_path='', output_path='', build_log_path='', local_repos_path='', gh_token='', gl_token='', gl_self_host_token='', debug_level=10, resources_path='', python_venv_path='')

The object that can be imported and used globally.

macaron.config.target_config module

This module contains the Configuration class for the target analyzed repository.

macaron.config.target_config.TARGET_CONFIG_SCHEMA: Schema = <yamale.schema.schema.Schema object>

The schema for the target configuration yaml file.

class macaron.config.target_config.Configuration(data=None)

Bases: object

This class contains the configuration for an analyzed repo in Macaron.

__init__(data=None)

Construct the Configuration object.

Parameters:

data (dict | None) – The dictionary contains the data to analyze a repository.

set_value(key, value)

Set an option in the configuration.

Parameters:
  • key (str) – The key to insert value.

  • value (Any) – The value to insert.

Return type:

None

get_value(key)

Get an option value in the configuration.

Parameters:

key (str) – The key to get the value.

Returns:

The value indicated by key or None if not existed.

Return type:

Any