BE Helpers
Custom brainelectronics python helper modules
General
Collection of custom brainelectronics specific python helper modules.
Installation
pip install be-helpers
Usage
from be_helpers import ModuleHelper
import time
from pathlib import Path
# default name is 'be_helpers.module_helper'
my_logger = ModuleHelper.create_logger()
# set logger level to INFO
ModuleHelper.set_logger_verbose_level(logger=my_logger, verbose_level=3)
# check 'a' to be an option of ['a', 'b', 'c'], result will be True
result = ModuleHelper.check_option_values(options=['a', 'b', 'c'], option='a')
print('"a" is an option of ["a", "b", "c"]: {}'.format(result))
# "a" is an option of ["a", "b", "c"]: True
# get current unix timestamp and format it
now = ModuleHelper.get_unix_timestamp()
time_format = "%H:%M:%S"
print('{}'.format(ModuleHelper.format_timestamp(timestamp=now, format=time_format)))
# 11:30:01
# create a random character number string of length 10
print('{}'.format(ModuleHelper.get_random_string(length=10)))
# 235LS5AY6BPC
# convert a string to a "uint16_t" list, useful for Modbus communications
result = ModuleHelper.convert_string_to_uint16t(content="test")
print('"test" as uint16_t: {}'.format(result))
# "test" as uint16_t: [29797, 29556]
# check for valid files or folders
here = ModuleHelper.get_full_path('.')
ModuleHelper.check_file(here / 'README.md', '.md')
# True
ModuleHelper.check_folder(here)
# True
# load YAML or JSON files as dictionaries
config = ModuleHelper.load_dict_from_file(here / 'tests/data/valid.json')
config = ModuleHelper.load_dict_from_file(here / 'tests/data/valid.yaml')
# {'key': 'val', 'key2': {'key_nested': 'val_nested'}, 'key3': ['asdf', 123, {'key4': 'val4'}]}
# save dictionaries as JSON or YAML files
ModuleHelper.save_dict_to_file(path=here / 'example/cfg.json', content=config)
ModuleHelper.save_dict_to_file(path=here / 'example/cfg.yaml', content=config)
# True
Contributing
Unittests
Run the unittests locally with the following command after installing this package in a virtual environment
# run all tests
nose2 --config tests/unittest.cfg
# run only one specific tests
nose2 tests.test_module_helper.TestModuleHelper.test_set_logger_verbose_level
Generate the coverage files with
python create_report_dirs.py
coverage html
The coverage report is placed at be-helpers/reports/coverage/html/index.html
Credits
Based on the PyPa sample project.
Metadata
Release files for be-helpers 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| be-helpers-0.1.0.tar.gz | 12.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| be_helpers-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.9 kB
Release files / be-helpers-0.1.0.tar.gz
| Download URL | be-helpers-0.1.0.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d23f8ea1e72acdf1281b7808165140625620bfd07cdfaa5a8d72bbe972b4f942
|
|
BLAKE2b-256 checksum How to use checksums |
51c1ab693587774117e3d1f8426b65f7685c69a6ccdc61d3ba6ea69725217444
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.14
|
Release files / be_helpers-0.1.0-py3-none-any.whl
| Download URL | be_helpers-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5c9a78325967fac71d6da16bc18be7114f52e02c6e4eb3c8d8cb0fe8548acaba
|
|
BLAKE2b-256 checksum How to use checksums |
a972705d21fb0ad31ffb1ff8f82533b4c65aa81622edeb3232ef86464a1d71ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.14
|