My friendly library base class - for Python.
One in general tend to need a library specific base class, but creating one for every new library with some common logger customization means redundant work every time. This library base class right now don't do much now beside setting up a default logger, but keeps library code a bit cleaner.
NOTE: Possibly should support being used as a mixin (e.g. @mybase.mixin) optionally, but not yet implemented.
Install using pip:
$ pip install mybaseVery basic example:
frommybaseimportBaseclassFoo(Base):
defhello():
self.logger.log('hello from instance: `{0}`'.format(self))
foo=Foo()
# logs using default logger - with colors unless disabled via `COLORS` / `LOGGER_COLORS` env variablesfoo.hello()
foo.logger.log('hello world 1')
print(foo.name)
print(repr(foo))
print(str(foo))
importloggingfoo2=Foo(logger=logging.get_logger('custom'))
# logs using custom loggerfoo.hello()
foo.logger.log('hello world 2')
foo3=Foo(logger=False)
# logs nothingfoo.hello()
foo.logger.log('hello world 3')Clone down source code:
$ make installRun colorful tests, with only native environment (dependency sandboxing up to you):
$ make testRun less colorful tests, with multi-environment (using tox):
$ make test-toxmybad- "My error base class - for Python"
This project was mainly initiated - in lack of solid existing alternatives - to be used at our work at Markable.ai to have common code conventions between various programming environments where Python (research, CV, AI) is heavily used.
Released under the MIT license.