commit 99f33f56b2dda19b5d430d323f93c988d70bc5ea Author: Dave Shawley Date: Sat Mar 28 12:33:29 2015 -0400 SYN diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..67b480a --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +__pycache__/ +build/ +dist/ +env/ +*.egg-info/ +*.sw[op] +*.egg +*.pyc +.coverage +LOCAL-VERSION diff --git a/HISTORY.rst b/HISTORY.rst new file mode 100644 index 0000000..ffa8a35 --- /dev/null +++ b/HISTORY.rst @@ -0,0 +1,7 @@ +Version History +--------------- + +0.0.0 +~~~~~ + - Nothing to see here + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3c72859 --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) 2015 AWeber Communications +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of Sprockets nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..75e26f9 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,7 @@ +include LICENSE +include README.rst +include *requirements.txt +include tests.py +graft docs +global-exclude __pycache__ +global-exclude *.pyc diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..dbf56e5 --- /dev/null +++ b/README.rst @@ -0,0 +1,88 @@ +sprockets.mixins.correlation +============================ + +|Version| |Downloads| |Status| |Coverage| |License| |Documentation| + +This sprocket provides a single mix-in that imbues your ``RequestHandler`` +with a unique correlation ID. If a correlation ID is present upon input then +it will be preserved in the output. It is also available for your use as +the ``correlation_id`` property. + +Installation +------------ + +``sprockets.mixins.correlation`` is available on the `Python Package Index`_ +and can be installed via ``pip``: + +.. code-block:: shell + + $ pip install sprockets.mixins.correlation + +Example +------- + +.. code-block:: python + + from sprockets.mixins import correlation + from tornado import ioloop, web + + class Handler(correlation.HandlerMixin, web.RequestHandler): + def get(self): + self.finish('my id is {0}'.format(self.correlation_id) + + if __name__ == '__main__': + application = web.Application([('/', Handler)]) + application.listen(8888) + ioloop.IOLoop.instance().start() + +Generated Correlation ID +~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: http + + GET / HTTP/1.1 + Host: localhost:8888 + Connection: keep-alive + +.. code-block:: http + + HTTP/1.1 200 OK + Correlation-ID: 0a2b6080-e4da-43bf-a2a5-38d861846cb9 + Content-Length: 44 + + my id is 0a2b6080-e4da-43bf-a2a5-38d861846cb9 + +Relayed Correlation ID +~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: http + + GET / HTTP/1.1 + Host: localhost:8888 + Connection: keep-alive + Correlation-Id: 4676922073c4c59b1f5e6b4a18894bd46f867316 + +.. code-block:: http + + HTTP/1.1 200 OK + Correlation-ID: 4676922073c4c59b1f5e6b4a18894bd46f867316 + Connection: close + Content-Length: 48 + + my id is 4676922073c4c59b1f5e6b4a18894bd46f867316 + + +.. |Version| image:: https://img.shields.io/pypi/v/sprockets.mixins.correlation.svg + :target: https://pypi.python.org/pypi/sprockets.mixins.correlation +.. |Status| image:: https://img.shields.io/travis/sprockets/sprockets.mixins.correlation.svg + :target: https://travis-ci.org/sprockets/sprockets.mixins.correlation +.. |Coverage| image:: https://img.shields.io/coveralls/sprockets/sprockets.mixins.correlation.svg + :target: http://coveralls.io/r/sprockets/sprockets.mixins.correlation +.. |Downloads| image:: https://img.shields.io/pypi/dm/sprockets.mixins.correlation.svg + :target: https://pypi.python.org/pypi/sprockets.mixins.correlation +.. |License| image:: https://pypip.in/license/sprockets.mixins.correlation/badge.svg + :target: https://sprocketsmixinscorrelation.readthedocs.org/ +.. |Documentation| image:: https://readthedocs.org/projects/sprocketsmixinscorrelation/badge + :target: https://sprocketsmixinscorrelation.readthedocs.org/ + +.. _Python Package Index: https://pypi.python.org/pypi/sprockets.mixins.correlation diff --git a/dev-requirements.txt b/dev-requirements.txt new file mode 100644 index 0000000..4e8c0ae --- /dev/null +++ b/dev-requirements.txt @@ -0,0 +1,6 @@ +-r requirements.txt +-r test-requirements.txt +flake8>=2.1,<3 +sphinx>=1.2,<2 +sphinx-rtd-theme>=0.1,<1.0 +tornado>=4.0,<5 diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..1c7d13c --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,24 @@ +import sphinx_rtd_theme +from sprockets.mixins.correlation import version_info, __version__ + +needs_sphinx = '1.0' +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.intersphinx', +] +templates_path = [] +source_suffix = '.rst' +master_doc = 'index' +project = 'sprockets.mixins.correlation' +copyright = '2015, AWeber Communications' +version = '.'.join(__version__.split('.')[0:1]) +release = __version__ +if len(version_info) > 3: + release += '-{0}'.format(str(v) for v in version_info[3:]) +exclude_patterns = [] +pygments_style = 'sphinx' +html_theme = 'sphinx_rtd_theme' +html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] +intersphinx_mapping = { + 'python': ('https://docs.python.org/', None), +} diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..949f3f3 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,23 @@ +.. include:: ../README.rst + +Contributing to this Library +---------------------------- + +The easiest way to start working with this code is to set up a virtual +environment and run ``env/bin/pip -r dev-requirements.txt``. That will +install the necessary testing tools. Then you can run everything else +using ``env/bin/python setup.py``: + +- *setup.py nosetests* will run the tests using nose to test against the + and generate a coverage report to stdout. + +- *setup.py build_sphinx* will generate HTML documentation into + *build/doc/html*. This is the doc set that is uploaded to Read The Docs. + +- *setup.py flake8* will run the ``flake8`` utility and report on any + static code analysis failures. + +This library follows the standard fork, modify, and pull request flow +for contributing. + +.. include:: ../HISTORY.rst diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..a3c2d9b --- /dev/null +++ b/setup.cfg @@ -0,0 +1,18 @@ +[bdist_wheel] +universal = 1 + +[build_sphinx] +all-files = 1 + +[flake8] +exclude = build,dist,docs,env + +[nosetests] +tests = tests.py +nocapture = 1 +verbose = 1 +stop = 1 +with-coverage = 1 +cover-erase = 1 +cover-branches = 1 +cover-package = sprockets diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..27435c0 --- /dev/null +++ b/setup.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +import codecs +import sys + +import setuptools + +from sprockets.mixins import correlation + + +def read_requirements_file(req_name): + requirements = [] + try: + with codecs.open(req_name, encoding='utf-8') as req_file: + for req_line in req_file: + if '#' in req_line: + req_line = req_line[0:req_line.find('#')].strip() + if req_line: + requirements.append(req_line.strip()) + except IOError: + pass + return requirements + + +install_requires = read_requirements_file('requirements.txt') +setup_requires = read_requirements_file('setup-requirements.txt') +tests_require = read_requirements_file('test-requirements.txt') + +setuptools.setup( + name='sprockets.mixins.correlation', + version=correlation.__version__, + description='Stuff to correlate requests, logs, and the like', + long_description=codecs.open('README.rst', encoding='utf-8').read(), + url='https://github.com/sprockets/sprockets.mixins.correlation.git', + author='AWeber Communications', + author_email='api@aweber.com', + license=codecs.open('LICENSE', encoding='utf-8').read(), + classifiers=[ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Natural Language :: English', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', + 'Topic :: Software Development :: Libraries', + 'Topic :: Software Development :: Libraries :: Python Modules' + ], + packages=setuptools.find_packages(), + namespace_packages=['sprockets'], + install_requires=install_requires, + setup_requires=setup_requires, + tests_require=tests_require, + test_suite='nose.collector', + zip_safe=True, +) diff --git a/sprockets/__init__.py b/sprockets/__init__.py new file mode 100644 index 0000000..de40ea7 --- /dev/null +++ b/sprockets/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/sprockets/mixins/__init__.py b/sprockets/mixins/__init__.py new file mode 100644 index 0000000..de40ea7 --- /dev/null +++ b/sprockets/mixins/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/sprockets/mixins/correlation/__init__.py b/sprockets/mixins/correlation/__init__.py new file mode 100644 index 0000000..9969ce6 --- /dev/null +++ b/sprockets/mixins/correlation/__init__.py @@ -0,0 +1,2 @@ +version_info = (0, 0, 0) +__version__ = '.'.join(str(v) for v in version_info[:3]) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..dc209eb --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,4 @@ +coverage>=3.7,<4 +coveralls>=0.4,<1 +nose>=1.3,<2 +tox>=1.7,<2 diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..e69de29 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..36947a8 --- /dev/null +++ b/tox.ini @@ -0,0 +1,15 @@ +[tox] +envlist = py27,py33,py34,pypy,pypy3 +toxworkdir = {toxinidir}/build/tox +skip_missing_intepreters = true + +[testenv] +deps = + -rtest-requirements.txt + tornado +commands = {envbindir}/nosetests + +[testenv:py27] +deps = + {[testenv]deps} + mock