mirror of
https://github.com/dtomlinson91/panaetius.git
synced 2025-12-21 20:55:43 +00:00
adding a config.yml instead of config.toml
This commit is contained in:
17
.vscode/settings.json
vendored
17
.vscode/settings.json
vendored
@@ -4,5 +4,20 @@
|
||||
"python.linting.enabled": true,
|
||||
"python.pythonPath": ".venv/bin/python",
|
||||
"restructuredtext.confPath": "${workspaceFolder}/docs/source",
|
||||
"peacock.color": "#307E6A"
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Access variables from a config file or an environment variable.
|
||||
|
||||
This module defines the `Config` class to interact and read variables from either a
|
||||
`config.toml` or an environment variable.
|
||||
`config.yml` or an environment variable.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -12,7 +12,8 @@ import os
|
||||
import pathlib
|
||||
from typing import Any
|
||||
|
||||
import toml
|
||||
# import toml
|
||||
import yaml
|
||||
|
||||
from panaetius.exceptions import KeyErrorTooDeepException, InvalidPythonException
|
||||
|
||||
@@ -31,7 +32,7 @@ class Config:
|
||||
|
||||
Example:
|
||||
A header of `data_analysis` with a config_path of `~/myapps` will define
|
||||
a config file in `~/myapps/data_analysis/config.toml`.
|
||||
a config file in `~/myapps/data_analysis/config.yml`.
|
||||
"""
|
||||
self.header_variable = header_variable
|
||||
self.config_path = (
|
||||
@@ -52,12 +53,13 @@ class Config:
|
||||
Return the contents of the config file. If missing returns an empty dictionary.
|
||||
|
||||
Returns:
|
||||
dict: The contents of the `.toml` loaded as a python dictionary.
|
||||
dict: The contents of the `.yml` loaded as a python dictionary.
|
||||
"""
|
||||
config_file_location = self.config_path / self.header_variable / "config.toml"
|
||||
config_file_location = self.config_path / self.header_variable / "config.yml"
|
||||
try:
|
||||
with open(config_file_location, "r", encoding="utf-8") as config_file:
|
||||
return dict(toml.load(config_file))
|
||||
# return dict(toml.load(config_file))
|
||||
return dict(yaml.load(stream=config_file, Loader=yaml.SafeLoader))
|
||||
except FileNotFoundError:
|
||||
return {}
|
||||
|
||||
@@ -67,8 +69,8 @@ class Config:
|
||||
|
||||
The key can either be one (`value`) or two (`data.value`) levels deep.
|
||||
|
||||
A key of (`value`) (with a header of `data_analysis`) would refer to a
|
||||
`config.toml` of:
|
||||
A key of `value` (with a header of `data_analysis`) would refer to a
|
||||
`config.yml` of:
|
||||
|
||||
```
|
||||
[data_analysis]
|
||||
@@ -77,7 +79,7 @@ class Config:
|
||||
|
||||
or an environment variable of `DATA_ANALYSIS_VALUE="'some value'"`.
|
||||
|
||||
A key of (`data.value`) would refer to a `config.toml` of:
|
||||
A key of `data.value` would refer to a `config.yml` of:
|
||||
```
|
||||
[data_analysis.data]
|
||||
value = "some value"
|
||||
@@ -101,7 +103,7 @@ class Config:
|
||||
return self._get_env_value(env_key, default)
|
||||
|
||||
def _check_config_file_exists(self) -> bool:
|
||||
config_file_location = self.config_path / self.header_variable / "config.toml"
|
||||
config_file_location = self.config_path / self.header_variable / "config.yml"
|
||||
try:
|
||||
with open(config_file_location, "r", encoding="utf-8"):
|
||||
return False
|
||||
|
||||
16
poetry.lock
generated
16
poetry.lock
generated
@@ -421,14 +421,6 @@ python-versions = "*"
|
||||
[package.dependencies]
|
||||
pylint = ">=1.7"
|
||||
|
||||
[[package]]
|
||||
name = "pylite"
|
||||
version = "0.1.0"
|
||||
description = "Intract with sqlite3 in python as simple as it can be."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
|
||||
[[package]]
|
||||
name = "pyparsing"
|
||||
version = "2.4.7"
|
||||
@@ -504,7 +496,7 @@ testing = ["filelock"]
|
||||
name = "pyyaml"
|
||||
version = "6.0"
|
||||
description = "YAML parser and emitter for Python"
|
||||
category = "dev"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
|
||||
@@ -621,7 +613,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytes
|
||||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.7"
|
||||
content-hash = "468d1aa5e0c440262f6041ad859358a84ef32462941aa6f3ba71838a52cc1ced"
|
||||
content-hash = "f68e5ab35a155ce5ea567b670f93f4678b6c65d1335017b21431b315297a0410"
|
||||
|
||||
[metadata.files]
|
||||
astroid = [
|
||||
@@ -834,10 +826,6 @@ pylint-plugin-utils = [
|
||||
{file = "pylint-plugin-utils-0.6.tar.gz", hash = "sha256:57625dcca20140f43731311cd8fd879318bf45a8b0fd17020717a8781714a25a"},
|
||||
{file = "pylint_plugin_utils-0.6-py3-none-any.whl", hash = "sha256:2f30510e1c46edf268d3a195b2849bd98a1b9433229bb2ba63b8d776e1fc4d0a"},
|
||||
]
|
||||
pylite = [
|
||||
{file = "pylite-0.1.0-py3-none-any.whl", hash = "sha256:eb46f5beb1f2102672fd4355c013ac2feebc0df284d65f7711f2041a0a410141"},
|
||||
{file = "pylite-0.1.0.tar.gz", hash = "sha256:e338d20d3f8f72dd84d1e58f2fd6dba008d593e0cfacfb5fbdd5a297b830628e"},
|
||||
]
|
||||
pyparsing = [
|
||||
{file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"},
|
||||
{file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"},
|
||||
|
||||
@@ -25,7 +25,7 @@ classifiers = [
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.7"
|
||||
toml = "^0.10.0"
|
||||
pylite = "^0.1.0"
|
||||
PyYAML = "^6.0"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
prospector = {extras = ["with_bandit", "with_mypy"], version = "^1.5.1"}
|
||||
|
||||
9
tests/data/without_logging/panaetius_testing/config.yml
Normal file
9
tests/data/without_logging/panaetius_testing/config.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
panaetius_testing:
|
||||
some_top_string: some_top_value
|
||||
second:
|
||||
some_second_string: some_second_value
|
||||
some_second_int: 1
|
||||
some_second_float: 1.0
|
||||
some_second_list: ["some", "second", "value"]
|
||||
some_second_table: { "first": ["some", "first", "value"] }
|
||||
some_second_table_bools: { "bool": [true, false] }
|
||||
Reference in New Issue
Block a user