Scruffy
=======
.. image:: https://img.shields.io/travis/snare/scruffy.svg
:target: https://travis-ci.org/snare/scruffy
.. image:: https://img.shields.io/pypi/format/scruffington.svg
:target: https://pypi.python.org/pypi/scruffington
.. image:: https://readthedocs.org/projects/scruffy/badge/?version=latest
:target: http://scruffy.readthedocs.org/en/latest/
*Scruffy. The Janitor.*
Scruffy is a framework for taking care of a bunch of boilerplate in Python apps. It handles the loading of configuration files, the loading and management of plugins, and the management of other filesystem resources such as temporary files and directories, log files, etc.
A typical use case for Scruffy is a command-line Python tool with some or all of the following requirements:
* Read a set of configuration defaults
* Read a local configuration file and apply it on top of the defaults
* Allow overriding some configuration options with command line flags or at runtime
* Load a core set of Python-based plugins
* Load a set of user-defined Python-based plugins
* Generate log files whose name, location and other logging settings are based on configuration
* Store application state between runs in a file or database
Scruffy is used by Voltron_ and Calculon_
.. _Voltron: https://github.com/snare/voltron
.. _Calculon: https://github.com/snare/calculon
Installation
------------
A standard python setup script is included.
$ python setup.py install
This will install the Scruffy package wherever that happens on your system.
Alternately, Scruffy can be installed with `pip` from PyPi (where it's called `scruffington`, because I didn't check for a conflict before I named it).
$ pip install scruffington
Documentation
-------------
Full documentation is hosted at readthedocs_
.. _readthedocs: http://scruffy.readthedocs.io/
Quick start
-----------
Config
~~~~~~
Load a user config file, and apply it on top of a set of defaults loaded from inside the Python package we're currently running from.
*thingy.yaml*:
.. code:: yaml
some_property: 1
other_property: a thing
*thingy.py*:
.. code:: python
from scruffy import ConfigFile
c = ConfigFile('thingy.yaml', load=True,
defaults=File('defaults.yaml', parent=PackageDirectory())
)
print("c.some_property == {c.some_property}".format(c=c))
print("c.other_property == {c.other_property}".format(c=c))
Run it:
::
$ python thingy.py
c.some_property == 1
c.other_property == a thing
Plugins
~~~~~~~
Load some plugins.
*~/.thingy/plugins/example.py*:
.. code:: python
from scruffy import Plugin
class ExamplePlugin(Plugin):
def do_a_thing(self):
print('{}.{} is doing a thing'.format(__name__, self.__class__.__name__))
*thingy.py*:
.. code:: python
from scruffy import PluginDirectory, PluginRegistry
pd = PluginDirectory('~/.thingy/plugins')
pd.load()
for p in PluginRegistry.plugins:
print("Initialising plugin {}".format(p))
p().do_a_thing()
Run it:
::
$ python thingy.py
Initialising plugin <class 'example.ExamplePlugin'>
example.ExamplePlugin is doing a thing
Logging
~~~~~~~
Scruffy's `LogFile` class will do some configuration of Python's `logging` module.
*log.py*:
.. code:: python
import logging
from scruffy import LogFile
log = logging.getLogger('main')
log.setLevel(logging.INFO)
LogFile('/tmp/thingy.log', logger='main').configure()
log.info('Hello from log.py')
*/tmp/thingy.log*:
::
Hello from log.py
Environment
~~~~~~~~~~~
Scruffy's `Environment` class ties all the other stuff together. The other classes can be instantiated as named children of an `Environment`, which will load any `Config` objects, apply the configs to the other objects, and then prepare the other objects.
*~/.thingy/config*:
.. code:: yaml
log_dir: /tmp/logs
log_file: thingy.log
*env.py*:
.. code:: python
from scruffy import *
e = Environment(
main_dir=Directory('~/.thingy', create=True,
config=ConfigFile('config', defaults=File('defaults.yaml', parent=PackageDirectory())),
lock=LockFile('lock')
user_plugins=PluginDirectory('plugins')
),
log_dir=Directory('{config:log_dir}', create=True
LogFile('{config:log_file}', logger='main')
),
pkg_plugins=PluginDirectory('plugins', parent=PackageDirectory())
)
License
-------
See LICENSE file. If you use this and don't hate it, buy me a beer at a conference some time.
Credits
-------
Props to richo_. Flat duck pride.
.. _richo: http://github.com/richo
Raw data
{
"_id": null,
"home_page": "https://github.com/snare/scruffy",
"name": "scruffington",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "scruffy",
"author": "snare",
"author_email": "snare@ho.ax",
"download_url": "https://files.pythonhosted.org/packages/90/6f/58d8fc9750db4d5d14c37f96ab1b604679adf9f02e447c4cfe1055207477/scruffington-0.3.9.tar.gz",
"platform": null,
"description": "Scruffy\n=======\n\n.. image:: https://img.shields.io/travis/snare/scruffy.svg\n :target: https://travis-ci.org/snare/scruffy\n\n.. image:: https://img.shields.io/pypi/format/scruffington.svg\n :target: https://pypi.python.org/pypi/scruffington\n\n.. image:: https://readthedocs.org/projects/scruffy/badge/?version=latest\n :target: http://scruffy.readthedocs.org/en/latest/\n\n\n*Scruffy. The Janitor.*\n\nScruffy is a framework for taking care of a bunch of boilerplate in Python apps. It handles the loading of configuration files, the loading and management of plugins, and the management of other filesystem resources such as temporary files and directories, log files, etc.\n\nA typical use case for Scruffy is a command-line Python tool with some or all of the following requirements:\n\n* Read a set of configuration defaults\n* Read a local configuration file and apply it on top of the defaults\n* Allow overriding some configuration options with command line flags or at runtime\n* Load a core set of Python-based plugins\n* Load a set of user-defined Python-based plugins\n* Generate log files whose name, location and other logging settings are based on configuration\n* Store application state between runs in a file or database\n\nScruffy is used by Voltron_ and Calculon_\n\n.. _Voltron: https://github.com/snare/voltron\n.. _Calculon: https://github.com/snare/calculon\n\nInstallation\n------------\n\nA standard python setup script is included.\n\n $ python setup.py install\n\nThis will install the Scruffy package wherever that happens on your system.\n\nAlternately, Scruffy can be installed with `pip` from PyPi (where it's called `scruffington`, because I didn't check for a conflict before I named it).\n\n $ pip install scruffington\n\nDocumentation\n-------------\n\nFull documentation is hosted at readthedocs_\n\n.. _readthedocs: http://scruffy.readthedocs.io/\n\nQuick start\n-----------\n\nConfig\n~~~~~~\n\nLoad a user config file, and apply it on top of a set of defaults loaded from inside the Python package we're currently running from.\n\n*thingy.yaml*:\n\n.. code:: yaml\n\n some_property: 1\n other_property: a thing\n\n*thingy.py*:\n\n.. code:: python\n\n from scruffy import ConfigFile\n\n c = ConfigFile('thingy.yaml', load=True,\n defaults=File('defaults.yaml', parent=PackageDirectory())\n )\n\n print(\"c.some_property == {c.some_property}\".format(c=c))\n print(\"c.other_property == {c.other_property}\".format(c=c))\n\nRun it:\n\n::\n\n $ python thingy.py\n c.some_property == 1\n c.other_property == a thing\n\nPlugins\n~~~~~~~\n\nLoad some plugins.\n\n*~/.thingy/plugins/example.py*:\n\n.. code:: python\n\n from scruffy import Plugin\n\n class ExamplePlugin(Plugin):\n def do_a_thing(self):\n print('{}.{} is doing a thing'.format(__name__, self.__class__.__name__))\n\n*thingy.py*:\n\n.. code:: python\n\n from scruffy import PluginDirectory, PluginRegistry\n\n pd = PluginDirectory('~/.thingy/plugins')\n pd.load()\n\n for p in PluginRegistry.plugins:\n print(\"Initialising plugin {}\".format(p))\n p().do_a_thing()\n\nRun it:\n\n::\n\n $ python thingy.py\n Initialising plugin <class 'example.ExamplePlugin'>\n example.ExamplePlugin is doing a thing\n\nLogging\n~~~~~~~\n\nScruffy's `LogFile` class will do some configuration of Python's `logging` module.\n\n*log.py*:\n\n.. code:: python\n\n import logging\n from scruffy import LogFile\n\n log = logging.getLogger('main')\n log.setLevel(logging.INFO)\n LogFile('/tmp/thingy.log', logger='main').configure()\n\n log.info('Hello from log.py')\n\n*/tmp/thingy.log*:\n\n::\n\n Hello from log.py\n\nEnvironment\n~~~~~~~~~~~\n\nScruffy's `Environment` class ties all the other stuff together. The other classes can be instantiated as named children of an `Environment`, which will load any `Config` objects, apply the configs to the other objects, and then prepare the other objects.\n\n*~/.thingy/config*:\n\n.. code:: yaml\n\n log_dir: /tmp/logs\n log_file: thingy.log\n\n*env.py*:\n\n.. code:: python\n\n from scruffy import *\n\n e = Environment(\n main_dir=Directory('~/.thingy', create=True,\n config=ConfigFile('config', defaults=File('defaults.yaml', parent=PackageDirectory())),\n lock=LockFile('lock')\n user_plugins=PluginDirectory('plugins')\n ),\n log_dir=Directory('{config:log_dir}', create=True\n LogFile('{config:log_file}', logger='main')\n ),\n pkg_plugins=PluginDirectory('plugins', parent=PackageDirectory())\n )\n\nLicense\n-------\n\nSee LICENSE file. If you use this and don't hate it, buy me a beer at a conference some time.\n\nCredits\n-------\n\nProps to richo_. Flat duck pride.\n\n.. _richo: http://github.com/richo\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "The janitor",
"version": "0.3.9",
"project_urls": {
"Homepage": "https://github.com/snare/scruffy"
},
"split_keywords": [
"scruffy"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "dfabbab06583872a571e420da5cef8ad156de57269d9ae12915c087c954986cf",
"md5": "88272aa578a7db5ac4a5866cc76f0970",
"sha256": "290736f5d55502f3d939cc125e0cd0a143c2ef8606de1bcc4b083ff2404f4573"
},
"downloads": -1,
"filename": "scruffington-0.3.9-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "88272aa578a7db5ac4a5866cc76f0970",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 14198,
"upload_time": "2025-01-30T00:14:14",
"upload_time_iso_8601": "2025-01-30T00:14:14.149347Z",
"url": "https://files.pythonhosted.org/packages/df/ab/bab06583872a571e420da5cef8ad156de57269d9ae12915c087c954986cf/scruffington-0.3.9-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "906f58d8fc9750db4d5d14c37f96ab1b604679adf9f02e447c4cfe1055207477",
"md5": "8e22e582758244632cae2858f0ecf138",
"sha256": "c5a0accb943fd532f2e6ee9e98ae2ac97032246a6b8393a180038a24c11096ed"
},
"downloads": -1,
"filename": "scruffington-0.3.9.tar.gz",
"has_sig": false,
"md5_digest": "8e22e582758244632cae2858f0ecf138",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12127,
"upload_time": "2025-01-30T00:14:16",
"upload_time_iso_8601": "2025-01-30T00:14:16.539622Z",
"url": "https://files.pythonhosted.org/packages/90/6f/58d8fc9750db4d5d14c37f96ab1b604679adf9f02e447c4cfe1055207477/scruffington-0.3.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-30 00:14:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "snare",
"github_project": "scruffy",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "PyYAML",
"specs": [
[
">=",
"3.11"
]
]
},
{
"name": "six",
"specs": [
[
">=",
"1.10.0"
]
]
}
],
"lcname": "scruffington"
}