Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#5320)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.1 → v0.4.2](astral-sh/ruff-pre-commit@v0.4.1...v0.4.2)

* Format

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ken Odegard <kodegard@anaconda.com>
Co-authored-by: Bianca Henderson <bhenderson@anaconda.com>
  • Loading branch information
3 people authored Apr 30, 2024
1 parent e235104 commit 2fb469a
Show file tree
Hide file tree
Showing 30 changed files with 192 additions and 207 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ repos:
# auto format Python codes within docstrings
- id: blacken-docs
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.1
rev: v0.4.2
hooks:
# lint & attempt to correct failures (e.g. pyupgrade)
- id: ruff
Expand Down
14 changes: 7 additions & 7 deletions conda_build/_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
SITE_PACKAGES = "Lib/site-packages"
else:
BIN_DIR = join(PREFIX, "bin")
SITE_PACKAGES = "lib/python%s/site-packages" % sys.version[:3]
SITE_PACKAGES = f"lib/python{sys.version[:3]}/site-packages"

# the list of these files is going to be store in info/_files
FILES = []
Expand Down Expand Up @@ -110,20 +110,20 @@ def create_script(fn):
dst = join(BIN_DIR, fn)
if sys.platform == "win32":
shutil.copy2(src, dst + "-script.py")
FILES.append("Scripts/%s-script.py" % fn)
FILES.append(f"Scripts/{fn}-script.py")
shutil.copy2(
join(THIS_DIR, "cli-%d.exe" % (8 * tuple.__itemsize__)), dst + ".exe"
)
FILES.append("Scripts/%s.exe" % fn)
FILES.append(f"Scripts/{fn}.exe")
else:
with open(src) as fi:
data = fi.read()
with open(dst, "w") as fo:
shebang = replace_long_shebang("#!%s\n" % normpath(sys.executable))
shebang = replace_long_shebang(f"#!{normpath(sys.executable)}\n")
fo.write(shebang)
fo.write(data)
os.chmod(dst, 0o775)
FILES.append("bin/%s" % fn)
FILES.append(f"bin/{fn}")


def create_scripts(files):
Expand All @@ -140,9 +140,9 @@ def main():
link_files("site-packages", SITE_PACKAGES, DATA["site-packages"])
link_files("Examples", "Examples", DATA["Examples"])

with open(join(PREFIX, "conda-meta", "%s.files" % DATA["dist"]), "w") as fo:
with open(join(PREFIX, "conda-meta", "{}.files".format(DATA["dist"])), "w") as fo:
for f in FILES:
fo.write("%s\n" % f)
fo.write(f"{f}\n")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion conda_build/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def convert(
"Conversion from wheel packages is not implemented yet, stay tuned."
)
else:
raise RuntimeError("cannot convert: %s" % package_file)
raise RuntimeError(f"cannot convert: {package_file}")


def test_installable(channel: str = "defaults") -> bool:
Expand Down
27 changes: 13 additions & 14 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ def copy_readme(m):
if readme:
src = join(m.config.work_dir, readme)
if not isfile(src):
sys.exit("Error: no readme file: %s" % readme)
sys.exit(f"Error: no readme file: {readme}")
dst = join(m.config.info_dir, readme)
utils.copy_into(src, dst, m.config.timeout, locking=m.config.locking)
if os.path.split(readme)[1] not in {"README.md", "README.rst", "README"}:
Expand Down Expand Up @@ -1187,7 +1187,7 @@ def record_prefix_files(m, files_with_prefix):
if fn in text_has_prefix_files:
text_has_prefix_files.remove(fn)
else:
ignored_because = " (not in build/%s_has_prefix_files)" % (mode)
ignored_because = f" (not in build/{mode}_has_prefix_files)"

print(
"{fn} ({mode}): {action}{reason}".format(
Expand All @@ -1204,10 +1204,10 @@ def record_prefix_files(m, files_with_prefix):
# make sure we found all of the files expected
errstr = ""
for f in text_has_prefix_files:
errstr += "Did not detect hard-coded path in %s from has_prefix_files\n" % f
errstr += f"Did not detect hard-coded path in {f} from has_prefix_files\n"
for f in binary_has_prefix_files:
errstr += (
"Did not detect hard-coded path in %s from binary_has_prefix_files\n" % f
f"Did not detect hard-coded path in {f} from binary_has_prefix_files\n"
)
if errstr:
raise RuntimeError(errstr)
Expand Down Expand Up @@ -1276,7 +1276,7 @@ def write_about_json(m):
with open(join(m.config.info_dir, "about.json"), "w") as fo:
d = {}
for key, default in FIELDS["about"].items():
value = m.get_value("about/%s" % key)
value = m.get_value(f"about/{key}")
if value:
d[key] = value
if default is list:
Expand Down Expand Up @@ -1332,7 +1332,7 @@ def write_info_json(m: MetaData):
"# $ conda create --name <env> --file <this file>"
)
for dist in sorted(runtime_deps + [" ".join(m.dist().rsplit("-", 2))]):
fo.write("%s\n" % "=".join(dist.split()))
fo.write("{}\n".format("=".join(dist.split())))

mode_dict = {"mode": "w", "encoding": "utf-8"}
with open(join(m.config.info_dir, "index.json"), **mode_dict) as fo:
Expand All @@ -1355,10 +1355,10 @@ def get_entry_point_script_names(entry_point_scripts):
for entry_point in entry_point_scripts:
cmd = entry_point[: entry_point.find("=")].strip()
if utils.on_win:
scripts.append("Scripts\\%s-script.py" % cmd)
scripts.append("Scripts\\%s.exe" % cmd)
scripts.append(f"Scripts\\{cmd}-script.py")
scripts.append(f"Scripts\\{cmd}.exe")
else:
scripts.append("bin/%s" % cmd)
scripts.append(f"bin/{cmd}")
return scripts


Expand Down Expand Up @@ -1520,7 +1520,7 @@ def _recurse_symlink_to_size(path, seen=None):
return _recurse_symlink_to_size(dest, seen=seen)
elif not isfile(dest):
# this is a symlink that points to nowhere, so is zero bytes
warnings.warn("file %s is a symlink with no target" % path, UserWarning)
warnings.warn(f"file {path} is a symlink with no target", UserWarning)
return 0

return 0
Expand Down Expand Up @@ -1764,8 +1764,7 @@ def bundle_conda(output, metadata: MetaData, env, stats, **kw):
var = var.split("=", 1)[0]
elif var not in os.environ:
warnings.warn(
"The environment variable '%s' specified in script_env is undefined."
% var,
f"The environment variable '{var}' specified in script_env is undefined.",
UserWarning,
)
val = ""
Expand Down Expand Up @@ -3295,9 +3294,9 @@ def test(
os.path.dirname(prefix),
"_".join(
(
"%s_prefix_moved" % name,
f"{name}_prefix_moved",
metadata.dist(),
getattr(metadata.config, "%s_subdir" % name),
getattr(metadata.config, f"{name}_subdir"),
)
),
)
Expand Down
2 changes: 1 addition & 1 deletion conda_build/cli/main_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_render_parser() -> ArgumentParser:
"--version",
action="version",
help="Show the conda-build version number and exit.",
version="conda-build %s" % __version__,
version=f"conda-build {__version__}",
)
p.add_argument(
"-n",
Expand Down
24 changes: 13 additions & 11 deletions conda_build/create_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _create_test_files(
fo.write(
f"{comment_char} tests for {m.dist()} (this is a generated file);\n"
)
fo.write("print('===== testing package: %s =====');\n" % m.dist())
fo.write(f"print('===== testing package: {m.dist()} =====');\n")

try:
with open(test_file) as fi:
Expand All @@ -134,7 +134,7 @@ def _create_test_files(
fo.write(
"# tests were not packaged with this module, and cannot be run\n"
)
fo.write("\nprint('===== %s OK =====');\n" % m.dist())
fo.write(f"\nprint('===== {m.dist()} OK =====');\n")
return (
out_file,
bool(name) and isfile(out_file) and basename(test_file) != "no-file",
Expand Down Expand Up @@ -175,8 +175,8 @@ def create_py_files(m: MetaData, test_dir: os.PathLike) -> bool:
if imports:
with open(tf, "a") as fo:
for name in imports:
fo.write('print("import: %r")\n' % name)
fo.write("import %s\n" % name)
fo.write(f'print("import: {name!r}")\n')
fo.write(f"import {name}\n")
fo.write("\n")
return tf if (tf_exists or imports) else False

Expand All @@ -202,8 +202,8 @@ def create_r_files(m: MetaData, test_dir: os.PathLike) -> bool:
if imports:
with open(tf, "a") as fo:
for name in imports:
fo.write('print("library(%r)")\n' % name)
fo.write("library(%s)\n" % name)
fo.write(f'print("library({name!r})")\n')
fo.write(f"library({name})\n")
fo.write("\n")
return tf if (tf_exists or imports) else False

Expand All @@ -225,11 +225,13 @@ def create_pl_files(m: MetaData, test_dir: os.PathLike) -> bool:
break
if tf_exists or imports:
with open(tf, "a") as fo:
print(r'my $expected_version = "%s";' % m.version().rstrip("0"), file=fo)
print(
r'my $expected_version = "{}";'.format(m.version().rstrip("0")), file=fo
)
if imports:
for name in imports:
print(r'print("import: %s\n");' % name, file=fo)
print("use %s;\n" % name, file=fo)
print(rf'print("import: {name}\n");', file=fo)
print(f"use {name};\n", file=fo)
# Don't try to print version for complex imports
if " " not in name:
print(
Expand Down Expand Up @@ -264,8 +266,8 @@ def create_lua_files(m: MetaData, test_dir: os.PathLike) -> bool:
if imports:
with open(tf, "a+") as fo:
for name in imports:
print(r'print("require \"%s\"\n");' % name, file=fo)
print('require "%s"\n' % name, file=fo)
print(rf'print("require \"{name}\"\n");', file=fo)
print(f'require "{name}"\n', file=fo)
return tf if (tf_exists or imports) else False


Expand Down
5 changes: 2 additions & 3 deletions conda_build/develop.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,11 @@ def execute(
) -> None:
if not isdir(prefix):
sys.exit(
"""\
Error: environment does not exist: %s
f"""\
Error: environment does not exist: {prefix}
#
# Use 'conda create' to create the environment first.
#"""
% prefix
)

assert find_executable("python", prefix=prefix)
Expand Down
13 changes: 6 additions & 7 deletions conda_build/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,7 @@ def meta_vars(meta: MetaData, skip_build_id=False):
value = os.getenv(var_name)
if value is None:
warnings.warn(
"The environment variable '%s' specified in script_env is undefined."
% var_name,
f"The environment variable '{var_name}' specified in script_env is undefined.",
UserWarning,
)
else:
Expand Down Expand Up @@ -855,7 +854,7 @@ def get_install_actions(
capture = utils.capture
for feature, value in feature_list:
if value:
specs.append("%s@" % feature)
specs.append(f"{feature}@")

bldpkgs_dirs = ensure_list(bldpkgs_dirs)

Expand Down Expand Up @@ -961,7 +960,7 @@ def get_install_actions(
# specs are the raw specifications, not the conda-derived actual specs
# We're testing that pip etc. are manually specified
if not any(
re.match(r"^%s(?:$|[\s=].*)" % pkg, str(dep)) for dep in specs
re.match(rf"^{pkg}(?:$|[\s=].*)", str(dep)) for dep in specs
):
precs = [prec for prec in precs if prec.name != pkg]
cached_precs[(specs, env, subdir, channel_urls, disable_pip)] = precs.copy()
Expand Down Expand Up @@ -1341,7 +1340,7 @@ def _display_actions(prefix, precs):

builder = ["", "## Package Plan ##\n"]
if prefix:
builder.append(" environment location: %s" % prefix)
builder.append(f" environment location: {prefix}")
builder.append("")
print("\n".join(builder))

Expand Down Expand Up @@ -1385,9 +1384,9 @@ def channel_filt(s):
# string with new-style string formatting.
fmt[pkg] = f"{{pkg:<{maxpkg}}} {{vers:<{maxver}}}"
if maxchannels:
fmt[pkg] += " {channel:<%s}" % maxchannels
fmt[pkg] += f" {{channel:<{maxchannels}}}"
if features[pkg]:
fmt[pkg] += " [{features:<%s}]" % maxfeatures
fmt[pkg] += f" [{{features:<{maxfeatures}}}]"

lead = " " * 4

Expand Down
6 changes: 3 additions & 3 deletions conda_build/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,19 @@ class BuildLockError(CondaBuildException):
class OverLinkingError(RuntimeError):
def __init__(self, error, *args):
self.error = error
self.msg = "overlinking check failed \n%s" % (error)
self.msg = f"overlinking check failed \n{error}"
super().__init__(self.msg)


class OverDependingError(RuntimeError):
def __init__(self, error, *args):
self.error = error
self.msg = "overdepending check failed \n%s" % (error)
self.msg = f"overdepending check failed \n{error}"
super().__init__(self.msg)


class RunPathError(RuntimeError):
def __init__(self, error, *args):
self.error = error
self.msg = "runpaths check failed \n%s" % (error)
self.msg = f"runpaths check failed \n{error}"
super().__init__(self.msg)
4 changes: 2 additions & 2 deletions conda_build/inspect_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def print_linkages(
else sort_order.get(key[0], (4, key[0]))
),
):
output_string += "%s:\n" % prec
output_string += f"{prec}:\n"
if show_files:
for lib, path, binary in sorted(links):
output_string += f" {lib} ({path}) from {binary}\n"
Expand Down Expand Up @@ -296,7 +296,7 @@ def inspect_linkages(
output_string += print_linkages(inverted_map[dep], show_files=show_files)

else:
raise ValueError("Unrecognized groupby: %s" % groupby)
raise ValueError(f"Unrecognized groupby: {groupby}")
if hasattr(output_string, "decode"):
output_string = output_string.decode("utf-8")
return output_string
Expand Down
2 changes: 1 addition & 1 deletion conda_build/license_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
gpl3_regex = re.compile("GPL[^2]*3") # match GPL3
gpl23_regex = re.compile("GPL[^2]*>= *2") # match GPL >= 2
cc_regex = re.compile(r"CC\w+") # match CC
punk_regex = re.compile("[%s]" % re.escape(string.punctuation)) # removes punks
punk_regex = re.compile(f"[{re.escape(string.punctuation)}]") # removes punks


def match_gpl3(family):
Expand Down
Loading

0 comments on commit 2fb469a

Please sign in to comment.