Skip to content

Commit

Permalink
Merge pull request #266 from DimitriPapadopoulos/TRY
Browse files Browse the repository at this point in the history
 Enforce ruff/tryceratops rules (TRY)
  • Loading branch information
jaraco authored Aug 26, 2024
2 parents 6c224d3 + d0e3de1 commit d42a6aa
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions distutils/command/install_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def finalize_options(self):
if not isinstance(self.optimize, int):
try:
self.optimize = int(self.optimize)
if self.optimize not in (0, 1, 2):
raise AssertionError
except (ValueError, AssertionError):
except ValueError:
pass
if self.optimize not in (0, 1, 2):
raise DistutilsOptionError("optimize must be 0, 1, or 2")

def run(self):
Expand Down
5 changes: 3 additions & 2 deletions distutils/cygwinccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ def check_config_h():
fn = sysconfig.get_config_h_filename()
try:
config_h = pathlib.Path(fn).read_text(encoding='utf-8')
except OSError as exc:
return (CONFIG_H_UNCERTAIN, f"couldn't read '{fn}': {exc.strerror}")
else:
substring = '__GNUC__'
if substring in config_h:
code = CONFIG_H_OK
Expand All @@ -316,8 +319,6 @@ def check_config_h():
code = CONFIG_H_NOTOK
mention_inflected = 'does not mention'
return code, f"{fn!r} {mention_inflected} {substring!r}"
except OSError as exc:
return (CONFIG_H_UNCERTAIN, f"couldn't read '{fn}': {exc.strerror}")


def is_cygwincc(cc):
Expand Down
2 changes: 1 addition & 1 deletion distutils/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(
**kw, # To catch unknown keywords
):
if not isinstance(name, str):
raise AssertionError("'name' must be a string")
raise AssertionError("'name' must be a string") # noqa: TRY004
if not (
isinstance(sources, list)
and all(isinstance(v, (str, os.PathLike)) for v in sources)
Expand Down
3 changes: 2 additions & 1 deletion distutils/file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,13 @@ def copy_file( # noqa: C901
if not (os.path.exists(dst) and os.path.samefile(src, dst)):
try:
os.link(src, dst)
return (dst, 1)
except OSError:
# If hard linking fails, fall back on copying file
# (some special filesystems don't support hard linking
# even under Unix, see issue #8876).
pass
else:
return (dst, 1)
elif link == 'sym':
if not (os.path.exists(dst) and os.path.samefile(src, dst)):
os.symlink(src, dst)
Expand Down
2 changes: 1 addition & 1 deletion distutils/msvc9compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def load_macros(self, version):
if version >= 8.0:
self.set_macro("FrameworkSDKDir", NET_BASE, "sdkinstallrootv2.0")
else:
raise KeyError("sdkinstallrootv2.0")
raise KeyError("sdkinstallrootv2.0") # noqa: TRY301
except KeyError:
raise DistutilsPlatformError(
"""Python was built with Visual Studio 2008;
Expand Down
4 changes: 3 additions & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ extend-select = [
"PERF",
"RUF010",
"RUF100",
"TRY",
"UP",
]
ignore = [
# local
"PERF203",
"TRY003",

# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
"E114",
Expand Down

0 comments on commit d42a6aa

Please sign in to comment.