Skip to content

Commit

Permalink
Add sha1 property to Config
Browse files Browse the repository at this point in the history
  • Loading branch information
erick committed Feb 17, 2025
1 parent 74d5482 commit 13eda37
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up Python
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Runt tests
- name: Unittest
run: |
export PYTHONPATH=./src
python -m unittest -v ./tests/test_*.py
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ class MyConfig(Config):
settings = Config.from_toml(filepath="config.toml", defaults=defaults)
super().__init__(settings=settings)

@property
def listen(self) -> str:
return self["main"]["listen"]

@property
def port(self) -> int:
return self["main"]["port"]

if __name__ == "__main__":
cfg = MyConfig()
print(cfg.port())
print(cfg.port)
# it will print the default port value if not port setting was defined in config.toml

```
Expand Down Expand Up @@ -114,10 +116,10 @@ from minibone.logging import setup_log
if __name__ == "__main__":

# setup_log must be called only once in your code.
# So you have to choice if logging to stderr or to a file when calling it
# So you have to choice if logging to stdin or to a file when calling it

setup_log(level="INFO")
logging.info('This is a log to the stderr')
logging.info('This is a log to the stdin')

# or call the next lines instead if you want to log into a file
# setup_log(file="sample.log", level="INFO")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[project]
name = "minibone"
version = "0.7.4"
version = "0.7.5"
description = "Small boiler plate with tools for multithreading."
keywords = ["multithreading", "task", "job", "background"]
authors = [
Expand Down
6 changes: 6 additions & 0 deletions src/minibone/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import hashlib
import json
import logging
import re
Expand Down Expand Up @@ -257,6 +258,11 @@ def __init__(self, settings: dict = {}, filepath: str = None):
for key, value in settings.items():
self.add(key, value)

@property
def sha1(self):
"""Return the sha1 hash value for current config settings"""
return hashlib.sha1(bytes(str(self.copy()), "utf-8")).hexdigest()

def _tofile(self, format: FORMAT):
"""Save settings to file in format
Expand Down
2 changes: 1 addition & 1 deletion src/minibone/storing.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def to_json(self, path: str, filename: str, data: dict | list):

item = {"format": FORMAT.JSON, "path": path, "file": filename, "data": data}
self._queue.append(item)
self._logger.info("{}/{} aded to queue".format(path, filename))
self._logger.info("{}/{} added to queue".format(path, filename))

def on_process(self):
if len(self._queue) == 0:
Expand Down
1 change: 1 addition & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def test_settings(self):
settings = {"setting1": "value1", "setting2": 2, "setting3": True}
cfg = Config(settings=settings, filepath=None)

self.assertEqual(cfg.sha1, "f8b312b90657dbef8a72ece9ab687921c0200a26")
self.assertEqual(cfg.get("setting1", None), "value1")
self.assertEqual(cfg.get("setting10", None), None)
self.assertEqual(cfg.get("setting2", None), 2)
Expand Down

0 comments on commit 13eda37

Please sign in to comment.