项目作者: grimen

项目描述 :
My friendly library base class - for Python.
高级语言: Python
项目地址: git://github.com/grimen/python-mybase.git
创建时间: 2019-01-28T05:48:20Z
项目社区:https://github.com/grimen/python-mybase

开源协议:MIT License

下载


mybase Build Status PyPI version Coverage Status

My friendly library base class - for Python.

Introduction

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

Install using pip:

  1. $ pip install mybase

Use

Very basic example:

  1. from mybase import Base
  2. class Foo(Base):
  3. def hello():
  4. self.logger.log('hello from instance: `{0}`'.format(self))
  5. foo = Foo()
  6. # logs using default logger - with colors unless disabled via `COLORS` / `LOGGER_COLORS` env variables
  7. foo.hello()
  8. foo.logger.log('hello world 1')
  9. print(foo.name)
  10. print(repr(foo))
  11. print(str(foo))
  12. import logging
  13. foo2 = Foo(logger = logging.get_logger('custom'))
  14. # logs using custom logger
  15. foo.hello()
  16. foo.logger.log('hello world 2')
  17. foo3 = Foo(logger = False)
  18. # logs nothing
  19. foo.hello()
  20. foo.logger.log('hello world 3')

Test

Clone down source code:

  1. $ make install

Run colorful tests, with only native environment (dependency sandboxing up to you):

  1. $ make test

Run less colorful tests, with multi-environment (using tox):

  1. $ make test-tox
  • mybad - “My error base class - for Python”

About

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.

License

Released under the MIT license.