Register config¶
Within the package root folder, logging_strict.yml is a catalog of
available logging config YAML files. Including test files
Record fields
- file:
relative_path: configs/file_name_wo_suffixes
category: worker
genre: mp
flavor: asz
version_no: 1
is_test_file: false
version_no value is cast to str
Optional parameters
is_test_file. Test files are marked to indicate shouldn’t normally be returned in a normal query. If true, will be returned
Workflow
In package base folder, check if a
logging_strict.ymlexistsvalidate the yaml file against a schema. Failure results in a INFO and a WARNING message
read in the yaml file contents
Allow a way to search/query
Have a way to mark bad files, resources intended only for testing
- logging_strict.register_config.REGEX_REL_PATH: str¶
regex for posix relative path. Modified to:
include A-Z and underscore
the last negative lookbehind prevents trailing underscore period and hyphen
path/file.html-path/file.html.path/file.html_
See also
regex for relative path tool to test regex <https://regex101.com/>
Given a yaml str, what does strictyaml sees?
import strictyaml as s
lst_expected = [{"file": {"a": "b", "c": "d"}}, {"file": {"b": "a", "d": "c"}}]
obj_yaml = s.YAML(lst_expected)
print(obj_yaml.as_yaml())
- file:
a: b
c: d
- file:
b: a
d: c
Between - file:\\n and a: b\\n there are four spaces, not two.
Very helpful to understand difference between expected dict and needed yaml str
- class logging_strict.register_config.ExtractorLoggingConfig(package_name, path_alternative_dest_folder=None, is_test_file=False)¶
Bases:
objectExtract both registry (YAML) db and a logging config YAML file
- Variables:
package_name (str) – Dirty package name of a package installed into venv.
path_alternative_dest_folder (pathlib.Path | None) –
The extraction folder, by default, is XDG User config folder. Support specifying an alternative folder.
Having this feature baked in, would eleviate the need to use unittest.mock.patch and know what to patch
is_test_file (bool | None) – Default False. True if want to search for test files
- __slots__: tuple[str, str, str, str, str, str, str] = ("_package_name", "_patch_extract_folder", "_path_extraction_dir", "_is_test_file", "_path_extracted_db", "_logging_config_yaml_str", "_registry", "_logging_config_yaml_relpath")¶
Fixed class private attributes
- _is_test_file¶
- _logging_config_yaml_relpath¶
- _logging_config_yaml_str¶
- _package_name¶
- _patch_extract_folder¶
- _path_extracted_db¶
- _path_extraction_dir¶
- _registry¶
- static clean_package_name(val)¶
Set raw package name. Is sanitized so it’s a valid package name
- extract_db()¶
Extract logging config YAML file registry db. Implementation is YAML so can be validated.
If no such package installed, Logs a warning. Does not raise ImportError
- get_db(path_extracted_db=None)¶
Get YAML registry of logging config YAML file records. Which happens also to be a YAML file.
If package not installed, will emit INFO and WARNING log messages
- Parameters:
path_extracted_db¶ (pathlib.Path | None) – Default None. None extract registry otherwise restore previously extracted YAML registry from file
- Returns:
On success entire database. None if database file not found
- Return type:
- Raises:
strictyaml.YAMLValidationError– validation failed
- property is_test_file¶
True if should extract a test files otherwise extract normal logging strict YAML files
- Returns:
True extract a test file. False extract normal file
- Return type:
- property logging_config_yaml_relpath¶
Get query_db result absolute path to destination logging config YAML file
- Returns:
absolute path
- Return type:
str | None
- property logging_config_yaml_str¶
Get query_db result
UI – will return a logging config dict
WORKER – logging config returns a yaml str. Multiprocessing situation can only pass str, not a dict
- property path_extracted_db¶
After
logging_strict.register_config.ExtractorLoggingConfig.extract_db()will hold the path to the registry db YAML file- Returns:
logging config YAML registry db path. registry db is also a YAML file
- Return type:
pathlib.Path | None
- query_db(category, genre=None, flavor=None, version_no='1', logger_package_name=None, is_skip_setup=True)¶
Query the database
Result available from property logging_config_yaml_str
Does not emit log messages
- Parameters:
category¶ (logging_strict.constants.LoggingConfigCategory | str | Any | None) – worker or app. Unfortunitely the default is app.
genre¶ (str | None) – Library or how the logging config YAML file is applied. If UI: “textual”. If worker: “mp”. More will be added over time
flavor¶ (str | None) – The brand or package which first used this logging config YAML file
version_no¶ (str | None) – Default “1”. The logging config YAML file version no. Previous versions are not necessarily removed unless it’s known no one on the planet is using it.
logger_package_name¶ (str | None) – Default None. In the logging config YAML file, replaces default logger token with package name that will be logged
is_skip_setup¶ (bool | None) – Default True. During querying, avoid (UI only) setup. Logging setup can raise errors, such as ModuleNotFoundError