Skip to content

Commit

Permalink
upgrade syntax to py37+ and autoconvert some f-strings. add tox synta…
Browse files Browse the repository at this point in the history
…x-upgrade task.
  • Loading branch information
mahmoud committed Nov 2, 2024
1 parent 3df8e6f commit 8bf19e7
Show file tree
Hide file tree
Showing 28 changed files with 172 additions and 185 deletions.
1 change: 0 additions & 1 deletion glom/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from glom.core import (glom,
Fill,
Auto,
Expand Down
1 change: 0 additions & 1 deletion glom/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from glom.cli import console_main

if __name__ == '__main__':
Expand Down
17 changes: 8 additions & 9 deletions glom/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"""


from __future__ import print_function

import os
import ast
Expand Down Expand Up @@ -65,7 +64,7 @@ def glom_cli(target, spec, indent, debug, inspect):
try:
result = glom.glom(target, spec)
except GlomError as ge:
print('%s: %s' % (ge.__class__.__name__, ge))
print(f'{ge.__class__.__name__}: {ge}')
return 1

if not indent:
Expand Down Expand Up @@ -170,10 +169,10 @@ def mw_get_target(next_, posargs_, target_file, target_format, spec_file, spec_f
raise UsageError('expected spec file or spec argument, not both')
elif spec_file:
try:
with open(spec_file, 'r') as f:
with open(spec_file) as f:
spec_text = f.read()
except IOError as ose:
raise UsageError('could not read spec file %r, got: %s' % (spec_file, ose))
except OSError as ose:
raise UsageError(f'could not read spec file {spec_file!r}, got: {ose}')

if not spec_text:
spec = Path()
Expand All @@ -195,9 +194,9 @@ def mw_get_target(next_, posargs_, target_file, target_format, spec_file, spec_f
target_text = sys.stdin.read()
elif target_file:
try:
target_text = open(target_file, 'r').read()
except IOError as ose:
raise UsageError('could not read target file %r, got: %s' % (target_file, ose))
target_text = open(target_file).read()
except OSError as ose:
raise UsageError(f'could not read target file {target_file!r}, got: {ose}')
elif not target_text and not isatty(sys.stdin):
target_text = sys.stdin.read()

Expand All @@ -218,7 +217,7 @@ def _from_glom_import_star():

def _eval_python_full_spec(py_text):
name = '__cli_glom_spec__'
code_str = '%s = %s' % (name, py_text)
code_str = f'{name} = {py_text}'
env = _from_glom_import_star()
spec = _compile_code(code_str, name=name, env=env)
return spec
Expand Down
Loading

0 comments on commit 8bf19e7

Please sign in to comment.