Skip to content

happyfaults/pymylabs

Repository files navigation

PyMyLabs

A repository for Python-based experimentations (labs).

Quick Install

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:

  1. pip install -r requirements.txt
  2. pip install -e .
  3. 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:

  1. pip install -r requirements.txt
  2. python setup.py develop (or install)
  3. python config/setup.py develop (or install)

Features

Image Utils

From mylabs.client.image.App

from mylabs.client.image import App
a = App.Load()

Dependencies:

  1. Pillow (PIL)

Resize PNG Images - Preserving Transparent Background

img = a.resizeImagePNG(
    src_path, 
    dst_path, 
    width,
    height=height,
    ratio=ratio,
    resample=resample
)

Configuration

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',
...
}

Namespaces

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'

Config Modules

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

Ensure Config Modules Can Be Imported

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
>>> 

Logging

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.

TDD & CI

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.

Development Roadmap

Experimental Features will be added when necessart.

About

A repository for Python-based experimentation.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages