From b50609bc0e63704947c0e9d66e503155e885bc0d Mon Sep 17 00:00:00 2001 From: Victor Sergeyev Date: Tue, 22 Apr 2014 18:11:55 +0300 Subject: [PATCH] Fix dhellmann's notes from April 18 removed the python 3 classifier. See note https://github.com/malor/oslo.db/commit/e4cfa6d39d2aa53af64ab34de97183f98fbeb667#commitcomment-6058177 added W292 pep8 check. See note https://github.com/malor/oslo.db/commit/276f7570d7af4a7a62d0e1ffb4edf904cfbf0600#commitcomment-6058296 added usage examples. See note https://github.com/malor/oslo.db/commit/e4cfa6d39d2aa53af64ab34de97183f98fbeb667#commitcomment-6058130 --- doc/source/usage.rst | 64 ++++++++++++++++++++++++++++++++++++++++++-- oslo/__init__.py | 2 +- setup.cfg | 2 -- setup.py | 2 +- tox.ini | 2 +- 5 files changed, 65 insertions(+), 7 deletions(-) diff --git a/doc/source/usage.rst b/doc/source/usage.rst index 81c25cf9..be9ff69a 100644 --- a/doc/source/usage.rst +++ b/doc/source/usage.rst @@ -2,6 +2,66 @@ Usage ======== -To use in a project:: +To use oslo.db in a project:: + +* Session Handling + + .. code:: python + + from oslo.db.sqlalchemy import session as db_session + + _FACADE = None + + def _create_facade_lazily(): + global _FACADE + if _FACADE is None: + _FACADE = db_session.EngineFacade.from_config( + CONF.database.connection, CONF) + return _FACADE + + def get_engine(): + facade = _create_facade_lazily() + return facade.get_engine() + + def get_session(**kwargs): + facade = _create_facade_lazily() + return facade.get_session(**kwargs) + + +* Base class for models usage + + .. code:: python + + from oslo.db import models + + + class ProjectSomething(models.TimestampMixin, + models.ModelBase): + id = Column(Integer, primary_key=True) + ... + + +* DB API backend support + + .. code:: python + + from oslo.config import cfg + from oslo.db import api as db_api + + CONF = cfg.CONF + CONF.import_opt('backend', 'oslo.db.options', group='database') + + _BACKEND_MAPPING = {'sqlalchemy': 'project.db.sqlalchemy.api'} + + IMPL = db_api.DBAPI(CONF.database.backend, backend_mapping=_BACKEND_MAPPING) + + def get_engine(): + return IMPL.get_engine() + + def get_session(): + return IMPL.get_session() + + # DB-API method + def do_something(somethind_id): + return IMPL.do_something(somethind_id) - import db \ No newline at end of file diff --git a/oslo/__init__.py b/oslo/__init__.py index c659cac1..bf1237a6 100644 --- a/oslo/__init__.py +++ b/oslo/__init__.py @@ -12,4 +12,4 @@ # License for the specific language governing permissions and limitations # under the License. -__import__('pkg_resources').declare_namespace(__name__) \ No newline at end of file +__import__('pkg_resources').declare_namespace(__name__) diff --git a/setup.cfg b/setup.cfg index efc991c5..f393ea57 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,8 +16,6 @@ classifier = Programming Language :: Python :: 2 Programming Language :: Python :: 2.7 Programming Language :: Python :: 2.6 - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.3 [files] packages = diff --git a/setup.py b/setup.py index 7eeb36b5..70c2b3f3 100755 --- a/setup.py +++ b/setup.py @@ -19,4 +19,4 @@ import setuptools setuptools.setup( setup_requires=['pbr'], - pbr=True) \ No newline at end of file + pbr=True) diff --git a/tox.ini b/tox.ini index cde32ce7..06b2516c 100644 --- a/tox.ini +++ b/tox.ini @@ -31,6 +31,6 @@ commands = OSLO_LOCK_PATH=/tmp/ python setup.py testr --coverage --testr-args='{ # E123, E125 skipped as they are invalid PEP-8. show-source = True -ignore = E123,E125,H803,W292 +ignore = E123,E125,H803 builtins = _ exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build