Skip to content

Commit f5cdc88

Browse files
committed
Use f-strings
1 parent f523b71 commit f5cdc88

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

add-to-pydotorg.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ def run_cmd(cmd, silent=False, shell=True, **kwargs):
4747
if shell:
4848
cmd = " ".join(cmd)
4949
if not silent:
50-
print("Executing %s" % cmd)
50+
print(f"Executing {cmd}")
5151
try:
5252
if silent:
5353
subprocess.check_call(cmd, shell=shell, stdout=subprocess.PIPE, **kwargs)
5454
else:
5555
subprocess.check_call(cmd, shell=shell, **kwargs)
5656
except subprocess.CalledProcessError:
57-
error("%s failed" % cmd)
57+
error(f"{cmd} failed")
5858

5959

6060
try:
@@ -72,7 +72,7 @@ def run_cmd(cmd, silent=False, shell=True, **kwargs):
7272

7373
tag_cre = re.compile(r"(\d+)(?:\.(\d+)(?:\.(\d+))?)?(?:([ab]|rc)(\d+))?$")
7474

75-
headers = {"Authorization": "ApiKey %s" % auth_info, "Content-Type": "application/json"}
75+
headers = {"Authorization": f"ApiKey {auth_info}", "Content-Type": "application/json"}
7676

7777
github_oidc_provider = "https://github.com/login/oauth"
7878
google_oidc_provider = "https://accounts.google.com"
@@ -153,9 +153,9 @@ def get_file_descriptions(release):
153153

154154

155155
def changelog_for(release):
156-
new_url = "http://docs.python.org/release/%s/whatsnew/changelog.html" % release
156+
new_url = f"http://docs.python.org/release/{release}/whatsnew/changelog.html"
157157
if requests.head(new_url).status_code != 200:
158-
return "http://hg.python.org/cpython/file/v%s/Misc/NEWS" % release
158+
return f"http://hg.python.org/cpython/file/v{release}/Misc/NEWS"
159159

160160

161161
def slug_for(release):
@@ -204,8 +204,8 @@ def build_file_dict(release, rfile, rel_pk, file_desc, os_pk, add_download, add_
204204
d = {
205205
"name": file_desc,
206206
"slug": slug_for(release) + "-" + make_slug(file_desc)[:40],
207-
"os": "/api/v1/downloads/os/%s/" % os_pk,
208-
"release": "/api/v1/downloads/release/%s/" % rel_pk,
207+
"os": f"/api/v1/downloads/os/{os_pk}/",
208+
"release": f"/api/v1/downloads/release/{rel_pk}/",
209209
"description": add_desc,
210210
"is_source": os_pk == 3,
211211
"url": download_root + f"{base_version(release)}/{rfile}",
@@ -276,7 +276,7 @@ def list_files(release):
276276

277277
def query_object(objtype, **params):
278278
"""Find an API object by query parameters."""
279-
uri = base_url + "downloads/%s/" % objtype
279+
uri = base_url + f"downloads/{objtype}/"
280280
uri += "?" + "&".join(f"{k}={v}" for k, v in params.items())
281281
resp = requests.get(uri, headers=headers)
282282
if resp.status_code != 200 or not json.loads(resp.text)["objects"]:
@@ -391,20 +391,20 @@ def main():
391391
continue
392392
print("Creating ReleaseFile object for", rfile, key)
393393
if key in file_dicts:
394-
raise RuntimeError("duplicate slug generated: %s" % key)
394+
raise RuntimeError(f"duplicate slug generated: {key}")
395395
file_dicts[key] = file_dict
396396
print("Deleting previous release files")
397397
resp = requests.delete(
398-
base_url + "downloads/release_file/?release=%s" % rel_pk, headers=headers
398+
base_url + f"downloads/release_file/?release={rel_pk}", headers=headers
399399
)
400400
if resp.status_code != 204:
401-
raise RuntimeError("deleting previous releases failed: %s" % resp.status_code)
401+
raise RuntimeError(f"deleting previous releases failed: {resp.status_code}")
402402
for file_dict in file_dicts.values():
403403
file_pk = post_object("release_file", file_dict)
404404
if file_pk >= 0:
405405
print("Created as id =", file_pk)
406406
n += 1
407-
print("Done - %d files added" % n)
407+
print(f"Done - {n} files added")
408408

409409

410410
if not sys.flags.interactive:

release.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ def run_cmd(cmd, silent=False, shell=False, **kwargs):
3838
if shell:
3939
cmd = SPACE.join(cmd)
4040
if not silent:
41-
print("Executing %s" % cmd)
41+
print(f"Executing {cmd}")
4242
try:
4343
if silent:
4444
subprocess.check_call(cmd, shell=shell, stdout=subprocess.PIPE, **kwargs)
4545
else:
4646
subprocess.check_call(cmd, shell=shell, **kwargs)
4747
except subprocess.CalledProcessError:
48-
error("%s failed" % cmd)
48+
error(f"{cmd} failed")
4949

5050

5151
readme_re = re.compile(r"This is Python version [23]\.\d").match
@@ -186,7 +186,7 @@ def constant_replace(fn, updated_constants, comment_start="/*", comment_end="*/"
186186
else:
187187
outfile.write(line)
188188
if not found_constants:
189-
error("Constant section delimiters not found: %s" % fn)
189+
error(f"Constant section delimiters not found: {fn}")
190190
os.rename(fn + ".new", fn)
191191

192192

@@ -217,7 +217,7 @@ def tweak_patchlevel(tag, done=False):
217217

218218

219219
def bump(tag):
220-
print("Bumping version to %s" % tag)
220+
print(f"Bumping version to {tag}")
221221

222222
tweak_patchlevel(tag)
223223

@@ -240,10 +240,10 @@ def bump(tag):
240240
print("\nManual editing time...")
241241
for fn in other_files:
242242
if os.path.exists(fn):
243-
print("Edit %s" % fn)
243+
print(f"Edit {fn}")
244244
manual_edit(fn)
245245
else:
246-
print("Skipping %s" % fn)
246+
print(f"Skipping {fn}")
247247

248248
print("Bumped revision")
249249
if extra_work:
@@ -258,7 +258,7 @@ def manual_edit(fn: str) -> None:
258258

259259
@contextmanager
260260
def pushd(new):
261-
print("chdir'ing to %s" % new)
261+
print(f"chdir'ing to {new}")
262262
old = os.getcwd()
263263
os.chdir(new)
264264
try:
@@ -272,11 +272,11 @@ def make_dist(name):
272272
os.mkdir(name)
273273
except OSError:
274274
if os.path.isdir(name):
275-
print("WARNING: dist dir %s already exists" % name, file=sys.stderr)
275+
print(f"WARNING: dist dir {name} already exists", file=sys.stderr)
276276
else:
277-
error("%s/ is not a directory" % name)
277+
error(f"{name}/ is not a directory")
278278
else:
279-
print("created dist directory %s" % name)
279+
print(f"created dist directory {name}")
280280

281281

282282
def tarball(source, clamp_mtime):
@@ -330,25 +330,25 @@ def tarball(source, clamp_mtime):
330330
def export(tag, silent=False, skip_docs=False):
331331
make_dist(tag.text)
332332
print("Exporting tag:", tag.text)
333-
archivename = "Python-%s" % tag.text
333+
archivename = f"Python-{tag.text}"
334334
# I have not figured out how to get git to directly produce an
335335
# archive directory like hg can, so use git to produce a temporary
336336
# tarball then expand it with tar.
337-
archivetempfile = "%s.tar" % archivename
337+
archivetempfile = f"{archivename}.tar"
338338
run_cmd(
339339
[
340340
"git",
341341
"archive",
342342
"--format=tar",
343-
"--prefix=%s/" % archivename,
343+
f"--prefix={archivename}/",
344344
"-o",
345345
archivetempfile,
346346
tag.gitname,
347347
],
348348
silent=silent,
349349
)
350350
with pushd(tag.text):
351-
archivetempfile = "../%s" % archivetempfile
351+
archivetempfile = f"../{archivetempfile}"
352352
run_cmd(["tar", "-xf", archivetempfile], silent=silent)
353353
os.unlink(archivetempfile)
354354
with pushd(archivename):
@@ -446,7 +446,7 @@ def export(tag, silent=False, skip_docs=False):
446446
os.mkdir("src")
447447
tarball(archivename, tag.committed_at.strftime("%Y-%m-%d %H:%M:%SZ"))
448448
print()
449-
print("**Now extract the archives in %s/src and run the tests**" % tag.text)
449+
print(f"**Now extract the archives in {tag.text}/src and run the tests**")
450450
print("**You may also want to run make install and re-test**")
451451

452452

@@ -469,16 +469,16 @@ def build_docs():
469469

470470
def upload(tag, username):
471471
"""scp everything to dinsdale"""
472-
address = '"%s@dinsdale.python.org:' % username
472+
address = f'"{username}@dinsdale.python.org:'
473473

474474
def scp(from_loc, to_loc):
475475
run_cmd(["scp", from_loc, address + to_loc])
476476

477477
with pushd(tag.text):
478478
print("Uploading source tarballs")
479-
scp("src", "/data/python-releases/%s" % tag.nickname)
479+
scp("src", f"/data/python-releases/{tag.nickname}")
480480
print("Upload doc tarballs")
481-
scp("docs", "/data/python-releases/doc/%s" % tag.nickname)
481+
scp("docs", f"/data/python-releases/doc/{tag.nickname}")
482482
print(
483483
"* Now change the permissions on the tarballs so they are "
484484
"writable by the webmaster group. *"
@@ -495,7 +495,7 @@ def __init__(self, tag_name):
495495
tag_name = os.path.basename(os.getcwd())
496496
result = tag_cre.match(tag_name)
497497
if result is None:
498-
error("tag %s is not valid" % tag_name)
498+
error(f"tag {tag_name} is not valid")
499499
data = list(result.groups())
500500
if data[3] is None:
501501
# A final release.

run_release.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ def sign_source_artifacts(db: DbfilenameShelf) -> None:
526526
uid = input("Please enter key ID to use for signing: ")
527527

528528
tarballs_path = pathlib.Path(db["git_repo"] / str(db["release"]) / "src")
529-
tgz = str(tarballs_path / ("Python-%s.tgz" % db["release"]))
530-
xz = str(tarballs_path / ("Python-%s.tar.xz" % db["release"]))
529+
tgz = str(tarballs_path / (f"Python-{db['release']}.tgz"))
530+
xz = str(tarballs_path / (f"Python-{db['release']}.tar.xz"))
531531

532532
subprocess.check_call(["gpg", "-bas", "-u", uid, tgz])
533533
subprocess.check_call(["gpg", "-bas", "-u", uid, xz])

0 commit comments

Comments
 (0)