A repository for Python-based experimentations (labs).
Currently, the library has only been tested with Python 3.6.6.
To install everything using pip, issue the following commands from the project root directory:
- pip install -r requirements.txt
- pip install -e .
- pip install -e config/
Leave out the -e switch if you want to install the packages into your Python site folder.
You can also use the equivalent Python setup commands:
- pip install -r requirements.txt
- python setup.py develop (or install)
- python config/setup.py develop (or install)
from mylabs.client.image import App
a = App.Load()
img = a.resizeImagePNG(
src_path,
dst_path,
width,
height=height,
ratio=ratio,
resample=resample
)
All configuration is done using a framework that sets items to a Python dict when the app is loaded. When App.Load()
is invoked, it will call its config manager type to populate the app's config
member variable.
>>> from mylabs.client.files import App
>>> a = App.Load()
>>> a.config
{'.NS': 'mylabs',
'mylabs.prefix': 'files',
'mylabs.now_dt': datetime.datetime(2018, 8, 13, 14, 33, 30, 175158),
'mylabs.working_dir': '/home/hendrix/dev/pymylabs',
'mylabs.level_code': 10,
'mylabs.logging_dir': '/home/hendrix/dev/pymylabs/logs',
...
}
For convenience, you can access and update configuration items using a namespace type variable.
>>> NS = a.config['.NS']
>>> NS
'mylabs'
>>> RootNS = a.RootNS
>>> assert NS == RootNS
>>> assert NS == 'mylabs'
>>> a.config[NS.logging_dir]
'/home/hendrix/dev/pymylabs/logs'
>>> NS.logging_dir
'mylabs.logging_dir'
>>> a.config['mylabs.logging_dir']
'/home/hendrix/dev/pymylabs/logs'
To access the settings for the regex and whoosh analyzers associated with this app, you can do something like the following:
>>> aNS = NS.analyzers
>>> aNS
'mylabs.analyzers'
>>> a.config[aNS.regex]
{}
>>> whoosh_settings = a.config[aNS.whoosh]
>>> whoosh_settings
{'index_dir': 'wtf_index', 'word_ngrams_max': 3, 'slop_factor': 2}
>>> whoosh_settings['index_dir'] = 'new_wtf_index'
From the project directory, you can find the default configuration modules in the subfolder: config/mylabs_c
So the configuration module for the interactor app type: mylabs.client.image.App
Is the corresponding matching config type: mylabs_c.client.image.App
To update the default values, see file: config/mylabs_c/client/image/__init__.py
If you do not install the mylabs_c package, the root config path must be included in your PYTHONPATH environment variable so that the configuration modules can be imported when App.Load()
is called.
If running App.Load()
throws ModuleNotFoundError type exceptions, verify that under your environment you can import both these modules without any errors.
>>> import mylabs
>>> import mylabs_c
>>>
When executing the library with an app interactor type, log messages will be outputted to files. The configuration settings for logging can be accessed as follows:
>>> a.config[NS.logging_dir]
'/home/hendrix/dev/pymylabs/logs'
>>> a.logger
<Logger mylabs.client.files (INFO)>
>>> a.config[NS.logging]
{'version': 1,
'disable_existing_loggers': False,
'formatters': {'simple': {'format': '%(asctime)s|%(name)s|%(levelname)s: %(message)s'}},
'handlers': {'console': {'class': 'logging.StreamHandler',
'level': 'CRITICAL',
'formatter': 'simple',
'stream': 'ext://sys.stdout'},
'info_file_handler': {'class': 'logging.handlers.RotatingFileHandler',
'level': 'INFO',
'formatter': 'simple',
'filename': '/home/hendrix/dev/pymylabs/logs/files-2018_08_13_14_33_30-info.log',
'maxBytes': 10485760,
'backupCount': 20,
'encoding': 'utf8'},
...
}
By default, in the log folder there will be two files for critical and non-critical messages respectively.
This library is being developed using the agile principles of test-driven development (TDD) and continous integration (CI).
Testing is done with Pytest.
This repository is connected to Travis-CI.
Experimental Features will be added when necessart.