Skip to content

Commit 15a1fb6

Browse files
committed
refactor: manually add transitions to f-strings
1 parent 5a93542 commit 15a1fb6

27 files changed

+90
-152
lines changed

docs/source/conf.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,10 @@
6161

6262
default_python = CondaBuildPack.major_pythons["3"]
6363

64-
rst_prolog = """
64+
rst_prolog = f"""
6565
.. |default_python| replace:: **Python {default_python}**
6666
.. |default_python_version| replace:: {default_python}
67-
""".format(
68-
default_python=default_python
69-
)
67+
"""
7068

7169

7270
# -- Options for HTML output -------------------------------------------------

repo2docker/__main__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ def make_r2d(argv=None):
304304
r2d.volumes[os.path.abspath(args.repo)] = "."
305305
else:
306306
r2d.log.error(
307-
'Cannot mount "{}" in editable mode '
308-
"as it is not a directory".format(args.repo),
307+
f'Cannot mount "{args.repo}" in editable mode '
308+
"as it is not a directory",
309309
extra=dict(phase=R2dState.FAILED),
310310
)
311311
sys.exit(1)

repo2docker/_version.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
293293
mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
294294
if not mo:
295295
# unparseable. Maybe git-describe is misbehaving?
296-
pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
296+
pieces["error"] = f"unable to parse git-describe output: '{describe_out}'"
297297
return pieces
298298

299299
# tag
@@ -302,10 +302,9 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
302302
if verbose:
303303
fmt = "tag '%s' doesn't start with prefix '%s'"
304304
print(fmt % (full_tag, tag_prefix))
305-
pieces["error"] = "tag '{}' doesn't start with prefix '{}'".format(
306-
full_tag,
307-
tag_prefix,
308-
)
305+
pieces[
306+
"error"
307+
] = f"tag '{full_tag}' doesn't start with prefix '{tag_prefix}'"
309308
return pieces
310309
pieces["closest-tag"] = full_tag[len(tag_prefix) :]
311310

repo2docker/app.py

+11-24
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,7 @@ def get_engine(self):
425425
entry = engines[self.engine]
426426
except KeyError:
427427
raise ContainerEngineException(
428-
"Container engine '{}' not found. Available engines: {}".format(
429-
self.engine, ",".join(engines.keys())
430-
)
428+
f"Container engine '{self.engine}' not found. Available engines: {','.join(engines.keys())}"
431429
)
432430
engine_class = entry.load()
433431
return engine_class(parent=self)
@@ -447,16 +445,11 @@ def fetch(self, url, ref, checkout_path):
447445
spec = cp.detect(url, ref=ref)
448446
if spec is not None:
449447
picked_content_provider = cp
450-
self.log.info(
451-
"Picked {cp} content "
452-
"provider.\n".format(cp=cp.__class__.__name__)
453-
)
448+
self.log.info(f"Picked {cp.__class__.__name__} content provider.\n")
454449
break
455450

456451
if picked_content_provider is None:
457-
self.log.error(
458-
"No matching content provider found for " "{url}.".format(url=url)
459-
)
452+
self.log.error(f"No matching content provider found for {url}.")
460453

461454
swh_token = self.config.get("swh_token", self.swh_token)
462455
if swh_token and isinstance(picked_content_provider, contentproviders.Swhid):
@@ -488,8 +481,7 @@ def json_excepthook(self, etype, evalue, traceback):
488481
Avoids non-JSON output on errors when using --json-logs
489482
"""
490483
self.log.error(
491-
"Error during build: %s",
492-
evalue,
484+
f"Error during build: {evalue}",
493485
exc_info=(etype, evalue, traceback),
494486
extra=dict(phase=R2dState.FAILED),
495487
)
@@ -619,11 +611,9 @@ def start_container(self):
619611
run_cmd = [
620612
"jupyter",
621613
"notebook",
622-
"--ip",
623-
"0.0.0.0",
624-
"--port",
625-
container_port,
626-
f"--NotebookApp.custom_display_url=http://{host_name}:{host_port}"
614+
"--ip=0.0.0.0",
615+
f"--port={container_port}",
616+
f"--NotebookApp.custom_display_url=http://{host_name}:{host_port}",
627617
"--NotebookApp.default_url=/lab",
628618
]
629619
else:
@@ -730,7 +720,7 @@ def build(self):
730720
try:
731721
docker_client = self.get_engine()
732722
except ContainerEngineException as e:
733-
self.log.error("\nContainer engine initialization error: %s\n", e)
723+
self.log.error(f"\nContainer engine initialization error: {e}\n")
734724
self.exit(1)
735725

736726
# If the source to be executed is a directory, continue using the
@@ -751,8 +741,7 @@ def build(self):
751741

752742
if self.find_image():
753743
self.log.info(
754-
"Reusing existing image ({}), not "
755-
"building.".format(self.output_image_spec)
744+
f"Reusing existing image ({self.output_image_spec}), not building."
756745
)
757746
# no need to build, so skip to the end by `return`ing here
758747
# this will still execute the finally clause and let's us
@@ -763,8 +752,7 @@ def build(self):
763752
checkout_path = os.path.join(checkout_path, self.subdir)
764753
if not os.path.isdir(checkout_path):
765754
self.log.error(
766-
"Subdirectory %s does not exist",
767-
self.subdir,
755+
f"Subdirectory {self.subdir} does not exist",
768756
extra=dict(phase=R2dState.FAILED),
769757
)
770758
raise FileNotFoundError(f"Could not find {checkout_path}")
@@ -808,8 +796,7 @@ def build(self):
808796
)
809797

810798
self.log.info(
811-
"Using %s builder\n",
812-
bp.__class__.__name__,
799+
f"Using {bp.__class__.__name__} builder\n",
813800
extra=dict(phase=R2dState.BUILDING),
814801
)
815802

repo2docker/buildpacks/_r_base.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def rstudio_base_scripts(r_version):
2626
# we should have --no-install-recommends on all our apt-get install commands,
2727
# but here it's important because these recommend r-base,
2828
# which will upgrade the installed version of R, undoing our pinned version
29-
r"""
29+
rf"""
3030
curl --silent --location --fail {rstudio_url} > /tmp/rstudio.deb && \
3131
curl --silent --location --fail {shiny_server_url} > /tmp/shiny.deb && \
3232
echo '{rstudio_sha256sum} /tmp/rstudio.deb' | sha256sum -c - && \
@@ -37,24 +37,16 @@ def rstudio_base_scripts(r_version):
3737
apt-get -qq purge && \
3838
apt-get -qq clean && \
3939
rm -rf /var/lib/apt/lists/*
40-
""".format(
41-
rstudio_url=rstudio_url,
42-
rstudio_sha256sum=rstudio_sha256sum,
43-
shiny_server_url=shiny_server_url,
44-
shiny_sha256sum=shiny_sha256sum,
45-
),
40+
""",
4641
),
4742
(
4843
"${NB_USER}",
4944
# Install jupyter-rsession-proxy
50-
r"""
45+
rf"""
5146
pip install --no-cache \
5247
jupyter-rsession-proxy=={rsession_proxy_version} \
5348
jupyter-shiny-proxy=={shiny_proxy_version}
54-
""".format(
55-
rsession_proxy_version=rsession_proxy_version,
56-
shiny_proxy_version=shiny_proxy_version,
57-
),
49+
""",
5850
),
5951
(
6052
# Not all of these locations are configurable; so we make sure

repo2docker/buildpacks/base.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,8 @@ def _filter_tar(tar):
594594
# buildpacks/docker.py where it is duplicated
595595
if not isinstance(memory_limit, int):
596596
raise ValueError(
597-
"The memory limit has to be specified as an"
598-
"integer but is '{}'".format(type(memory_limit))
597+
"The memory limit has to be specified as an "
598+
f"integer but is '{type(memory_limit)}'"
599599
)
600600
limits = {}
601601
if memory_limit:
@@ -647,8 +647,7 @@ def get_preassemble_scripts(self):
647647
# FIXME: Add support for specifying version numbers
648648
if not re.match(r"^[a-z0-9.+-]+", package):
649649
raise ValueError(
650-
"Found invalid package name {} in "
651-
"apt.txt".format(package)
650+
f"Found invalid package name {package} in apt.txt"
652651
)
653652
extra_apt_packages.append(package)
654653

repo2docker/buildpacks/conda/__init__.py

+14-22
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,13 @@ def get_env_scripts(self):
341341
scripts.append(
342342
(
343343
"${NB_USER}",
344-
r"""
344+
rf"""
345345
TIMEFORMAT='time: %3R' \
346-
bash -c 'time ${{MAMBA_EXE}} env update -p {0} --file "{1}" && \
346+
bash -c 'time ${{MAMBA_EXE}} env update -p {env_prefix} --file "{environment_yml}" && \
347347
time ${{MAMBA_EXE}} clean --all -f -y && \
348-
${{MAMBA_EXE}} list -p {0} \
348+
${{MAMBA_EXE}} list -p {env_prefix} \
349349
'
350-
""".format(
351-
env_prefix, environment_yml
352-
),
350+
""",
353351
)
354352
)
355353

@@ -361,36 +359,30 @@ def get_env_scripts(self):
361359
scripts.append(
362360
(
363361
"${NB_USER}",
364-
r"""
365-
${{MAMBA_EXE}} install -p {0} r-base{1} r-irkernel r-devtools -y && \
362+
rf"""
363+
${{MAMBA_EXE}} install -p {env_prefix} r-base{r_pin} r-irkernel r-devtools -y && \
366364
${{MAMBA_EXE}} clean --all -f -y && \
367-
${{MAMBA_EXE}} list -p {0}
368-
""".format(
369-
env_prefix, r_pin
370-
),
365+
${{MAMBA_EXE}} list -p {env_prefix}
366+
""",
371367
)
372368
)
373369
scripts += rstudio_base_scripts(self.r_version)
374370
scripts += [
375371
(
376372
"root",
377-
r"""
373+
rf"""
378374
echo auth-none=1 >> /etc/rstudio/rserver.conf && \
379375
echo auth-minimum-user-id=0 >> /etc/rstudio/rserver.conf && \
380-
echo "rsession-which-r={}/bin/R" >> /etc/rstudio/rserver.conf && \
376+
echo "rsession-which-r={env_prefix}/bin/R" >> /etc/rstudio/rserver.conf && \
381377
echo www-frame-origin=same >> /etc/rstudio/rserver.conf
382-
""".format(
383-
env_prefix
384-
),
378+
""",
385379
),
386380
(
387381
"${NB_USER}",
388382
# Register the jupyter kernel
389-
r"""
390-
R --quiet -e "IRkernel::installspec(prefix='{}')"
391-
""".format(
392-
env_prefix
393-
),
383+
rf"""
384+
R --quiet -e "IRkernel::installspec(prefix='{env_prefix}')"
385+
""",
394386
),
395387
]
396388
return scripts

repo2docker/buildpacks/docker.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def build(
3434
# buildpacks/base.py where it is duplicated
3535
if not isinstance(memory_limit, int):
3636
raise ValueError(
37-
"The memory limit has to be specified as an"
38-
"integer but is '{}'".format(type(memory_limit))
37+
"The memory limit has to be specified as an "
38+
f"integer but is '{type(memory_limit)}'"
3939
)
4040
limits = {}
4141
if memory_limit:

repo2docker/buildpacks/nix/__init__.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ def get_assemble_scripts(self):
6262
return super().get_assemble_scripts() + [
6363
(
6464
"${NB_USER}",
65-
"""
65+
f"""
6666
nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs && \
6767
nix-channel --update && \
68-
nix-shell {}
69-
""".format(
70-
self.binder_path("default.nix")
71-
),
68+
nix-shell {self.binder_path("default.nix")}
69+
""",
7270
)
7371
]
7472

repo2docker/buildpacks/pipfile/__init__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ def get_assemble_scripts(self):
123123
assemble_scripts.append(
124124
(
125125
"${NB_USER}",
126-
'${{NB_PYTHON_PREFIX}}/bin/pip install --no-cache-dir -r "{}"'.format(
127-
nb_requirements_file
128-
),
126+
f'${{NB_PYTHON_PREFIX}}/bin/pip install --no-cache-dir -r "{nb_requirements_file}"',
129127
)
130128
)
131129

repo2docker/buildpacks/python/__init__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ def _get_pip_scripts(self):
5555
"${NB_USER}",
5656
# want the $NB_PYHTON_PREFIX environment variable, not for
5757
# Python's string formatting to try and replace this
58-
'${{NB_PYTHON_PREFIX}}/bin/pip install --no-cache-dir -r "{}"'.format(
59-
nb_requirements_file
60-
),
58+
f'${{NB_PYTHON_PREFIX}}/bin/pip install --no-cache-dir -r "{nb_requirements_file}"',
6159
)
6260
)
6361

repo2docker/buildpacks/r.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,10 @@ def get_build_scripts(self):
336336
(
337337
"${NB_USER}",
338338
# Install a pinned version of devtools, IRKernel and shiny
339-
r"""
340-
R --quiet -e "install.packages(c('devtools', 'IRkernel', 'shiny'), repos='{devtools_cran_mirror_url}')" && \
339+
rf"""
340+
R --quiet -e "install.packages(c('devtools', 'IRkernel', 'shiny'), repos='{self.get_devtools_snapshot_url()}')" && \
341341
R --quiet -e "IRkernel::installspec(prefix='$NB_PYTHON_PREFIX')"
342-
""".format(
343-
devtools_cran_mirror_url=self.get_devtools_snapshot_url()
344-
),
342+
""",
345343
),
346344
]
347345

@@ -374,8 +372,7 @@ def get_preassemble_scripts(self):
374372
"${NB_USER}",
375373
# Delete /tmp/downloaded_packages only if install.R fails, as the second
376374
# invocation of install.R might be able to reuse them
377-
"Rscript %s && touch /tmp/.preassembled || true && rm -rf /tmp/downloaded_packages"
378-
% installR_path,
375+
f"Rscript {installR_path} && touch /tmp/.preassembled || true && rm -rf /tmp/downloaded_packages",
379376
)
380377
]
381378

@@ -392,9 +389,7 @@ def get_assemble_scripts(self):
392389
"${NB_USER}",
393390
# only run install.R if the pre-assembly failed
394391
# Delete any downloaded packages in /tmp, as they aren't reused by R
395-
"""if [ ! -f /tmp/.preassembled ]; then Rscript {}; rm -rf /tmp/downloaded_packages; fi""".format(
396-
installR_path
397-
),
392+
f"""if [ ! -f /tmp/.preassembled ]; then Rscript {installR_path}; rm -rf /tmp/downloaded_packages; fi""",
398393
)
399394
]
400395

repo2docker/contentproviders/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ def detect(self, source, ref=None, extra_args=None):
6868

6969
def fetch(self, spec, output_dir, yield_output=False):
7070
# nothing to be done if your content is already in the output directory
71-
msg = "Local content provider assumes {} == {}".format(spec["path"], output_dir)
71+
msg = f'Local content provider assumes {spec["path"]} == {output_dir}'
7272
assert output_dir == spec["path"], msg
73-
yield "Using local repo {}.\n".format(spec["path"])
73+
yield f'Using local repo {spec["path"]}.\n'

repo2docker/contentproviders/dataverse.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ def detect(self, doi, ref=None, extra_args=None):
7676
data = self.urlopen(search_url).json()["data"]
7777
if data["count_in_response"] != 1:
7878
self.log.debug(
79-
"Dataverse search query failed!\n - doi: {}\n - url: {}\n - resp: {}\n".format(
80-
doi, url, json.dump(data)
81-
)
79+
f"Dataverse search query failed!\n - doi: {doi}\n - url: {url}\n - resp: {json.dump(data)}\n"
8280
)
8381
return
8482

@@ -98,16 +96,14 @@ def fetch(self, spec, output_dir, yield_output=False):
9896
host = spec["host"]
9997

10098
yield f"Fetching Dataverse record {record_id}.\n"
101-
url = "{}/api/datasets/:persistentId?persistentId={}".format(
102-
host["url"], record_id
103-
)
99+
url = f'{host["url"]}/api/datasets/:persistentId?persistentId={record_id}'
104100

105101
resp = self.urlopen(url, headers={"accept": "application/json"})
106102
record = resp.json()["data"]
107103

108104
for fobj in deep_get(record, "latestVersion.files"):
109-
file_url = "{}/api/access/datafile/{}".format(
110-
host["url"], deep_get(fobj, "dataFile.id")
105+
file_url = (
106+
f'{host["url"]}/api/access/datafile/{deep_get(fobj, "dataFile.id")}'
111107
)
112108
filename = os.path.join(fobj.get("directoryLabel", ""), fobj["label"])
113109

0 commit comments

Comments
 (0)