diff --git a/.vscode/settings.json b/.vscode/settings.json index 7c32b0d..9f07c66 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,20 +4,5 @@ "python.linting.enabled": true, "python.pythonPath": ".venv/bin/python", "restructuredtext.confPath": "${workspaceFolder}/docs/source", - "peacock.color": "#307E6A", - "workbench.colorCustomizations": { - "editorGroup.border": "#3ea389", - "panel.border": "#3ea389", - "sash.hoverBorder": "#3ea389", - "sideBar.border": "#3ea389", - "statusBar.background": "#307e6a", - "statusBar.foreground": "#e7e7e7", - "statusBarItem.hoverBackground": "#3ea389", - "statusBarItem.remoteBackground": "#307e6a", - "statusBarItem.remoteForeground": "#e7e7e7", - "titleBar.activeBackground": "#307e6a", - "titleBar.activeForeground": "#e7e7e7", - "titleBar.inactiveBackground": "#307e6a99", - "titleBar.inactiveForeground": "#e7e7e799" - } + "peacock.color": "#307E6A" } diff --git a/README.md b/README.md index f933352..3c357a5 100644 --- a/README.md +++ b/README.md @@ -32,16 +32,21 @@ See Tembo for an example: str: raise NotImplementedError + @property + @abstractmethod + def logging_level(self) -> str: + raise NotImplementedError + @abstractmethod def __init__(self, logging_level: str): raise NotImplementedError @@ -119,8 +124,12 @@ class SimpleLogger(LoggingData): '"%(levelname)s",\n\t"message": "%(message)s"\n}', ) + @property + def logging_level(self) -> str: + return self._logging_level + def __init__(self, logging_level: str = "INFO"): - self.logging_level = logging_level + self._logging_level = logging_level class AdvancedLogger(LoggingData): @@ -133,8 +142,12 @@ class AdvancedLogger(LoggingData): '"%(levelname)s",\n\t"message": "%(message)s"\n}', ) + @property + def logging_level(self) -> str: + return self._logging_level + def __init__(self, logging_level: str = "INFO"): - self.logging_level = logging_level + self._logging_level = logging_level class CustomLogger(LoggingData): @@ -142,6 +155,10 @@ class CustomLogger(LoggingData): def format(self) -> str: return str(self._format) + @property + def logging_level(self) -> str: + return self._logging_level + def __init__(self, logging_format: str, logging_level: str = "INFO"): - self.logging_level = logging_level + self._logging_level = logging_level self._format = logging_format diff --git a/pyproject.toml b/pyproject.toml index 974e63f..7875796 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,19 @@ coverage = "^6.0.2" duty = "^0.7.0" types-PyYAML = "^6.0.1" +[tool.black] +line-length = 120 + +[tool.isort] +line-length = 120 +not_skip = "__init__.py" +multi_line_output = 3 +force_single_line = false +balanced_wrapping = true +default_section = "THIRDPARTY" +known_first_party = "duty" +include_trailing_comma = true + [build-system] requires = ["poetry>=0.12"] build-backend = "poetry.masonry.api" diff --git a/setup.py b/setup.py index acec652..3646deb 100644 --- a/setup.py +++ b/setup.py @@ -12,9 +12,9 @@ install_requires = \ setup_kwargs = { 'name': 'panaetius', - 'version': '2.3.1', + 'version': '2.3.2', 'description': 'Python module to gracefully handle a .config file/environment variables for scripts, with built in masking for sensitive options. Provides a Splunk friendly formatted logger instance.', - 'long_description': '# Panaetius\n\nThis package provides:\n\n- Functionality to read user variables from a `config.yml` or environment variables.\n- A convenient default logging formatter printing `json` that can save to disk and rotate.\n- Utility functions.\n\n## Config\n\n### options\n\n#### skip_header_init\n\nIf `skip_header_init=True` then the `config_path` will not use the `header_variable` as the\nsub-directory in the `config_path`.\n\nE.g\n\n`CONFIG = panaetius.Config("tembo", "~/tembo/.config", skip_header_init=True)`\n\nWill look in `~/tembo/config/config.yml`.\n\nIf `skip_header_init=False` then would look in `~/tembo/config/tembo/config.yml`.\n\n### Module\n\nConvenient to place in a package/sub-package `__init__.py`.\n\nSee Tembo for an example: \n\nExample snippet to use in a module:\n\n```python\nimport os\n\nimport panaetius\nfrom panaetius.exceptions import LoggingDirectoryDoesNotExistException\n\n\nif (config_path := os.environ.get("TEMBO_CONFIG")) is not None:\n CONFIG = panaetius.Config("tembo", config_path, skip_header_init=True)\nelse:\n CONFIG = panaetius.Config("tembo", "~/tembo/.config", skip_header_init=True)\n\n\npanaetius.set_config(CONFIG, "base_path", "~/tembo")\npanaetius.set_config(CONFIG, "template_path", "~/tembo/.templates")\npanaetius.set_config(CONFIG, "scopes", {})\npanaetius.set_config(CONFIG, "logging.level", "DEBUG")\npanaetius.set_config(CONFIG, "logging.path")\n\ntry:\n logger = panaetius.set_logger(\n CONFIG, panaetius.SimpleLogger(logging_level=CONFIG.logging_level)\n )\nexcept LoggingDirectoryDoesNotExistException:\n _LOGGING_PATH = CONFIG.logging_path\n CONFIG.logging_path = ""\n logger = panaetius.set_logger(\n CONFIG, panaetius.SimpleLogger(logging_level=CONFIG.logging_level)\n )\n logger.warning("Logging directory %s does not exist", _LOGGING_PATH)\n\n```\n\nThis means in `./tembo/cli/cli.py` you can\n\n```python\nimport tembo.cli\n\n# access the CONFIG instance + variables from the config.yml\ntembo.cli.CONFIG\n```\n\n\n## Utility Functions\n\n### Squasher\n\nSquashes a json object or Python dictionary into a single level dictionary.\n', + 'long_description': '# Panaetius\n\nThis package provides:\n\n- Functionality to read user variables from a `config.yml` or environment variables.\n- A convenient default logging formatter printing `json` that can save to disk and rotate.\n- Utility functions.\n\n## Config\n\n### options\n\n#### skip_header_init\n\nIf `skip_header_init=True` then the `config_path` will not use the `header_variable` as the\nsub-directory in the `config_path`.\n\nE.g\n\n`CONFIG = panaetius.Config("tembo", "~/tembo/.config", skip_header_init=True)`\n\nWill look in `~/tembo/config/config.yml`.\n\nIf `skip_header_init=False` then would look in `~/tembo/config/tembo/config.yml`.\n\n### Module\n\nConvenient to place in a package/sub-package `__init__.py`.\n\nSee Tembo for an example: \n\nExample snippet to use in a module:\n\n```python\n"""Subpackage that contains the CLI application."""\n\nimport os\nfrom typing import Any\n\nimport panaetius\nfrom panaetius.exceptions import LoggingDirectoryDoesNotExistException\n\n\nif (config_path := os.environ.get("TEMBO_CONFIG")) is not None:\n CONFIG: Any = panaetius.Config("tembo", config_path, skip_header_init=True)\nelse:\n CONFIG = panaetius.Config(\n "tembo", "~/tembo/.config", skip_header_init=True\n )\n\n\npanaetius.set_config(CONFIG, "base_path", "~/tembo")\npanaetius.set_config(CONFIG, "template_path", "~/tembo/.templates")\npanaetius.set_config(CONFIG, "scopes", {})\npanaetius.set_config(CONFIG, "logging.level", "DEBUG")\npanaetius.set_config(CONFIG, "logging.path")\n\ntry:\n logger = panaetius.set_logger(\n CONFIG, panaetius.SimpleLogger(logging_level=CONFIG.logging_level)\n )\nexcept LoggingDirectoryDoesNotExistException:\n _LOGGING_PATH = CONFIG.logging_path\n CONFIG.logging_path = ""\n logger = panaetius.set_logger(\n CONFIG, panaetius.SimpleLogger(logging_level=CONFIG.logging_level)\n )\n logger.warning("Logging directory %s does not exist", _LOGGING_PATH)\n\n```\n\nThis means in `./tembo/cli/cli.py` you can\n\n```python\nimport tembo.cli\n\n# access the CONFIG instance + variables from the config.yml\ntembo.cli.CONFIG\n```\n\n\n## Utility Functions\n\n### Squasher\n\nSquashes a json object or Python dictionary into a single level dictionary.\n', 'author': 'dtomlinson', 'author_email': 'dtomlinson@panaetius.co.uk', 'maintainer': None,