35
35
# that file here, it would be evaluated too early and not get the
36
36
# settings we make in this file.
37
37
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
+
40
41
41
42
@contextlib .contextmanager
42
43
def ignore_warnings ():
@@ -72,12 +73,17 @@ def do_remove_extension(*args):
72
73
if "--from-install" in args :
73
74
# Get the install location using a subprocess to avoid
74
75
# 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
+ )
81
87
roots = [root ]
82
88
else :
83
89
roots = ["coverage" , "build/*/coverage" ]
@@ -149,8 +155,8 @@ def make_env_id(tracer):
149
155
150
156
def run_tests (tracer , * runner_args ):
151
157
"""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"
154
160
print_banner (label_for_tracer (tracer ))
155
161
156
162
return pytest .main (list (runner_args ))
@@ -159,14 +165,14 @@ def run_tests(tracer, *runner_args):
159
165
def run_tests_with_coverage (tracer , * runner_args ):
160
166
"""Run tests, but with coverage."""
161
167
# 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" )
166
172
if context :
167
173
if context [0 ] == "$" :
168
174
context = os .environ [context [1 :]]
169
- os .environ [' COVERAGE_CONTEXT' ] = context + "." + tracer
175
+ os .environ [" COVERAGE_CONTEXT" ] = context + "." + tracer
170
176
171
177
# Create the .pth file that will let us measure coverage in sub-processes.
172
178
# 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):
178
184
pth_file .write ("import coverage; coverage.process_startup()\n " )
179
185
180
186
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 )
182
188
183
189
import coverage
190
+
184
191
cov = coverage .Coverage (config_file = "metacov.ini" )
185
192
cov ._warn_unimported_source = False
186
193
cov ._warn_preimported_source = False
@@ -195,11 +202,12 @@ def run_tests_with_coverage(tracer, *runner_args):
195
202
# We have to make a list since we'll be deleting in the loop.
196
203
modules = list (sys .modules .items ())
197
204
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 ):
200
207
covmods [name ] = mod
201
208
del sys .modules [name ]
202
- import coverage # pylint: disable=reimported
209
+ import coverage # pylint: disable=reimported
210
+
203
211
sys .modules .update (covmods )
204
212
205
213
# Run tests, with the arguments from our command line.
@@ -216,7 +224,8 @@ def run_tests_with_coverage(tracer, *runner_args):
216
224
def do_combine_html ():
217
225
"""Combine data from a meta-coverage run, and make the HTML report."""
218
226
import coverage
219
- os .environ ['COVERAGE_HOME' ] = os .getcwd ()
227
+
228
+ os .environ ["COVERAGE_HOME" ] = os .getcwd ()
220
229
cov = coverage .Coverage (config_file = "metacov.ini" )
221
230
cov .load ()
222
231
cov .combine ()
@@ -225,7 +234,9 @@ def do_combine_html():
225
234
# control over message verbosity...
226
235
cov = coverage .Coverage (config_file = "metacov.ini" , messages = True )
227
236
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
+ )
229
240
cov .html_report (show_contexts = show_contexts )
230
241
231
242
@@ -247,29 +258,30 @@ def do_test_with_tracer(tracer, *runner_args):
247
258
def do_zip_mods ():
248
259
"""Build the zip files needed for tests."""
249
260
with zipfile .ZipFile ("tests/zipmods.zip" , "w" ) as zf :
250
-
251
261
# Take some files from disk.
252
262
zf .write ("tests/covmodzip1.py" , "covmodzip1.py" )
253
263
254
264
# The others will be various encodings.
255
- source = textwrap .dedent ("""\
265
+ source = textwrap .dedent (
266
+ """\
256
267
# coding: {encoding}
257
268
text = u"{text}"
258
269
ords = {ords}
259
270
assert [ord(c) for c in text] == ords
260
271
print(u"All OK with {encoding}")
261
272
encoding = "{encoding}"
262
- """ )
273
+ """
274
+ )
263
275
# These encodings should match the list in tests/test_python.py
264
276
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”" ),
270
282
]
271
283
for encoding , text in details :
272
- filename = f' encoded_{ encoding } .py'
284
+ filename = f" encoded_{ encoding } .py"
273
285
ords = [ord (c ) for c in text ]
274
286
source_text = source .format (encoding = encoding , text = text , ords = ords )
275
287
zf .writestr (filename , source_text .encode (encoding ))
@@ -304,28 +316,31 @@ def print_banner(label):
304
316
# On Windows having a python executable on a different drive
305
317
# than the sources cannot be relative.
306
318
which_python = sys .executable
307
- print (f' === { impl } { version } { label } ({ which_python } ) ===' )
319
+ print (f" === { impl } { version } { label } ({ which_python } ) ===" )
308
320
sys .stdout .flush ()
309
321
310
322
311
323
def do_quietly (command ):
312
324
"""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
+ )
314
328
return proc .returncode
315
329
316
330
317
331
def get_release_facts ():
318
332
"""Return an object with facts about the current release."""
319
333
import coverage
320
334
import coverage .version
335
+
321
336
facts = types .SimpleNamespace ()
322
337
facts .ver = coverage .__version__
323
338
mjr , mnr , mcr , rel , ser = facts .vi = coverage .version_info
324
339
facts .dev = coverage .version ._dev
325
340
facts .shortver = f"{ mjr } .{ mnr } .{ mcr } "
326
341
facts .anchor = facts .shortver .replace ("." , "-" )
327
342
if rel == "final" :
328
- facts .next_vi = (mjr , mnr , mcr + 1 , "alpha" , 0 )
343
+ facts .next_vi = (mjr , mnr , mcr + 1 , "alpha" , 0 )
329
344
else :
330
345
facts .anchor += f"{ rel [0 ]} { ser } "
331
346
facts .next_vi = (mjr , mnr , mcr , rel , ser + 1 )
@@ -348,9 +363,11 @@ def update_file(fname, pattern, replacement):
348
363
with open (fname , "w" ) as fobj :
349
364
fobj .write (new_text )
350
365
366
+
351
367
UNRELEASED = "Unreleased\n ----------"
352
368
SCRIV_START = ".. scriv-start-here\n \n "
353
369
370
+
354
371
def do_edit_for_release ():
355
372
"""Edit a few files in preparation for a release."""
356
373
facts = get_release_facts ()
@@ -360,7 +377,9 @@ def do_edit_for_release():
360
377
return
361
378
362
379
# 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
+ )
364
383
365
384
# CHANGES.rst
366
385
title = f"Version { facts .ver } — { facts .now :%Y-%m-%d} "
@@ -371,7 +390,8 @@ def do_edit_for_release():
371
390
update_file ("CHANGES.rst" , re .escape (UNRELEASED ), SCRIV_START + new_head )
372
391
373
392
# doc/conf.py
374
- new_conf = textwrap .dedent (f"""\
393
+ new_conf = textwrap .dedent (
394
+ f"""\
375
395
# @@@ editable
376
396
copyright = "2009\N{EN DASH} { facts .now :%Y} , Ned Batchelder" # pylint: disable=redefined-builtin
377
397
# The short X.Y.Z version.
@@ -381,7 +401,8 @@ def do_edit_for_release():
381
401
# The date of release, in "monthname day, year" format.
382
402
release_date = "{ facts .now :%B %-d, %Y} "
383
403
# @@@ end
384
- """ )
404
+ """
405
+ )
385
406
update_file ("doc/conf.py" , r"(?s)# @@@ editable\n.*# @@@ end\n" , new_conf )
386
407
387
408
@@ -398,7 +419,9 @@ def do_bump_version():
398
419
399
420
# coverage/version.py
400
421
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
+ )
402
425
403
426
404
427
def do_cheats ():
@@ -410,13 +433,15 @@ def do_cheats():
410
433
411
434
repo = "nedbat/coveragepy"
412
435
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
+ )
415
440
416
441
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 } )."
420
445
)
421
446
422
447
print ("\n ## To run this code:" )
@@ -427,10 +452,10 @@ def do_cheats():
427
452
print (f"pip install git+{ github } @{ facts .sha } #{ egg } " )
428
453
429
454
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 } "
434
459
)
435
460
436
461
@@ -439,7 +464,7 @@ def do_help():
439
464
items = list (globals ().items ())
440
465
items .sort ()
441
466
for name , value in items :
442
- if name .startswith (' do_' ):
467
+ if name .startswith (" do_" ):
443
468
print (f"{ name [3 :]:<20} { value .__doc__ } " )
444
469
445
470
@@ -464,7 +489,7 @@ def main(args):
464
489
"""
465
490
while args :
466
491
verb = args .pop (0 )
467
- handler = globals ().get (' do_' + verb )
492
+ handler = globals ().get (" do_" + verb )
468
493
if handler is None :
469
494
print (f"*** No handler for { verb !r} " )
470
495
return 1
@@ -484,5 +509,5 @@ def main(args):
484
509
return 0
485
510
486
511
487
- if __name__ == ' __main__' :
512
+ if __name__ == " __main__" :
488
513
sys .exit (main (sys .argv [1 :]))
0 commit comments