A reusable utility library.
dazbo-commons/
│
├── src/
│ └── dazbo_commons/
│ ├── __init__.py
│ └── colored_logging.py
│
├── tests/
│ └── test_colored_logging.py
│
├── .env
├── .gitignore
├── LICENSE
├── pyproject.toml
├── README.md
└── requirements.txt
You can simply install the package from PyPi. There's no need to clone this repo.
pip install --upgrade dazbo-commonsThen, in your Python code, include this import:
import dazbo_commons as dcThis module provides a function to retrieve a logger that logs to the console, with colour.
Example:
import logging
import dazbo_commons as dc
logger_name = __name__ # or just pass in a str
logger = dc.retrieve_console_logger(logger_name)
logger.setLevel(logging.INFO) # Set threshold. E.g. INFO, DEBUG, or whatever
logger.info("Some msg") # log at info levelThis module is used to retrieve a Locations class, which stores directory paths
based on the location of a specified script.
This makes it convenient to manage and access different file and directory paths
relative to a given script's location.
Example:
import dazbo_commons as dc
APPNAME = "My_App"
locations = get_locations(APP_NAME)
with open(locations.input_file, mode="rt") as f:
input_data = f.read().splitlines()- Create a Python virtual and install dependencies. E.g.
make install # runs uv sync- Run tests. E.g.
make test
# Or for more verbose logging
py -m unittest discover -v -s tests -p '*.py'-
Make any required updates to the
pyproject.tomlfile. E.g. theversionattribute. -
Build the package.
make build-distThis generates a dist folder in your project folder and uploads it to PyPi.
You'll be prompted for your API token. In my experience, when doing this from a terminal inside VS Code, Ctrl-V doesn't work here. So I use Paste from the menu, and this works.
And we're done!