Skip to main content

Handy utility code, such as coloured logging.

Project description

Dazbo Commons

Table of Contents

Overview

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

To Install and Use

You can simply install the package from PyPi. There's no need to clone this repo.

pip install --upgrade dazbo-commons

Then, in your Python code, include this import:

import dazbo_commons as dc

Coloured Logging Module

This 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 level

File Locations Module

This 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()

Read Env File Module

This simply looks for a .env file in the current launch dir, and loads environment variables from it. If the file is not found, it searches in parent directories up to three directories higher.

import dazbo_commons as dc
dc.get_envs_from_file()

it not os.getenv('SOME_VAR'):
    os.environ['SOME_VAR'] = getpass('Enter your sensitive var: ')

To Build From Package Source

  1. Create a Python virtual environment and activate. E.g.
python3 -m venv .dazbo-commons-env
source .dazbo-commons-env/bin/activate
  1. Install dependent packages:
py -m pip install -r requirements.txt
  1. Run tests. E.g.
# Set env var so that the tests know how to find dazbo-commons
export PYTHONPATH=src
# Or in PS: $env:PYTHONPATH="src"

py -m unittest discover -v -s tests -p '*.py'

# Or, with pytest:
py -m pip install pytest
pytest
  1. Install packages for actually creating the build. (If not already included in requirements.txt):
py -m pip install twine
py -m pip install --upgrade build
  1. Make any required updates to the pyproject.toml file. E.g. the version attribute.

  2. Build the package.

py -m build

This generates a dist folder in your project folder.

  1. Upload the package to PyPi.

Notes:

  • You'll need to create a free account, if you haven't done so already.
  • You'll need to generate an API token in Account Settings, for uploading to the API.
  • You may want to delete any previous builds.
py -m twine upload dist/*

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dazbo_commons-0.1.5.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dazbo_commons-0.1.5-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file dazbo_commons-0.1.5.tar.gz.

File metadata

  • Download URL: dazbo_commons-0.1.5.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for dazbo_commons-0.1.5.tar.gz
Algorithm Hash digest
SHA256 f6de0ae593dda67bf7a119135c6a30bb1e010c2370ff0e31115ea4fbb7437a5d
MD5 c936f2499eb1ed65c8e8aa4f904c997e
BLAKE2b-256 c61521b01c2ffdb2c7b4ad77f2ee70b10b8b6c413fd3a903e5fc1bc8e27d1464

See more details on using hashes here.

File details

Details for the file dazbo_commons-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: dazbo_commons-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for dazbo_commons-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3fba269b44793851058b04ad8129c03fbd8865cf8b9601f616b6ddd9eebd9e21
MD5 7f48c2d8ba3162b332bff9828a26f2cf
BLAKE2b-256 064da50b396d7cfb136c4040e72d29a8ed539f4bf33ca8af72b7c1fa14be2540

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page