MCPcopy
hub / github.com/sqlalchemy/alembic / from_config

Method from_config

alembic/script/base.py:161–201  ·  view source on GitHub ↗

Produce a new :class:`.ScriptDirectory` given a :class:`.Config` instance. The :class:`.Config` need only have the ``script_location`` key present.

(cls, config: Config)

Source from the content-addressed store, hash-verified

159
160 @classmethod
161 def from_config(cls, config: Config) -> ScriptDirectory:
162 """Produce a new :class:`.ScriptDirectory` given a :class:`.Config`
163 instance.
164
165 The :class:`.Config` need only have the ``script_location`` key
166 present.
167
168 """
169 script_location = config.get_alembic_option("script_location")
170 if script_location is None:
171 raise util.CommandError(
172 "No 'script_location' key found in configuration."
173 )
174 truncate_slug_length: Optional[int]
175 tsl = config.get_alembic_option("truncate_slug_length")
176 if tsl is not None:
177 truncate_slug_length = int(tsl)
178 else:
179 truncate_slug_length = None
180
181 prepend_sys_path = config.get_prepend_sys_paths_list()
182 if prepend_sys_path:
183 sys.path[:0] = prepend_sys_path
184
185 rvl = config.get_alembic_boolean_option("recursive_version_locations")
186 return ScriptDirectory(
187 util.coerce_resource_to_filename(script_location),
188 file_template=config.get_alembic_option(
189 "file_template", _default_file_template
190 ),
191 truncate_slug_length=truncate_slug_length,
192 sourceless=config.get_alembic_boolean_option("sourceless"),
193 output_encoding=config.get_alembic_option(
194 "output_encoding", "utf-8"
195 ),
196 version_locations=config.get_version_locations_list(),
197 timezone=config.get_alembic_option("timezone"),
198 hooks=config.get_hooks_list(),
199 recursive_version_locations=rvl,
200 messaging_opts=config.messaging_opts,
201 )
202
203 @contextmanager
204 def _catch_revision_errors(

Callers 15

revisionFunction · 0.80
checkFunction · 0.80
mergeFunction · 0.80
upgradeFunction · 0.80
downgradeFunction · 0.80
showFunction · 0.80
historyFunction · 0.80
headsFunction · 0.80
branchesFunction · 0.80
currentFunction · 0.80
stampFunction · 0.80
editFunction · 0.80

Calls 6

ScriptDirectoryClass · 0.85
get_alembic_optionMethod · 0.80
get_hooks_listMethod · 0.80

Tested by 15

_test_001_revisionsMethod · 0.64
setUpMethod · 0.64
test_optionMethod · 0.64
test_lookup_legacyMethod · 0.64
_test_ignore_file_pyMethod · 0.64
test_needs_flagMethod · 0.64
_assert_setupMethod · 0.64
_setup_for_fixtureMethod · 0.64
non_recursive_fixtureMethod · 0.64
multi_base_fixtureMethod · 0.64