misc tools for configs, logs
Project description
hao
configurations, logs and others.
install
pip install hao
features
Precondition: The folder contained any of the following files (searched in this very order) will be treated as project root path.
- requirements.txt
- VERSION
- conf
- setup.py
- .idea
- .git
If your project structure does NOT conform to this, it will not work as expected.
config
It will try to load YAML config file from folder: ${project_root_path}/conf/
, by following order:
if os.environ.get("env") is not None:
try_to_load(f'config-{env}.yml', fallback='config.yml') # echo $env
else:
try_to_load(f'config-{socket.gethostname()}.yml', fallback='config.yml') # echo hostname
Say you have the following content in your config file:
es:
default:
host: 172.23.3.3
port: 9200
indices:
- news
- papers
The get the configured values in your code:
import hao
es_host = hao.config.get('es.default.host') # str
es_port = hao.config.get('es.default.port') # int
indices = hao.config.get('es.default.indices') # list
...
logs
Set the logger level in config.yml
e.g.
logging:
__main__: DEBUG
transformers: WARNING
lightning: INFO
pytorch_lightning: INFO
elasticsearch: WARNING
tests: DEBUG
root: INFO # root level
If you want to change the log format:
logger:
format: "%(asctime)s %(levelname)-7s %(name)s:%(lineno)-4d - %(message)s"
Declear your logger
``python import hao LOGGER = hao.logs.get_logger(name)
### namespaces
```python
from spanner.namespaces import from_args, attr
@from_args
#@from_args(adds=Trainer.add_argparse_args)
class TrainConf(Namespace):
root_path_checkpoints = attr(str, default=hao.paths.get_path('data/checkpoints/'))
dataset_train = attr(str, default='train.txt')
dataset_val = attr(str, default='val.txt')
dataset_test = attr(str, default='test.txt')
batch_size = attr(int, default=128, key='train.batch_size') # key means try to load from config.yml by the key
task = attr(str, choices=('ner', 'nmt'), default='ner')
seed = attr(int)
epochs = attr(int, default=5)
Where attr
is a wrapper for argpars.add_argument()
Usage 1: overwrite the default value from command line
python -m your_module --task=nmt
Usage 2: overwrite the default value from constructor
train_conf = TrainConf(task='nmt')
Value lookup order:
- command line
- constructor
- config yml if
key
specified inattr
default
if specified inattr
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hao-0.0.2.tar.gz
.
File metadata
- Download URL: hao-0.0.2.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cda451e69c47c61814f3e492c40531c70c69aa8afd731a781a3ba8e6ac980b7b |
|
MD5 | 672c1af526e4ec994c9b0021a42e939e |
|
BLAKE2b-256 | 173f0d4dfe144241424e97b0be9e7dc162f9da92f116c1b4d28647a0b0c2222c |
File details
Details for the file hao-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: hao-0.0.2-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ca9ed06627976b35d99261549bbe37e2d819ff18c762ce203a188b6bdc2e15c |
|
MD5 | 23a1c982e032a7227b831be0fcb5b2b6 |
|
BLAKE2b-256 | 5dfb76a72aa2ed0c16498e7b9c3c95c01dcf618bc1d7a86184060a5eb7f2515d |