Skip to content

Commit

Permalink
Reformat the code with Ruff (./run format).
Browse files Browse the repository at this point in the history
This reformats all the code with the Ruff Python formatter.
pyproject.toml contains the configuration for the formatter.
  • Loading branch information
dpranke committed Mar 16, 2024
1 parent 00d73a3 commit e93c816
Show file tree
Hide file tree
Showing 10 changed files with 1,227 additions and 556 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.coverage
.ruff_cache
build
dist
*.pyc
Expand Down
32 changes: 20 additions & 12 deletions benchmarks/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--pure', action='store_true')
parser.add_argument('-n', '--num-iterations', default=DEFAULT_ITERATIONS,
type=int)
parser.add_argument(
'-n', '--num-iterations', default=DEFAULT_ITERATIONS, type=int
)
parser.add_argument('benchmarks', nargs='*')
args = parser.parse_args()
if not args.benchmarks:
Expand All @@ -47,7 +48,6 @@ def main():
with open(f, encoding='utf-8') as fp:
file_contents.append(fp.read())


# json.decoder.c_scanstring = py_scanstring
def py_maker(*args, **kwargs):
del args
Expand Down Expand Up @@ -81,20 +81,28 @@ def py_maker(*args, **kwargs):
if json5_time and json_time:
if json5_time > json_time:
avg = json5_time / json_time
print(f"{fname:-%20s}: JSON was {avg:5.1f}x faster "
f"({json_time:.6f} to {json5_time:.6fs}")
print(
f'{fname:-%20s}: JSON was {avg:5.1f}x faster '
f'({json_time:.6f} to {json5_time:.6fs}'
)
else:
avg = json_time / json5_time
print(f"{fname:-%20s}: JSON5 was {avg:5.1f}x faster "
f"({json5_time:.6f} to {json_time:.6fs}")
print(
f'{fname:-%20s}: JSON5 was {avg:5.1f}x faster '
f'({json5_time:.6f} to {json_time:.6fs}'
)
elif json5_time:
print(f"{fname:-20s}: JSON5 took {json5_time:.6f} secs, "
f"JSON was too fast to measure")
print(
f'{fname:-20s}: JSON5 took {json5_time:.6f} secs, '
f'JSON was too fast to measure'
)
elif json_time:
print(f"{fname:-20s}: JSON took {json_time:.6f} secs, "
f"JSON5 was too fast to measure")
print(
f'{fname:-20s}: JSON took {json_time:.6f} secs, '
f'JSON5 was too fast to measure'
)
else:
print(f"{fname:-20s}: both were too fast to measure")
print(f'{fname:-20s}: both were too fast to measure')

return 0

Expand Down
11 changes: 7 additions & 4 deletions json5/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ def __init__(self, host, prog, desc, **kwargs):
super().__init__(**kwargs)
self._host = host
self.exit_status = None
self.add_argument('-V', '--version', action='store_true',
help='print the version and exit')
self.add_argument(
'-V',
'--version',
action='store_true',
help='print the version and exit',
)

def parse_args(self, args=None, namespace=None):
try:
Expand All @@ -49,8 +53,7 @@ def print_help(self, file=None):
def error(self, message, bailout=True):
self.exit(2, f'{self.prog}: error: {message}\n', bailout=bailout)

def exit(self, status=0, message=None,
bailout=True):
def exit(self, status=0, message=None, bailout=True):
self.exit_status = status
if message:
self._print_message(message, file=self._host.stderr)
Expand Down
Loading

0 comments on commit e93c816

Please sign in to comment.