Skip to content

Commit 5a93542

Browse files
pre-commit-ci[bot]consideRatio
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ce44f98 commit 5a93542

36 files changed

+139
-167
lines changed

repo2docker/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __call__(self, parser, namespace, values, option_string=None):
5252
# key pass using current value, or don't pass
5353
if "=" not in values:
5454
try:
55-
value_to_append = "{}={}".format(values, os.environ[values])
55+
value_to_append = f"{values}={os.environ[values]}"
5656
except KeyError:
5757
# no local def, so don't pass
5858
return

repo2docker/_version.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
8484
stderr=(subprocess.PIPE if hide_stderr else None),
8585
)
8686
break
87-
except EnvironmentError:
87+
except OSError:
8888
e = sys.exc_info()[1]
8989
if e.errno == errno.ENOENT:
9090
continue
@@ -94,7 +94,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
9494
return None, None
9595
else:
9696
if verbose:
97-
print("unable to find command, tried %s" % (commands,))
97+
print(f"unable to find command, tried {commands}")
9898
return None, None
9999
stdout = p.communicate()[0].strip()
100100
if sys.version_info[0] >= 3:
@@ -147,7 +147,7 @@ def git_get_keywords(versionfile_abs):
147147
# _version.py.
148148
keywords = {}
149149
try:
150-
f = open(versionfile_abs, "r")
150+
f = open(versionfile_abs)
151151
for line in f.readlines():
152152
if line.strip().startswith("git_refnames ="):
153153
mo = re.search(r'=\s*"(.*)"', line)
@@ -162,7 +162,7 @@ def git_get_keywords(versionfile_abs):
162162
if mo:
163163
keywords["date"] = mo.group(1)
164164
f.close()
165-
except EnvironmentError:
165+
except OSError:
166166
pass
167167
return keywords
168168

@@ -186,11 +186,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
186186
if verbose:
187187
print("keywords are unexpanded, not using")
188188
raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
189-
refs = set([r.strip() for r in refnames.strip("()").split(",")])
189+
refs = {r.strip() for r in refnames.strip("()").split(",")}
190190
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
191191
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
192192
TAG = "tag: "
193-
tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)])
193+
tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)}
194194
if not tags:
195195
# Either we're using git < 1.8.3, or there really are no tags. We use
196196
# a heuristic: assume all version tags have a digit. The old git %d
@@ -199,7 +199,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
199199
# between branches and tags. By ignoring refnames without digits, we
200200
# filter out many common branch names like "release" and
201201
# "stabilization", as well as "HEAD" and "master".
202-
tags = set([r for r in refs if re.search(r"\d", r)])
202+
tags = {r for r in refs if re.search(r"\d", r)}
203203
if verbose:
204204
print("discarding '%s', no digits" % ",".join(refs - tags))
205205
if verbose:
@@ -302,7 +302,7 @@ 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 '%s' doesn't start with prefix '%s'" % (
305+
pieces["error"] = "tag '{}' doesn't start with prefix '{}'".format(
306306
full_tag,
307307
tag_prefix,
308308
)

repo2docker/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def push_image(self):
568568
)
569569
last_emit_time = time.time()
570570
self.log.info(
571-
"Successfully pushed {}".format(self.output_image_spec),
571+
f"Successfully pushed {self.output_image_spec}",
572572
extra=dict(phase=R2dState.PUSHING),
573573
)
574574

@@ -767,7 +767,7 @@ def build(self):
767767
self.subdir,
768768
extra=dict(phase=R2dState.FAILED),
769769
)
770-
raise FileNotFoundError("Could not find {}".format(checkout_path))
770+
raise FileNotFoundError(f"Could not find {checkout_path}")
771771

772772
with chdir(checkout_path):
773773
for BP in self.buildpacks:

repo2docker/buildpacks/base.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def render(self, build_args=None):
462462
last_user = "root"
463463
for user, script in self.get_build_scripts():
464464
if last_user != user:
465-
build_script_directives.append("USER {}".format(user))
465+
build_script_directives.append(f"USER {user}")
466466
last_user = user
467467
build_script_directives.append(
468468
"RUN {}".format(textwrap.dedent(script.strip("\n")))
@@ -472,7 +472,7 @@ def render(self, build_args=None):
472472
last_user = "root"
473473
for user, script in self.get_assemble_scripts():
474474
if last_user != user:
475-
assemble_script_directives.append("USER {}".format(user))
475+
assemble_script_directives.append(f"USER {user}")
476476
last_user = user
477477
assemble_script_directives.append(
478478
"RUN {}".format(textwrap.dedent(script.strip("\n")))
@@ -482,7 +482,7 @@ def render(self, build_args=None):
482482
last_user = "root"
483483
for user, script in self.get_preassemble_scripts():
484484
if last_user != user:
485-
preassemble_script_directives.append("USER {}".format(user))
485+
preassemble_script_directives.append(f"USER {user}")
486486
last_user = user
487487
preassemble_script_directives.append(
488488
"RUN {}".format(textwrap.dedent(script.strip("\n")))
@@ -616,8 +616,7 @@ def _filter_tar(tar):
616616

617617
build_kwargs.update(extra_build_kwargs)
618618

619-
for line in client.build(**build_kwargs):
620-
yield line
619+
yield from client.build(**build_kwargs)
621620

622621

623622
class BaseImage(BuildPack):

repo2docker/buildpacks/conda/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def get_env_scripts(self):
377377
r"""
378378
echo auth-none=1 >> /etc/rstudio/rserver.conf && \
379379
echo auth-minimum-user-id=0 >> /etc/rstudio/rserver.conf && \
380-
echo "rsession-which-r={0}/bin/R" >> /etc/rstudio/rserver.conf && \
380+
echo "rsession-which-r={}/bin/R" >> /etc/rstudio/rserver.conf && \
381381
echo www-frame-origin=same >> /etc/rstudio/rserver.conf
382382
""".format(
383383
env_prefix
@@ -387,7 +387,7 @@ def get_env_scripts(self):
387387
"${NB_USER}",
388388
# Register the jupyter kernel
389389
r"""
390-
R --quiet -e "IRkernel::installspec(prefix='{0}')"
390+
R --quiet -e "IRkernel::installspec(prefix='{}')"
391391
""".format(
392392
env_prefix
393393
),

repo2docker/buildpacks/docker.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,4 @@ def build(
5757

5858
build_kwargs.update(extra_build_kwargs)
5959

60-
for line in client.build(**build_kwargs):
61-
yield line
60+
yield from client.build(**build_kwargs)

repo2docker/buildpacks/legacy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def detect(self):
2020
"""Check if current repo should be built with the Legacy BuildPack."""
2121
log = logging.getLogger("repo2docker")
2222
try:
23-
with open("Dockerfile", "r") as f:
23+
with open("Dockerfile") as f:
2424
for line in f:
2525
if line.startswith("FROM"):
2626
if "andrewosh/binder-base" in line.split("#")[0].lower():

repo2docker/buildpacks/python/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _get_pip_scripts(self):
6767
scripts.append(
6868
(
6969
"${NB_USER}",
70-
'{} install --no-cache-dir -r "{}"'.format(pip, requirements_file),
70+
f'{pip} install --no-cache-dir -r "{requirements_file}"',
7171
)
7272
)
7373
return scripts
@@ -126,9 +126,7 @@ def get_assemble_scripts(self):
126126

127127
# setup.py exists *and* binder dir is not used
128128
if not self.binder_dir and os.path.exists(setup_py):
129-
assemble_scripts.append(
130-
("${NB_USER}", "{} install --no-cache-dir .".format(pip))
131-
)
129+
assemble_scripts.append(("${NB_USER}", f"{pip} install --no-cache-dir ."))
132130
return assemble_scripts
133131

134132
def detect(self):

repo2docker/buildpacks/r.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def detect(self):
139139
self._checkpoint_date = datetime.date.today() - datetime.timedelta(
140140
days=2
141141
)
142-
self._runtime = "r-{}".format(str(self._checkpoint_date))
142+
self._runtime = f"r-{str(self._checkpoint_date)}"
143143
return True
144144

145145
def get_env(self):
@@ -223,7 +223,7 @@ def get_mran_snapshot_url(self, snapshot_date, max_days_prior=7):
223223
for i in range(max_days_prior):
224224
try_date = snapshot_date - datetime.timedelta(days=i)
225225
# Fall back to MRAN if packagemanager.rstudio.com doesn't have it
226-
url = "https://mran.microsoft.com/snapshot/{}".format(try_date.isoformat())
226+
url = f"https://mran.microsoft.com/snapshot/{try_date.isoformat()}"
227227
r = requests.head(url)
228228
if r.ok:
229229
return url

repo2docker/contentproviders/dataverse.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Dataverse(DoiProvider):
2020

2121
def __init__(self):
2222
data_file = os.path.join(os.path.dirname(__file__), "dataverse.json")
23-
with open(data_file, "r") as fp:
23+
with open(data_file) as fp:
2424
self.hosts = json.load(fp)["installations"]
2525
super().__init__()
2626

@@ -97,7 +97,7 @@ def fetch(self, spec, output_dir, yield_output=False):
9797
record_id = spec["record"]
9898
host = spec["host"]
9999

100-
yield "Fetching Dataverse record {}.\n".format(record_id)
100+
yield f"Fetching Dataverse record {record_id}.\n"
101101
url = "{}/api/datasets/:persistentId?persistentId={}".format(
102102
host["url"], record_id
103103
)
@@ -114,8 +114,7 @@ def fetch(self, spec, output_dir, yield_output=False):
114114
file_ref = {"download": file_url, "filename": filename}
115115
fetch_map = {key: key for key in file_ref.keys()}
116116

117-
for line in self.fetch_file(file_ref, fetch_map, output_dir):
118-
yield line
117+
yield from self.fetch_file(file_ref, fetch_map, output_dir)
119118

120119
new_subdirs = os.listdir(output_dir)
121120
# if there is only one new subdirectory move its contents

0 commit comments

Comments
 (0)