Skip to content

Commit

Permalink
- tried it out in my work project, and realized the "op" and "context…
Browse files Browse the repository at this point in the history
…" namespaces

need to be there fully and in particular "context" needs to be
a proxy object, as env.py may have dependencies which live beyond the
scope of the migration script.   Will have to try to make
these proxies as straightforward as possible.
- more architecture docs
  • Loading branch information
zzzeek committed Jan 24, 2012
1 parent 0f6c5a8 commit 8175fac
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 95 deletions.
11 changes: 7 additions & 4 deletions alembic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
package_dir = path.abspath(path.dirname(__file__))


class _OpProxy(object):
_proxy = None
from alembic import op

class _ContextProxy(object):
"""A proxy object for the current :class:`.EnvironmentContext`."""
def __getattr__(self, key):
return getattr(self._proxy, key)
op = _OpProxy()
return getattr(_context, key)
context = _ContextProxy()

4 changes: 2 additions & 2 deletions alembic/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def __enter__(self):
be made available as ``from alembic import context``.
"""
alembic.context = self
alembic._context = self
return self

def __exit__(self, *arg, **kw):
del alembic.context
alembic._context = None
alembic.op._proxy = None

def is_offline_mode(self):
Expand Down
19 changes: 19 additions & 0 deletions alembic/op.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from alembic.operations import Operations

# create proxy functions for
# each method on the Operations class.

# TODO: this is a quick and dirty version of this.
# Ideally, we'd be duplicating method signatures
# and such, using eval(), etc.

_proxy = None
def _create_op_proxy(name):
def go(*arg, **kw):
return getattr(_proxy, name)(*arg, **kw)
go.__name__ = name
return go

for methname in dir(Operations):
if not methname.startswith('_'):
locals()[methname] = _create_op_proxy(methname)
Loading

0 comments on commit 8175fac

Please sign in to comment.