use entrypoints terminology to parse dotted model class names
This commit is contained in:
parent
50246d65cb
commit
31bd33bcff
@ -1,4 +1,5 @@
|
||||
0.5.4
|
||||
- use entrypoints terminology to specify dotted model names (module.model.User) [Domen Kozar]
|
||||
- added engine_dict and engine_arg_* parameters to all api functions [Domen Kozar]
|
||||
- make --echo parameter a bit more forgivable (better Python API support) [Domen Kozar]
|
||||
- apply patch to refactor cmd line parsing for Issue 54 by Domen Kozar
|
||||
|
3
TODO
3
TODO
@ -1,3 +1,6 @@
|
||||
- better MySQL support
|
||||
- fix unit tests for other databases than PostgreSQL (MySQL and SQLite
|
||||
fail at test_changeset.test_fk(..))
|
||||
- document dotted_name parsing changes
|
||||
- document shell parsing
|
||||
- document engine parameters usage/parsing
|
||||
|
@ -1,23 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import warnings
|
||||
from decorator import decorator
|
||||
from pkg_resources import EntryPoint
|
||||
|
||||
from migrate.versioning import exceptions
|
||||
from migrate.versioning.util.keyedinstance import KeyedInstance
|
||||
from migrate.versioning.util.importpath import import_path
|
||||
|
||||
|
||||
def loadModel(model):
|
||||
''' Import module and use module-level variable -- assume model is of form "mod1.mod2.varname". '''
|
||||
if isinstance(model, basestring):
|
||||
varname = model.split('.')[-1]
|
||||
modules = '.'.join(model.split('.')[:-1])
|
||||
module = __import__(modules, globals(), {}, ['dummy-not-used'], -1)
|
||||
return getattr(module, varname)
|
||||
def loadModel(dotted_name):
|
||||
''' Import module and use module-level variable -- assume model is of form "mod1.mod2:varname". '''
|
||||
if isinstance(dotted_name, basestring):
|
||||
if ':' not in dotted_name:
|
||||
# backwards compatibility
|
||||
warnings.warn('model should be in form of module.model:User'
|
||||
'and not module.model.User', DeprecationWarning)
|
||||
dotted_name = ':'.join(dotted_name.rsplit('.', 1))
|
||||
return EntryPoint.parse('x=%s' % dotted_name).load(False)
|
||||
else:
|
||||
# Assume it's already loaded.
|
||||
return model
|
||||
return dotted_name
|
||||
|
||||
def asbool(obj):
|
||||
"""Do everything to use object as bool"""
|
||||
|
@ -495,7 +495,7 @@ class TestShellDatabase(Shell, fixture.DB):
|
||||
self.assertEquals(self.cmd_db_version(self.url,repos_path),0)
|
||||
|
||||
# Setup helper script.
|
||||
model_module = 'testmodel.meta'
|
||||
model_module = 'testmodel:meta'
|
||||
self.assertSuccess(self.cmd('manage',script_path,'--repository=%s --url=%s --model=%s' % (repos_path, self.url, model_module)))
|
||||
self.assert_(os.path.exists(script_path))
|
||||
|
||||
@ -522,6 +522,10 @@ class TestShellDatabase(Shell, fixture.DB):
|
||||
# Model is defined but database is empty.
|
||||
output, exitcode = self.output_and_exitcode('python %s compare_model_to_db' % script_path)
|
||||
assert "tables missing in database: tmp_account_rundiffs" in output, output
|
||||
|
||||
# Test Deprecation
|
||||
output, exitcode = self.output_and_exitcode('python %s compare_model_to_db --model=testmodel.meta' % script_path)
|
||||
assert "tables missing in database: tmp_account_rundiffs" in output, output
|
||||
|
||||
# Update db to latest model.
|
||||
output, exitcode = self.output_and_exitcode('python %s update_db_from_model' % script_path)
|
||||
|
Loading…
x
Reference in New Issue
Block a user