Skip to content

Commit

Permalink
build: replace Python linter flake8 with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Apr 13, 2023
1 parent 16afc86 commit 5e12816
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 14 deletions.
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@ ignore = [
"E7",
"PLC1901",
"RUF005",
"RUF100",
]
line-length = 172
target-version = "py37"

[tool.ruff.mccabe]
max-complexity = 100

[tool.ruff.per-file-ignores]
"tools/checkimports.py" = ["W605"]
"tools/gyp/pylib/gyp/xcodeproj_file.py" = ["PLE0101"]
"tools/icu/shrink-icu-src.py" = ["W605"]
"tools/mkssldef.py" = ["W605"]

[tool.ruff.pylint]
max-args = 12
max-branches = 110
Expand Down
2 changes: 1 addition & 1 deletion tools/checkimports.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import itertools

def do_exist(file_name, lines, imported):
if not any(not re.match('using \\w+::{0};'.format(imported), line) and
if not any(not re.match('using \w+::{0};'.format(imported), line) and
re.search('\\b{0}\\b'.format(imported), line) for line in lines):
print('File "{0}" does not use "{1}"'.format(file_name, imported))
return False
Expand Down
2 changes: 1 addition & 1 deletion tools/gyp/gyp_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def UnixifyPath(path):
# else the 'gyp' library will not be found
path = UnixifyPath(sys.argv[0])
sys.path.insert(0, os.path.join(os.path.dirname(path), "pylib"))
import gyp
import gyp # noqa: E402

if __name__ == "__main__":
sys.exit(gyp.script_main())
12 changes: 6 additions & 6 deletions tools/gyp/pylib/gyp/generator/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def CalculateGeneratorInputInfo(params):
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
cmd_solink_module = $(LINK.$(TOOLSET)) -bundle $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
"""
""" # noqa: E501

LINK_COMMANDS_ANDROID = """\
quiet_cmd_alink = AR($(TOOLSET)) $@
Expand Down Expand Up @@ -286,7 +286,7 @@ def CalculateGeneratorInputInfo(params):
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
"""
""" # noqa: E501


LINK_COMMANDS_OS400 = """\
Expand All @@ -304,7 +304,7 @@ def CalculateGeneratorInputInfo(params):
quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ $(filter-out FORCE_DO_CMD, $^) $(LIBS)
"""
""" # noqa: E501


LINK_COMMANDS_OS390 = """\
Expand Down Expand Up @@ -474,7 +474,7 @@ def CalculateGeneratorInputInfo(params):
cmd_symlink = ln -sf "$<" "$@"
%(link_commands)s
"""
""" # noqa: E501
r"""
# Define an escape_quotes function to escape single quotes.
# This allows us to handle quotes properly as long as we always use
Expand Down Expand Up @@ -573,7 +573,7 @@ def CalculateGeneratorInputInfo(params):
.PHONY: FORCE_DO_CMD
FORCE_DO_CMD:
"""
""" # noqa: E501
)

SHARED_HEADER_MAC_COMMANDS = """
Expand Down Expand Up @@ -604,7 +604,7 @@ def CalculateGeneratorInputInfo(params):
quiet_cmd_infoplist = INFOPLIST $@
cmd_infoplist = $(CC.$(TOOLSET)) -E -P -Wno-trigraphs -x c $(INFOPLIST_DEFINES) "$<" -o "$@"
"""
""" # noqa: E501


def WriteRootHeaderSuffixRules(writer):
Expand Down
2 changes: 1 addition & 1 deletion tools/gyp/pylib/gyp/generator/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ def _EscapeEnvironmentVariableExpansion(s):
Returns:
The escaped string.
"""
""" # noqa: E731,E123,E501
s = s.replace("%", "%%")
return s

Expand Down
2 changes: 1 addition & 1 deletion tools/gyp/pylib/gyp/generator/ninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -2533,7 +2533,7 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name
description="SOLINK $lib",
restat=True,
command=mtime_preserving_solink_base
% {"suffix": "@$link_file_list"},
% {"suffix": "@$link_file_list"}, # noqa: E501
rspfile="$link_file_list",
rspfile_content=(
"-Wl,--whole-archive $in $solibs -Wl," "--no-whole-archive $libs"
Expand Down
2 changes: 1 addition & 1 deletion tools/gyp/pylib/gyp/xcode_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ def _GetXcodeEnv(
"CONFIGURATION": configuration,
"PRODUCT_NAME": xcode_settings.GetProductName(),
# For FULL_PRODUCT_NAME see:
# /Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Specifications/MacOSX\ Product\ Types.xcspec
# /Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Specifications/MacOSX\ Product\ Types.xcspec # noqa: E501
"SRCROOT": srcroot,
"SOURCE_ROOT": "${SRCROOT}",
# This is not true for static libraries, but currently the env is only
Expand Down
2 changes: 1 addition & 1 deletion tools/gyp/pylib/gyp/xcodeproj_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2770,7 +2770,7 @@ def __init__(self, properties=None, id=None, parent=None, path=None):
self.path = path
self._other_pbxprojects = {}
# super
XCContainerPortal.__init__(self, properties, id, parent)
return XCContainerPortal.__init__(self, properties, id, parent)

def Name(self):
name = self.path
Expand Down
2 changes: 1 addition & 1 deletion tools/icu/shrink-icu-src.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def print_size(fn):
size = (os.stat(fn).st_size) / 1024000
print('%dM\t%s' % (size, fn))

ignore_regex = re.compile('^.*\\.(vcxproj|filters|nrm|icu|dat|xml|txt|ac|guess|m4|in|sub|py|mak)$')
ignore_regex = re.compile('^.*\.(vcxproj|filters|nrm|icu|dat|xml|txt|ac|guess|m4|in|sub|py|mak)$')

def icu_ignore(dir, files):
subdir = dir[len(options.icusrc)+1::]
Expand Down
2 changes: 1 addition & 1 deletion tools/mkssldef.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

for filename in filenames:
for line in open(filename).readlines():
name, _, _, meta, _ = re.split('\\s+', line)
name, _, _, meta, _ = re.split('\s+', line)
if any(p.match(name) for p in excludes): continue
meta = meta.split(':')
assert meta[0] in ('EXIST', 'NOEXIST')
Expand Down

0 comments on commit 5e12816

Please sign in to comment.