Skip to content

Commit e965163

Browse files
authored
Initial release (#1)
1 parent f30fc97 commit e965163

12 files changed

+743
-1
lines changed

.github/workflows/pipeline.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Test & Build
2+
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
8+
jobs:
9+
build_and_test:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout Repository
14+
uses: actions/checkout@v2
15+
16+
- name: Setup Python
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: '3.10'
20+
21+
- name: Install Dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install setuptools wheel
25+
26+
- name: Install Pytest
27+
run: |
28+
pip install pytest
29+
30+
- name: Build Package
31+
run: |
32+
python setup.py sdist
33+
34+
- name: Install Package
35+
run: |
36+
pip install dist/*
37+
38+
- name: Run Tests
39+
run: |
40+
pytest tests -vv -rEPW -o pytest_collection_order=alphabetical --cache-clear --color=yes

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Version History
2+
3+
- 0.1.0: Initial Release (latest)

README.md

+52-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,53 @@
1-
# pyconfigurationmanager
1+
# `pyconfigurationmanager`
22
The pyconfigurationmanager package provides a set of utilities for managing configuration settings in Python applications. It includes classes and functions for loading configuration data from files, auditing configuration changes, and ensuring secure access to configuration files.
3+
4+
## Installation
5+
Configuration Manager can be installed using pip:
6+
```bash
7+
pip install git+https://github.com/coldsofttech/pyconfigurationmanager.git
8+
```
9+
10+
## Usage
11+
````python
12+
from pyconfigurationmanager import ConfigurationManager
13+
14+
# Load the configuration file
15+
ConfigurationManager.load_config(file_path='config.json')
16+
17+
# Retrieve a string value
18+
string_value = ConfigurationManager.get_config_value('sample_string')
19+
print(string_value) # Output: 'string_of_sample'
20+
21+
# Retrieve an integer value
22+
integer_value = ConfigurationManager.get_config_value('sample_integer')
23+
print(integer_value) # Output: 100
24+
25+
# Retrieve a dictionary value
26+
dict_value = ConfigurationManager.get_config_value('sample_others')
27+
print(dict_value)
28+
# Output:
29+
# {'sample_boolean': True, 'sample_list': ['list_1', 'list_2']}
30+
31+
# Retrieve a boolean value
32+
boolean_value = ConfigurationManager.get_config_value('sample_others.sample_boolean')
33+
print(boolean_value) # Output: True
34+
35+
# Retrieve a list value
36+
list_value = ConfigurationManager.get_config_value('sample_others.sample_list')
37+
print(list_value) # Output: ['list_1', 'list_2']
38+
````
39+
40+
# Documentation
41+
## `pyconfigurationmanager`
42+
### `ConfigurationManager`
43+
The ConfigurationManager class is the heart of the package, offering a suite of functionalities for managing configuration settings.
44+
45+
#### Methods
46+
- `load_config(file_path: Optional[str] = 'config.json', secure: Optional[bool] = True, audit: Optional[bool] = False, audit_file_path: Optional[str] = 'audit.log')`: Loads configuration settings from a file into memory, with options to enable secure mode and auditing. By default, secure mode is enabled, ensuring that the configuration file has only readable permissions for the user. If auditing is enabled, all configuration accesses are logged for future audit purposes.
47+
- `get_config_value(key: Optional[str] = None)`: Retrieves the value of a specific configuration setting or the entire configuration if no key is provided. Hierarchical keys can be accessed by separating them with '.'.
48+
49+
### `ConfigurationManagerError`
50+
This error class is employed to signal any issues or errors encountered during the execution of ConfigurationManager methods.
51+
52+
#### Methods
53+
- `__init__(message: Optional[str])` - Initialize a ConfigurationManagerError

conftest.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) 2024 coldsofttech
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
def pytest_collection_modifyitems(config, items):
22+
"""
23+
Custom pytest hook to modify the collection of test items.
24+
This function sorts test items to execute specific tests first.
25+
"""
26+
def test_order(test_name):
27+
# Define the desired order of execution for specific test names
28+
order_mapping = {
29+
'test_get_config_value_invalid_no_config_set': 1,
30+
'test_valid_no_params': 2,
31+
'test_invalid_exposed_permissions': 3,
32+
'test_valid_insecure': 4,
33+
'test_invalid_file_not_found': 5,
34+
'test_invalid_json': 6,
35+
'test_get_config_value_valid_string': 7,
36+
'test_get_config_value_valid_integer': 8,
37+
'test_get_config_value_valid_dict': 9,
38+
'test_get_config_value_valid_boolean': 10,
39+
'test_get_config_value_valid_list': 11,
40+
'test_get_config_value_valid_audit_all': 12,
41+
'test_get_config_value_valid_audit_specific': 13
42+
}
43+
return order_mapping.get(test_name, float('inf')) # Default to infinity for tests not in the mapping
44+
45+
items.sort(key=lambda item: (test_order(item.nodeid.split("::")[-1]), item.fspath, item.originalname))

pyconfigurationmanager/__init__.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (c) 2024 coldsofttech
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
__all__ = [
22+
"ConfigurationManager",
23+
"ConfigurationManagerError",
24+
"__author__",
25+
"__description__",
26+
"__name__",
27+
"__version__"
28+
]
29+
__author__ = "coldsofttech"
30+
__description__ = """
31+
The pyconfigurationmanager package provides a set of utilities for managing configuration settings in
32+
Python applications. It includes classes and functions for loading configuration data from files,
33+
auditing configuration changes, and ensuring secure access to configuration files.
34+
"""
35+
__name__ = "pyconfigurationmanager"
36+
__version__ = "0.1.0"
37+
38+
from pyconfigurationmanager.__main__ import ConfigurationManager, ConfigurationManagerError

0 commit comments

Comments
 (0)