macrostrat.database 3.5.2__tar.gz → 3.5.3__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.
Files changed (15) hide show
  1. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/PKG-INFO +1 -1
  2. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/macrostrat/database/utils.py +24 -14
  3. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/pyproject.toml +1 -1
  4. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/macrostrat/database/__init__.py +0 -0
  5. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/macrostrat/database/mapper/__init__.py +0 -0
  6. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/macrostrat/database/mapper/base.py +0 -0
  7. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/macrostrat/database/mapper/cache.py +0 -0
  8. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/macrostrat/database/mapper/utils.py +0 -0
  9. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/macrostrat/database/postgresql.py +0 -0
  10. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/macrostrat/database/transfer/__init__.py +0 -0
  11. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/macrostrat/database/transfer/dump_database.py +0 -0
  12. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/macrostrat/database/transfer/move_tables.py +0 -0
  13. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/macrostrat/database/transfer/restore_database.py +0 -0
  14. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/macrostrat/database/transfer/stream_utils.py +0 -0
  15. {macrostrat_database-3.5.2 → macrostrat_database-3.5.3}/macrostrat/database/transfer/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: macrostrat.database
3
- Version: 3.5.2
3
+ Version: 3.5.3
4
4
  Summary: A SQLAlchemy-based database toolkit.
5
5
  Author: Daven Quinn
6
6
  Author-email: dev@davenquinn.com
@@ -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 PrintMode(Enum):
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.pop("output_mode", PrintMode.SUMMARY)
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 != PrintMode.ALL:
319
+ if output_mode != OutputMode.ALL:
316
320
  sql_text = summarize_statement(sql_text)
317
321
 
318
322
  if not should_run:
@@ -448,11 +452,17 @@ 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
- console = kwargs.pop("console", Console(stderr=True))
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
- console.print(f"[cyan bold]{fixture}[/]")
464
+ fn = fixture.relative_to(prefix)
465
+ console.print(f"[cyan bold]{fn}[/]")
456
466
  run_sql_file(connectable, fixture, params, **kwargs)
457
467
  console.print()
458
468
 
@@ -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.2"
6
+ version = "3.5.3"
7
7
 
8
8
  [tool.poetry.dependencies]
9
9
  GeoAlchemy2 = "^0.15.2"