Easy functions for paths, logging and configuration files.
* For python 2.7 only.
Installation and development of polite uses the Anaconda Distribution (Python 2.7)
To install:
$ conda install -c dataonlygreater polite
Conda can be used to install dependencies into a dedicated environment from the source code root directory:
$ conda create -n _polite python=2.7 pip
Now activate the environment and use conda and pip to install the source code:
$ conda activate _polite
$ conda install --file requirements-conda-dev.txt
$ pip install -e .
To deactivate the conda environment:
$ conda deactivate
A test suite is provided with the source code that uses pytest.
If not already active, activate the conda environment set up in the Source Code section:
$ conda activate _polite
Install pytest to the environment (one time only):
$ conda install -y mock pytest pytest-mock
Run the tests:
$ pytest tests
To uninstall the conda package:
$ conda remove polite
To uninstall the source code and its conda environment:
$ conda remove --name _polite --all
An example of setting up logging using a user-specific yaml configuration file.
Copy the default logging file from the module source code to the user's data
directory (C:\Users\<USERNAME>\AppData\Roaming\DTOcean\polite
):
>>> from polite.paths import (DirectoryMap,
ObjDirectory,
UserDataDirectory)
>>> objdir = ObjDirectory("polite", "config")
>>> datadir = UserDataDirectory("polite", "DTOcean")
>>> dirmap = DirectoryMap(datadir, objdir)
>>> dirmap.copy_file("logging.yaml", overwrite=True)
>>> datadir.isfile("logging.yaml")
True
Use the copied configuration file to set up logging:
>>> from polite.configuration import Logger
>>> log = Logger(datadir)
>>> log_config_dict = log.read()
>>> log.configure_logger(log_config_dict)
>>> logger = log.add_named_logger("polite")
>>> logger.info("Hello World")
INFO - polite - Hello World
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
See this blog post for information regarding development of the DTOcean ecosystem.
Please make sure to update tests as appropriate.
This package was initially created as part of the EU DTOcean project by Mathew Topper at TECNALIA.
It is now maintained by Mathew Topper at Data Only Greater.