diff --git a/.bumpversion.cfg b/.bumpversion.cfg index df3d3b6..fc03de0 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.1.0 +current_version = 0.2.0 files = setup.py flask_docker.py docs/conf.py commit = True tag = False diff --git a/CHANGELOG.rst b/CHANGELOG.rst new file mode 100644 index 0000000..b0db0ac --- /dev/null +++ b/CHANGELOG.rst @@ -0,0 +1,14 @@ +Changelog +--------- + +0.2.0 - 2015-06-08 +~~~~~~~~~~~~~~~~~~ + +* Make ``app`` attribute always be accessible in :class:`flask_docker.Docker`. +* Add ``zip_safe=False`` flag to ``setup.py``. +* Fix some description in the document. + +0.1.0 - 2015-02-01 +~~~~~~~~~~~~~~~~~~ + +* Initial release. diff --git a/README.rst b/README.rst index 4b0142b..42a7891 100644 --- a/README.rst +++ b/README.rst @@ -3,13 +3,17 @@ Flask-Docker ============ -Flask-Docker is an extension for Flask_ that integrates a Docker_ client into -your application. It is based on the official docker-py_. +Flask-Docker is an extension for Flask_ that integrates Docker_ client into +your application. It is based on the official client docker-py_. .. _Flask: http://flask.pocoo.org .. _Docker: https://www.docker.com .. _docker-py: https://github.com/docker/docker-py#readme +The document is in ReadTheDocs_. + +.. _ReadTheDocs: https://flask-docker.readthedocs.org + Installation ------------ @@ -40,7 +44,7 @@ You can send a pull reueqst on .. |Coverage Status| image:: https://img.shields.io/coveralls/tonyseek/flask-docker.svg?style=flat :target: https://coveralls.io/r/tonyseek/flask-docker :alt: Coverage Status -.. |Wheel Status| image:: https://pypip.in/wheel/Flask-Docker/badge.svg?style=flat +.. |Wheel Status| image:: https://img.shields.io/pypi/wheel/Flask-Docker.svg?style=flat :target: https://warehouse.python.org/project/Flask-Docker :alt: Wheel Status .. |PyPI Version| image:: https://img.shields.io/pypi/v/Flask-Docker.svg?style=flat diff --git a/docs/conf.py b/docs/conf.py index 821a154..5ce7ccd 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -55,9 +55,9 @@ # built documents. # # The short X.Y version. -version = '0.1.0' +version = '0.2.0' # The full version, including alpha/beta/rc tags. -release = '0.1.0' +release = '0.2.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/index.rst b/docs/index.rst index 9fe9396..c60cc5b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -19,7 +19,7 @@ Installation Configuration ------------- -You can configure it like mostly extensions of Flask. +You can configure it like most extensions of Flask. For single file applications: @@ -52,7 +52,6 @@ For large applications which following the application factory pattern: The Flask-Docker has some configuration values that describes how to connect to the Docker server. - ============================ ================================================== `DOCKER_URL` The URL of Docker server. **REQUIRED** `DOCKER_VERSION` The API version of Docker server. @@ -76,8 +75,8 @@ to the Docker server. certificate. Because the client certificate have two files (a public and a private), this configuration value - should be a tuple of their path. (e.g. - ``('/path/to/cert.pem', '/path/to/key.pem')``) + should be a colon-separated tuple of their path. + (e.g. ``"/path/to/cert.pem:/path/to/key.pem"``) This defaults to ``None``. `DOCKER_TLS_CA_CERT` The file path to the CA certificate. It is usually be used with a self-signed @@ -86,9 +85,8 @@ to the Docker server. `DOCKER_TLS_CERT_PATH` This defaults to ``None``. Once it be specified, The default value of `DOCKER_TLS_CLIENT_CERT` and `DOCKER_TLS_CA_CERT` will be filled to - ``("{DOCKER_TLS_CERT_PATH}/cert.pem", - "{DOCKER_TLS_CERT_PATH}/key.pem")`` and - ``"{DOCKER_TLS_CERT_PATH}/ca.pem"`` instead of + ``"{0}/cert.pem:{0}/key.pem"`` and + ``"{0}/ca.pem"`` instead of ``None``. It is usually be used with boot2docker_. ============================ ================================================== @@ -146,3 +144,5 @@ API Reference .. autoclass:: flask_docker.Docker :members: + +.. include:: ../CHANGELOG.rst diff --git a/flask_docker.py b/flask_docker.py index b62753a..ca2506c 100644 --- a/flask_docker.py +++ b/flask_docker.py @@ -6,7 +6,7 @@ __all__ = ['Docker'] -__version__ = '0.1.0' +__version__ = '0.2.0' class Docker(object): @@ -17,7 +17,9 @@ class Docker(object): """ def __init__(self, app=None): - if app: + if app is None: + self.app = current_app + else: self.app = app self.init_app(app) @@ -49,18 +51,16 @@ def client(self): docker.create_container('ubuntu') docker.client.create_container('ubuntu') # equivalent """ - app = getattr(self, 'app', current_app) - - if not app.config['DOCKER_URL']: + if not self.app.config['DOCKER_URL']: raise RuntimeError('"DOCKER_URL" must be specified') - if not app.extensions['docker.client']: - app.extensions['docker.client'] = Client( - base_url=app.config['DOCKER_URL'], - version=app.config['DOCKER_VERSION'], - timeout=app.config['DOCKER_TIMEOUT'], - tls=make_tls_config(app.config)) - return app.extensions['docker.client'] + if not self.app.extensions['docker.client']: + self.app.extensions['docker.client'] = Client( + base_url=self.app.config['DOCKER_URL'], + version=self.app.config['DOCKER_VERSION'], + timeout=self.app.config['DOCKER_TIMEOUT'], + tls=make_tls_config(self.app.config)) + return self.app.extensions['docker.client'] def __getattr__(self, name): if name != 'app' and hasattr(self.client, name): diff --git a/setup.py b/setup.py index 5ed1f4f..32dd76e 100644 --- a/setup.py +++ b/setup.py @@ -9,9 +9,9 @@ setup( name='Flask-Docker', - description='Uses Docker client in your Flask application.', + description='Using Docker client in your Flask application.', long_description=long_description, - version='0.1.0', + version='0.2.0', author='Jiangge Zhang', author_email='tonyseek@gmail.com', url='https://github.com/tonyseek/flask-docker', @@ -29,9 +29,12 @@ '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 :: Utilities', ], + zip_safe=False, py_modules=['flask_docker'], install_requires=['flask', 'docker-py'], platforms=['Any']) diff --git a/tests/test_factory.py b/tests/test_factory.py index b59f0da..30f22f2 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -1,4 +1,4 @@ -from flask import Flask +from flask import Flask, current_app from flask_docker import Docker from pytest import fixture, raises import responses @@ -14,7 +14,7 @@ def create_app(): @fixture -def current_app(request): +def app(request): app = create_app() ctx = app.app_context() ctx.push() @@ -23,42 +23,49 @@ def current_app(request): def test_factory(): - assert not hasattr(docker, 'app') + assert docker.app is current_app def test_out_of_context(): + docker.app # nothing raises + + # but if we... + with raises(RuntimeError) as error: + docker.app.name + assert error.value.args[0] == 'working outside of application context' + with raises(RuntimeError) as error: docker.client assert error.value.args[0] == 'working outside of application context' -def test_url_missing(current_app): +def test_url_missing(app): with raises(RuntimeError) as error: docker.client assert error.value.args[0] == '"DOCKER_URL" must be specified' @responses.activate -def test_versioned(current_app): +def test_versioned(app): responses.add( responses.GET, 'http://docker-testing:2375/v1.11/info', body='{"message": "Yo! Gotcha."}', status=200, content_type='application/json') - current_app.config['DOCKER_URL'] = 'http://docker-testing:2375' - current_app.config['DOCKER_VERSION'] = '1.11' + app.config['DOCKER_URL'] = 'http://docker-testing:2375' + app.config['DOCKER_VERSION'] = '1.11' assert docker.client.info() == {'message': 'Yo! Gotcha.'} -def test_lazy_creation(current_app): - current_app.config['DOCKER_URL'] = 'http://docker-testing:2375' +def test_lazy_creation(app): + app.config['DOCKER_URL'] = 'http://docker-testing:2375' - assert current_app.extensions['docker.client'] is None + assert app.extensions['docker.client'] is None client1 = docker.client client2 = docker.client - assert current_app.extensions['docker.client'] is client1 is client2 + assert app.extensions['docker.client'] is client1 is client2 def test_isolation(): diff --git a/tests/test_simple.py b/tests/test_simple.py index 042bdb1..4215276 100644 --- a/tests/test_simple.py +++ b/tests/test_simple.py @@ -1,4 +1,4 @@ -from flask import Flask +from flask import Flask, current_app from flask_docker import Docker from pytest import fixture, raises import responses @@ -13,6 +13,7 @@ def docker(): def test_singleton(docker): assert docker.app + assert docker.app is not current_app def test_url_missing(docker): diff --git a/tox.ini b/tox.ini index 8d0ab53..44b8b48 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py33,py34,pypy +envlist = py27,py33,py34,pypy,docs [testenv] deps = setuptools>=12.0 @@ -10,3 +10,11 @@ deps = responses commands = py.test +[testenv:docs] +changedir = docs +deps = + --requirement=docs/requirements.txt +whitelist_externals = + make +commands = + make html