src\wily\config\__init__.py
-- -- --- --- --- --- --- --- ------- ------- ------- | """
-- -- --- --- --- --- --- --- ------- ------- ------- | Configuration of wily.
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | TODO : Handle operator settings. Maybe a section for each operator and then pass kwargs to operators?
-- -- --- --- --- --- --- --- ------- ------- ------- | TODO : Better utilise default values and factory in @dataclass to replace DEFAULT_CONFIG
-- -- --- --- --- --- --- --- ------- ------- ------- | and replace the logic in load() to set default values.
-- -- --- --- --- --- --- --- ------- ------- ------- | """
-- -- --- --- --- --- --- --- ------- ------- ------- | import configparser
-- -- --- --- --- --- --- --- ------- ------- ------- | import logging
-- -- --- --- --- --- --- --- ------- ------- ------- | import pathlib
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | from wily import operators
-- -- --- --- --- --- --- --- ------- ------- ------- | from wily.config.types import WilyConfig
-- -- --- --- --- --- --- --- ------- ------- ------- | from wily.defaults import (
-- -- --- --- --- --- --- --- ------- ------- ------- | DEFAULT_ARCHIVER,
-- -- --- --- --- --- --- --- ------- ------- ------- | DEFAULT_CONFIG_PATH,
-- -- --- --- --- --- --- --- ------- ------- ------- | DEFAULT_CONFIG_SECTION,
-- -- --- --- --- --- --- --- ------- ------- ------- | DEFAULT_MAX_REVISIONS,
-- -- --- --- --- --- --- --- ------- ------- ------- | DEFAULT_PATH,
-- -- --- --- --- --- --- --- ------- ------- ------- | )
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | logger = logging.getLogger(__name__)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | # Default values for Wily
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | """ The default operators """
-- -- --- --- --- --- --- --- ------- ------- ------- | DEFAULT_OPERATORS = {
-- -- --- --- --- --- --- --- ------- ------- ------- | operators.OPERATOR_RAW.name,
-- -- --- --- --- --- --- --- ------- ------- ------- | operators.OPERATOR_MAINTAINABILITY.name,
-- -- --- --- --- --- --- --- ------- ------- ------- | operators.OPERATOR_CYCLOMATIC.name,
-- -- --- --- --- --- --- --- ------- ------- ------- | operators.OPERATOR_HALSTEAD.name,
-- -- --- --- --- --- --- --- ------- ------- ------- | }
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | """ The default configuration for Wily (if no config file exists) """
-- -- --- --- --- --- --- --- ------- ------- ------- | DEFAULT_CONFIG = WilyConfig(
-- -- --- --- --- --- --- --- ------- ------- ------- | operators=DEFAULT_OPERATORS,
-- -- --- --- --- --- --- --- ------- ------- ------- | archiver=DEFAULT_ARCHIVER,
-- -- --- --- --- --- --- --- ------- ------- ------- | path=DEFAULT_PATH,
-- -- --- --- --- --- --- --- ------- ------- ------- | max_revisions=DEFAULT_MAX_REVISIONS,
-- -- --- --- --- --- --- --- ------- ------- ------- | )
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | def load(config_path=DEFAULT_CONFIG_PATH):
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | """
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | Load config file and set values to defaults where no present.
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | :return: The configuration ``WilyConfig``
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | :rtype: :class:`wily.config.WilyConfig`
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | """
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | if not pathlib.Path(config_path).exists():
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | logger.debug(f"Could not locate {config_path}, using default config.")
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | return DEFAULT_CONFIG
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | config = configparser.ConfigParser(default_section=DEFAULT_CONFIG_SECTION)
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | config.read(config_path)
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | operators = config.get(
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | section=DEFAULT_CONFIG_SECTION, option="operators", fallback=DEFAULT_OPERATORS
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | )
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | archiver = config.get(
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | section=DEFAULT_CONFIG_SECTION, option="archiver", fallback=DEFAULT_ARCHIVER
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | )
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | path = config.get(section=DEFAULT_CONFIG_SECTION, option="path", fallback=".")
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | cache_path = config.get(
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | section=DEFAULT_CONFIG_SECTION, option="cache_path", fallback=""
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | )
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | max_revisions = config.getint(
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | section=DEFAULT_CONFIG_SECTION,
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | option="max_revisions",
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | fallback=DEFAULT_MAX_REVISIONS,
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | )
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | include_ipynb = config.getboolean(
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | section=DEFAULT_CONFIG_SECTION, option="include_ipynb", fallback=True
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | )
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | ipynb_cells = config.getboolean(
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | section=DEFAULT_CONFIG_SECTION, option="ipynb_cells", fallback=True
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | )
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 |
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | return WilyConfig(
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | operators=operators,
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | archiver=archiver,
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | path=path,
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | _cache_path=cache_path,
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | max_revisions=max_revisions,
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | include_ipynb=include_ipynb,
-- 02 001 001 001 001 002 002 0002.00 0001.00 0000.50 | ipynb_cells=ipynb_cells,
-- -- 001 001 001 001 002 002 0002.00 0001.00 0000.50 | )