macrostrat.database 3.5.2__tar.gz → 3.5.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/PKG-INFO +1 -1
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/utils.py +32 -15
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/pyproject.toml +1 -1
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/__init__.py +0 -0
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/mapper/__init__.py +0 -0
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/mapper/base.py +0 -0
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/mapper/cache.py +0 -0
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/mapper/utils.py +0 -0
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/postgresql.py +0 -0
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/transfer/__init__.py +0 -0
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/transfer/dump_database.py +0 -0
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/transfer/move_tables.py +0 -0
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/transfer/restore_database.py +0 -0
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/transfer/stream_utils.py +0 -0
- {macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/transfer/utils.py +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import os
|
|
1
2
|
from contextlib import contextmanager
|
|
2
3
|
from enum import Enum
|
|
3
4
|
from pathlib import Path
|
|
@@ -118,11 +119,6 @@ def summarize_statement(sql):
|
|
|
118
119
|
return line.split("(")[0].strip().rstrip(";").replace(" AS", "")
|
|
119
120
|
|
|
120
121
|
|
|
121
|
-
class DevNull(object):
|
|
122
|
-
def write(self, *_):
|
|
123
|
-
pass
|
|
124
|
-
|
|
125
|
-
|
|
126
122
|
def get_sql_text(sql, interpret_as_file=None, echo_file_name=True):
|
|
127
123
|
if interpret_as_file:
|
|
128
124
|
sql = Path(sql).read_text()
|
|
@@ -239,13 +235,25 @@ def infer_has_server_binds(sql):
|
|
|
239
235
|
_default_statement_filter = lambda sql_text, params: True
|
|
240
236
|
|
|
241
237
|
|
|
242
|
-
class
|
|
238
|
+
class OutputMode(Enum):
|
|
243
239
|
NONE = "none"
|
|
244
240
|
ERRORS = "errors"
|
|
245
241
|
SUMMARY = "summary"
|
|
246
242
|
ALL = "all"
|
|
247
243
|
|
|
248
244
|
|
|
245
|
+
def _normalize_output_args(kwargs):
|
|
246
|
+
output_mode = kwargs.pop("output_mode", OutputMode.SUMMARY)
|
|
247
|
+
output_file = kwargs.pop("output_file", stderr)
|
|
248
|
+
|
|
249
|
+
if not isinstance(output_mode, OutputMode):
|
|
250
|
+
output_mode = OutputMode(output_mode)
|
|
251
|
+
|
|
252
|
+
if output_mode == OutputMode.NONE:
|
|
253
|
+
output_file = open(os.devnull, "w")
|
|
254
|
+
return output_mode, output_file
|
|
255
|
+
|
|
256
|
+
|
|
249
257
|
def _run_sql(connectable, sql, params=None, **kwargs):
|
|
250
258
|
"""
|
|
251
259
|
Internal function for running a query on a SQLAlchemy connectable,
|
|
@@ -262,11 +270,7 @@ def _run_sql(connectable, sql, params=None, **kwargs):
|
|
|
262
270
|
has_server_binds = kwargs.pop("has_server_binds", None)
|
|
263
271
|
ensure_single_query = kwargs.pop("ensure_single_query", False)
|
|
264
272
|
statement_filter = kwargs.pop("statement_filter", _default_statement_filter)
|
|
265
|
-
output_mode = kwargs
|
|
266
|
-
output_file = kwargs.pop("output_file", stderr)
|
|
267
|
-
|
|
268
|
-
if output_mode == PrintMode.NONE:
|
|
269
|
-
output_file = DevNull()
|
|
273
|
+
output_mode, output_file = _normalize_output_args(kwargs)
|
|
270
274
|
|
|
271
275
|
if stop_on_error:
|
|
272
276
|
raise_errors = True
|
|
@@ -312,7 +316,7 @@ def _run_sql(connectable, sql, params=None, **kwargs):
|
|
|
312
316
|
should_run = statement_filter(sql_text, params)
|
|
313
317
|
|
|
314
318
|
# Shorten summary text for printing
|
|
315
|
-
if output_mode !=
|
|
319
|
+
if output_mode != OutputMode.ALL:
|
|
316
320
|
sql_text = summarize_statement(sql_text)
|
|
317
321
|
|
|
318
322
|
if not should_run:
|
|
@@ -448,12 +452,25 @@ def run_fixtures(connectable, fixtures: Union[Path, list[Path]], params=None, **
|
|
|
448
452
|
"""
|
|
449
453
|
recursive = kwargs.pop("recursive", False)
|
|
450
454
|
order_by_name = kwargs.pop("order_by_name", True)
|
|
451
|
-
|
|
455
|
+
output_mode, output_file = _normalize_output_args(kwargs)
|
|
456
|
+
|
|
457
|
+
console = kwargs.pop("console", Console(stderr=True, file=output_file))
|
|
452
458
|
files = get_sql_files(fixtures, recursive=recursive, order_by_name=order_by_name)
|
|
453
459
|
|
|
460
|
+
prefix = os.path.commonpath(files)
|
|
461
|
+
|
|
462
|
+
console.print(f"Running fixtures in [cyan bold]{prefix}[/]")
|
|
454
463
|
for fixture in files:
|
|
455
|
-
|
|
456
|
-
|
|
464
|
+
fn = fixture.relative_to(prefix)
|
|
465
|
+
console.print(f"[cyan bold]{fn}[/]")
|
|
466
|
+
run_sql_file(
|
|
467
|
+
connectable,
|
|
468
|
+
fixture,
|
|
469
|
+
params,
|
|
470
|
+
output_mode=output_mode,
|
|
471
|
+
output_file=output_file,
|
|
472
|
+
**kwargs,
|
|
473
|
+
)
|
|
457
474
|
console.print()
|
|
458
475
|
|
|
459
476
|
|
|
@@ -3,7 +3,7 @@ authors = ["Daven Quinn <dev@davenquinn.com>"]
|
|
|
3
3
|
description = "A SQLAlchemy-based database toolkit."
|
|
4
4
|
name = "macrostrat.database"
|
|
5
5
|
packages = [{ include = "macrostrat" }]
|
|
6
|
-
version = "3.5.
|
|
6
|
+
version = "3.5.4"
|
|
7
7
|
|
|
8
8
|
[tool.poetry.dependencies]
|
|
9
9
|
GeoAlchemy2 = "^0.15.2"
|
|
File without changes
|
{macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/mapper/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/transfer/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/transfer/move_tables.py
RENAMED
|
File without changes
|
|
File without changes
|
{macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/transfer/stream_utils.py
RENAMED
|
File without changes
|
{macrostrat_database-3.5.2 → macrostrat_database-3.5.4}/macrostrat/database/transfer/utils.py
RENAMED
|
File without changes
|