Skip to content

Commit acb8045

Browse files
committed
style: ruff format igor.py, setup.py, __main__.py
1 parent 924b6b8 commit acb8045

File tree

3 files changed

+135
-112
lines changed

3 files changed

+135
-112
lines changed

__main__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import runpy
77
import os
88

9-
PKG = 'coverage'
9+
PKG = "coverage"
1010

11-
run_globals = runpy.run_module(PKG, run_name='__main__', alter_sys=True)
12-
executed = os.path.splitext(os.path.basename(run_globals['__file__']))[0]
11+
run_globals = runpy.run_module(PKG, run_name="__main__", alter_sys=True)
12+
executed = os.path.splitext(os.path.basename(run_globals["__file__"]))[0]

igor.py

+74-49
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
# that file here, it would be evaluated too early and not get the
3636
# settings we make in this file.
3737

38-
CPYTHON = (platform.python_implementation() == "CPython")
39-
PYPY = (platform.python_implementation() == "PyPy")
38+
CPYTHON = platform.python_implementation() == "CPython"
39+
PYPY = platform.python_implementation() == "PyPy"
40+
4041

4142
@contextlib.contextmanager
4243
def ignore_warnings():
@@ -72,12 +73,17 @@ def do_remove_extension(*args):
7273
if "--from-install" in args:
7374
# Get the install location using a subprocess to avoid
7475
# locking the file we are about to delete
75-
root = os.path.dirname(subprocess.check_output([
76-
sys.executable,
77-
"-Xutf8",
78-
"-c",
79-
"import coverage; print(coverage.__file__)"
80-
], encoding="utf-8").strip())
76+
root = os.path.dirname(
77+
subprocess.check_output(
78+
[
79+
sys.executable,
80+
"-Xutf8",
81+
"-c",
82+
"import coverage; print(coverage.__file__)",
83+
],
84+
encoding="utf-8",
85+
).strip()
86+
)
8187
roots = [root]
8288
else:
8389
roots = ["coverage", "build/*/coverage"]
@@ -149,8 +155,8 @@ def make_env_id(tracer):
149155

150156
def run_tests(tracer, *runner_args):
151157
"""The actual running of tests."""
152-
if 'COVERAGE_TESTING' not in os.environ:
153-
os.environ['COVERAGE_TESTING'] = "True"
158+
if "COVERAGE_TESTING" not in os.environ:
159+
os.environ["COVERAGE_TESTING"] = "True"
154160
print_banner(label_for_tracer(tracer))
155161

156162
return pytest.main(list(runner_args))
@@ -159,14 +165,14 @@ def run_tests(tracer, *runner_args):
159165
def run_tests_with_coverage(tracer, *runner_args):
160166
"""Run tests, but with coverage."""
161167
# Need to define this early enough that the first import of env.py sees it.
162-
os.environ['COVERAGE_TESTING'] = "True"
163-
os.environ['COVERAGE_PROCESS_START'] = os.path.abspath('metacov.ini')
164-
os.environ['COVERAGE_HOME'] = os.getcwd()
165-
context = os.environ.get('COVERAGE_CONTEXT')
168+
os.environ["COVERAGE_TESTING"] = "True"
169+
os.environ["COVERAGE_PROCESS_START"] = os.path.abspath("metacov.ini")
170+
os.environ["COVERAGE_HOME"] = os.getcwd()
171+
context = os.environ.get("COVERAGE_CONTEXT")
166172
if context:
167173
if context[0] == "$":
168174
context = os.environ[context[1:]]
169-
os.environ['COVERAGE_CONTEXT'] = context + "." + tracer
175+
os.environ["COVERAGE_CONTEXT"] = context + "." + tracer
170176

171177
# Create the .pth file that will let us measure coverage in sub-processes.
172178
# The .pth file seems to have to be alphabetically after easy-install.pth
@@ -178,9 +184,10 @@ def run_tests_with_coverage(tracer, *runner_args):
178184
pth_file.write("import coverage; coverage.process_startup()\n")
179185

180186
suffix = f"{make_env_id(tracer)}_{platform.platform()}"
181-
os.environ['COVERAGE_METAFILE'] = os.path.abspath(".metacov."+suffix)
187+
os.environ["COVERAGE_METAFILE"] = os.path.abspath(".metacov." + suffix)
182188

183189
import coverage
190+
184191
cov = coverage.Coverage(config_file="metacov.ini")
185192
cov._warn_unimported_source = False
186193
cov._warn_preimported_source = False
@@ -195,11 +202,12 @@ def run_tests_with_coverage(tracer, *runner_args):
195202
# We have to make a list since we'll be deleting in the loop.
196203
modules = list(sys.modules.items())
197204
for name, mod in modules:
198-
if name.startswith('coverage'):
199-
if getattr(mod, '__file__', "??").startswith(covdir):
205+
if name.startswith("coverage"):
206+
if getattr(mod, "__file__", "??").startswith(covdir):
200207
covmods[name] = mod
201208
del sys.modules[name]
202-
import coverage # pylint: disable=reimported
209+
import coverage # pylint: disable=reimported
210+
203211
sys.modules.update(covmods)
204212

205213
# Run tests, with the arguments from our command line.
@@ -216,7 +224,8 @@ def run_tests_with_coverage(tracer, *runner_args):
216224
def do_combine_html():
217225
"""Combine data from a meta-coverage run, and make the HTML report."""
218226
import coverage
219-
os.environ['COVERAGE_HOME'] = os.getcwd()
227+
228+
os.environ["COVERAGE_HOME"] = os.getcwd()
220229
cov = coverage.Coverage(config_file="metacov.ini")
221230
cov.load()
222231
cov.combine()
@@ -225,7 +234,9 @@ def do_combine_html():
225234
# control over message verbosity...
226235
cov = coverage.Coverage(config_file="metacov.ini", messages=True)
227236
cov.load()
228-
show_contexts = bool(os.environ.get('COVERAGE_DYNCTX') or os.environ.get('COVERAGE_CONTEXT'))
237+
show_contexts = bool(
238+
os.environ.get("COVERAGE_DYNCTX") or os.environ.get("COVERAGE_CONTEXT")
239+
)
229240
cov.html_report(show_contexts=show_contexts)
230241

231242

@@ -247,29 +258,30 @@ def do_test_with_tracer(tracer, *runner_args):
247258
def do_zip_mods():
248259
"""Build the zip files needed for tests."""
249260
with zipfile.ZipFile("tests/zipmods.zip", "w") as zf:
250-
251261
# Take some files from disk.
252262
zf.write("tests/covmodzip1.py", "covmodzip1.py")
253263

254264
# The others will be various encodings.
255-
source = textwrap.dedent("""\
265+
source = textwrap.dedent(
266+
"""\
256267
# coding: {encoding}
257268
text = u"{text}"
258269
ords = {ords}
259270
assert [ord(c) for c in text] == ords
260271
print(u"All OK with {encoding}")
261272
encoding = "{encoding}"
262-
""")
273+
"""
274+
)
263275
# These encodings should match the list in tests/test_python.py
264276
details = [
265-
('utf-8', 'ⓗⓔⓛⓛⓞ, ⓦⓞⓡⓛⓓ'),
266-
('gb2312', '你好,世界'),
267-
('hebrew', 'שלום, עולם'),
268-
('shift_jis', 'こんにちは世界'),
269-
('cp1252', '“hi”'),
277+
("utf-8", "ⓗⓔⓛⓛⓞ, ⓦⓞⓡⓛⓓ"),
278+
("gb2312", "你好,世界"),
279+
("hebrew", "שלום, עולם"),
280+
("shift_jis", "こんにちは世界"),
281+
("cp1252", "“hi”"),
270282
]
271283
for encoding, text in details:
272-
filename = f'encoded_{encoding}.py'
284+
filename = f"encoded_{encoding}.py"
273285
ords = [ord(c) for c in text]
274286
source_text = source.format(encoding=encoding, text=text, ords=ords)
275287
zf.writestr(filename, source_text.encode(encoding))
@@ -304,28 +316,31 @@ def print_banner(label):
304316
# On Windows having a python executable on a different drive
305317
# than the sources cannot be relative.
306318
which_python = sys.executable
307-
print(f'=== {impl} {version} {label} ({which_python}) ===')
319+
print(f"=== {impl} {version} {label} ({which_python}) ===")
308320
sys.stdout.flush()
309321

310322

311323
def do_quietly(command):
312324
"""Run a command in a shell, and suppress all output."""
313-
proc = subprocess.run(command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
325+
proc = subprocess.run(
326+
command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
327+
)
314328
return proc.returncode
315329

316330

317331
def get_release_facts():
318332
"""Return an object with facts about the current release."""
319333
import coverage
320334
import coverage.version
335+
321336
facts = types.SimpleNamespace()
322337
facts.ver = coverage.__version__
323338
mjr, mnr, mcr, rel, ser = facts.vi = coverage.version_info
324339
facts.dev = coverage.version._dev
325340
facts.shortver = f"{mjr}.{mnr}.{mcr}"
326341
facts.anchor = facts.shortver.replace(".", "-")
327342
if rel == "final":
328-
facts.next_vi = (mjr, mnr, mcr+1, "alpha", 0)
343+
facts.next_vi = (mjr, mnr, mcr + 1, "alpha", 0)
329344
else:
330345
facts.anchor += f"{rel[0]}{ser}"
331346
facts.next_vi = (mjr, mnr, mcr, rel, ser + 1)
@@ -348,9 +363,11 @@ def update_file(fname, pattern, replacement):
348363
with open(fname, "w") as fobj:
349364
fobj.write(new_text)
350365

366+
351367
UNRELEASED = "Unreleased\n----------"
352368
SCRIV_START = ".. scriv-start-here\n\n"
353369

370+
354371
def do_edit_for_release():
355372
"""Edit a few files in preparation for a release."""
356373
facts = get_release_facts()
@@ -360,7 +377,9 @@ def do_edit_for_release():
360377
return
361378

362379
# NOTICE.txt
363-
update_file("NOTICE.txt", r"Copyright 2004.*? Ned", f"Copyright 2004-{facts.now:%Y} Ned")
380+
update_file(
381+
"NOTICE.txt", r"Copyright 2004.*? Ned", f"Copyright 2004-{facts.now:%Y} Ned"
382+
)
364383

365384
# CHANGES.rst
366385
title = f"Version {facts.ver}{facts.now:%Y-%m-%d}"
@@ -371,7 +390,8 @@ def do_edit_for_release():
371390
update_file("CHANGES.rst", re.escape(UNRELEASED), SCRIV_START + new_head)
372391

373392
# doc/conf.py
374-
new_conf = textwrap.dedent(f"""\
393+
new_conf = textwrap.dedent(
394+
f"""\
375395
# @@@ editable
376396
copyright = "2009\N{EN DASH}{facts.now:%Y}, Ned Batchelder" # pylint: disable=redefined-builtin
377397
# The short X.Y.Z version.
@@ -381,7 +401,8 @@ def do_edit_for_release():
381401
# The date of release, in "monthname day, year" format.
382402
release_date = "{facts.now:%B %-d, %Y}"
383403
# @@@ end
384-
""")
404+
"""
405+
)
385406
update_file("doc/conf.py", r"(?s)# @@@ editable\n.*# @@@ end\n", new_conf)
386407

387408

@@ -398,7 +419,9 @@ def do_bump_version():
398419

399420
# coverage/version.py
400421
next_version = f"version_info = {facts.next_vi}\n_dev = 1".replace("'", '"')
401-
update_file("coverage/version.py", r"(?m)^version_info = .*\n_dev = \d+$", next_version)
422+
update_file(
423+
"coverage/version.py", r"(?m)^version_info = .*\n_dev = \d+$", next_version
424+
)
402425

403426

404427
def do_cheats():
@@ -410,13 +433,15 @@ def do_cheats():
410433

411434
repo = "nedbat/coveragepy"
412435
github = f"https://github.com/{repo}"
413-
egg = "egg=coverage==0.0" # to force a re-install
414-
print(f"https://coverage.readthedocs.io/en/{facts.ver}/changes.html#changes-{facts.anchor}")
436+
egg = "egg=coverage==0.0" # to force a re-install
437+
print(
438+
f"https://coverage.readthedocs.io/en/{facts.ver}/changes.html#changes-{facts.anchor}"
439+
)
415440

416441
print(
417-
"\n## For GitHub commenting:\n" +
418-
"This is now released as part of " +
419-
f"[coverage {facts.ver}](https://pypi.org/project/coverage/{facts.ver})."
442+
"\n## For GitHub commenting:\n"
443+
+ "This is now released as part of "
444+
+ f"[coverage {facts.ver}](https://pypi.org/project/coverage/{facts.ver})."
420445
)
421446

422447
print("\n## To run this code:")
@@ -427,10 +452,10 @@ def do_cheats():
427452
print(f"pip install git+{github}@{facts.sha}#{egg}")
428453

429454
print(
430-
"\n## For other collaborators:\n" +
431-
f"git clone {github}\n" +
432-
f"cd {repo.partition('/')[-1]}\n" +
433-
f"git checkout {facts.sha}"
455+
"\n## For other collaborators:\n"
456+
+ f"git clone {github}\n"
457+
+ f"cd {repo.partition('/')[-1]}\n"
458+
+ f"git checkout {facts.sha}"
434459
)
435460

436461

@@ -439,7 +464,7 @@ def do_help():
439464
items = list(globals().items())
440465
items.sort()
441466
for name, value in items:
442-
if name.startswith('do_'):
467+
if name.startswith("do_"):
443468
print(f"{name[3:]:<20}{value.__doc__}")
444469

445470

@@ -464,7 +489,7 @@ def main(args):
464489
"""
465490
while args:
466491
verb = args.pop(0)
467-
handler = globals().get('do_'+verb)
492+
handler = globals().get("do_" + verb)
468493
if handler is None:
469494
print(f"*** No handler for {verb!r}")
470495
return 1
@@ -484,5 +509,5 @@ def main(args):
484509
return 0
485510

486511

487-
if __name__ == '__main__':
512+
if __name__ == "__main__":
488513
sys.exit(main(sys.argv[1:]))

0 commit comments

Comments
 (0)