Skip to content

Commit d9f8ef6

Browse files
ChubercikRepiteo
authored andcommitted
Update pre-commit hooks configuration to use ruff instead of black
1 parent aaa4560 commit d9f8ef6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+240
-237
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ repos:
1717
platform/android/java/lib/src/com/.*
1818
)
1919
20-
- repo: https://github.com/psf/black-pre-commit-mirror
21-
rev: 24.2.0
20+
- repo: https://github.com/astral-sh/ruff-pre-commit
21+
rev: v0.4.4
2222
hooks:
23-
- id: black
24-
files: (\.py$|SConstruct|SCsub)
25-
types_or: [text]
23+
- id: ruff
24+
args: [--fix]
25+
- id: ruff-format
2626

2727
- repo: https://github.com/pre-commit/mirrors-mypy
2828
rev: v0.971

SConstruct

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import os
1010
import pickle
1111
import sys
1212
import time
13-
from types import ModuleType
1413
from collections import OrderedDict
15-
from importlib.util import spec_from_file_location, module_from_spec
16-
from SCons import __version__ as scons_raw_version
14+
from importlib.util import module_from_spec, spec_from_file_location
15+
from types import ModuleType
1716

17+
from SCons import __version__ as scons_raw_version
1818

1919
# Explicitly resolve the helper modules, this is done to avoid clash with
2020
# modules of the same name that might be randomly added (e.g. someone adding
@@ -53,12 +53,12 @@ _helper_module("core.core_builders", "core/core_builders.py")
5353
_helper_module("main.main_builders", "main/main_builders.py")
5454

5555
# Local
56-
import methods
57-
import glsl_builders
5856
import gles3_builders
57+
import glsl_builders
58+
import methods
5959
import scu_builders
60-
from methods import print_warning, print_error
61-
from platform_methods import architectures, architecture_aliases
60+
from methods import print_error, print_warning
61+
from platform_methods import architecture_aliases, architectures
6262

6363
if ARGUMENTS.get("target", "editor") == "editor":
6464
_helper_module("editor.editor_builders", "editor/editor_builders.py")
@@ -68,7 +68,7 @@ if ARGUMENTS.get("target", "editor") == "editor":
6868
# <https://github.com/python/cpython/issues/73245>
6969
if sys.stdout.isatty() and sys.platform == "win32":
7070
try:
71-
from ctypes import windll, byref, WinError # type: ignore
71+
from ctypes import WinError, byref, windll # type: ignore
7272
from ctypes.wintypes import DWORD # type: ignore
7373

7474
stdout_handle = windll.kernel32.GetStdHandle(DWORD(-11))
@@ -562,15 +562,15 @@ if env["build_profile"] != "":
562562
dbo = ft["disabled_build_options"]
563563
for c in dbo:
564564
env[c] = dbo[c]
565-
except:
565+
except json.JSONDecodeError:
566566
print_error('Failed to open feature build profile: "{}"'.format(env["build_profile"]))
567567
Exit(255)
568568

569569
# Platform specific flags.
570570
# These can sometimes override default options.
571571
flag_list = platform_flags[env["platform"]]
572572
for f in flag_list:
573-
if not (f[0] in ARGUMENTS) or ARGUMENTS[f[0]] == "auto": # Allow command line to override platform flags
573+
if f[0] not in ARGUMENTS or ARGUMENTS[f[0]] == "auto": # Allow command line to override platform flags
574574
env[f[0]] = f[1]
575575

576576
# 'dev_mode' and 'production' are aliases to set default options if they haven't been
@@ -591,7 +591,7 @@ if env["production"]:
591591
# Run SCU file generation script if in a SCU build.
592592
if env["scu_build"]:
593593
max_includes_per_scu = 8
594-
if env.dev_build == True:
594+
if env.dev_build:
595595
max_includes_per_scu = 1024
596596

597597
read_scu_limit = int(env["scu_limit"])
@@ -984,7 +984,7 @@ GLSL_BUILDERS = {
984984
env.Append(BUILDERS=GLSL_BUILDERS)
985985

986986
scons_cache_path = os.environ.get("SCONS_CACHE")
987-
if scons_cache_path != None:
987+
if scons_cache_path is not None:
988988
CacheDir(scons_cache_path)
989989
print("Scons cache enabled... (path: '" + scons_cache_path + "')")
990990

core/SCsub

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
Import("env")
44

5+
import os
6+
57
import core_builders
8+
69
import methods
7-
import os
810

911
env.core_sources = []
1012

@@ -188,9 +190,7 @@ def version_info_builder(target, source, env):
188190
#define VERSION_WEBSITE "{website}"
189191
#define VERSION_DOCS_BRANCH "{docs_branch}"
190192
#define VERSION_DOCS_URL "https://docs.godotengine.org/en/" VERSION_DOCS_BRANCH
191-
""".format(
192-
**env.version_info
193-
)
193+
""".format(**env.version_info)
194194
)
195195

196196

@@ -206,9 +206,7 @@ def version_hash_builder(target, source, env):
206206
207207
const char *const VERSION_HASH = "{git_hash}";
208208
const uint64_t VERSION_TIMESTAMP = {git_timestamp};
209-
""".format(
210-
**env.version_info
211-
)
209+
""".format(**env.version_info)
212210
)
213211

214212

core/core_builders.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def next_line(self):
180180
return line
181181

182182
def next_tag(self):
183-
if not ":" in self.current:
183+
if ":" not in self.current:
184184
return ("", [])
185185
tag, line = self.current.split(":", 1)
186186
lines = [line.strip()]
@@ -206,7 +206,7 @@ def next_tag(self):
206206

207207
if not tag or not reader.current:
208208
# end of a paragraph start a new part
209-
if "License" in part and not "Files" in part:
209+
if "License" in part and "Files" not in part:
210210
# no Files tag in this one, so assume standalone license
211211
license_list.append(part["License"])
212212
part = {}
@@ -298,13 +298,13 @@ def next_tag(self):
298298
f.write("const int LICENSE_COUNT = " + str(len(license_list)) + ";\n")
299299

300300
f.write("const char *const LICENSE_NAMES[] = {\n")
301-
for l in license_list:
302-
f.write('\t"' + escape_string(l[0]) + '",\n')
301+
for license in license_list:
302+
f.write('\t"' + escape_string(license[0]) + '",\n')
303303
f.write("};\n\n")
304304

305305
f.write("const char *const LICENSE_BODIES[] = {\n\n")
306-
for l in license_list:
307-
for line in l[1:]:
306+
for license in license_list:
307+
for line in license[1:]:
308308
if line == ".":
309309
f.write('\t"\\n"\n')
310310
else:

core/extension/SCsub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
Import("env")
44

5-
import make_wrappers
65
import make_interface_dumper
6+
import make_wrappers
77

88
env.CommandNoCache(["ext_wrappers.gen.inc"], "make_wrappers.py", env.Run(make_wrappers.run))
99
env.CommandNoCache(

core/extension/make_wrappers.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
def generate_mod_version(argcount, const=False, returns=False):
1111
s = proto_mod
1212
sproto = str(argcount)
13-
method_info = ""
1413
if returns:
1514
sproto += "R"
1615
s = s.replace("$RETTYPE", "m_ret, ")
@@ -68,7 +67,6 @@ def generate_mod_version(argcount, const=False, returns=False):
6867
def generate_ex_version(argcount, const=False, returns=False):
6968
s = proto_ex
7069
sproto = str(argcount)
71-
method_info = ""
7270
if returns:
7371
sproto += "R"
7472
s = s.replace("$RETTYPE", "m_ret, ")

core/input/SCsub

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Import("env")
44

55
import input_builders
66

7-
87
# Order matters here. Higher index controller database files write on top of lower index database files.
98
controller_databases = [
109
"gamecontrollerdb.txt",

doc/tools/doc_status.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env python3
22

33
import fnmatch
4-
import os
5-
import sys
6-
import re
74
import math
5+
import os
86
import platform
7+
import re
8+
import sys
99
import xml.etree.ElementTree as ET
1010
from typing import Dict, List, Set
1111

@@ -286,7 +286,7 @@ def generate_for_class(c: ET.Element):
286286
status.progresses[tag.tag].increment(is_deprecated or is_experimental or has_descr)
287287
elif tag.tag in ["constants", "members", "theme_items"]:
288288
for sub_tag in list(tag):
289-
if not sub_tag.text is None:
289+
if sub_tag.text is not None:
290290
is_deprecated = "deprecated" in sub_tag.attrib
291291
is_experimental = "experimental" in sub_tag.attrib
292292
has_descr = len(sub_tag.text.strip()) > 0

doc/tools/make_rst.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44

55
import argparse
66
import os
7-
import platform
87
import re
98
import sys
109
import xml.etree.ElementTree as ET
1110
from collections import OrderedDict
12-
from typing import List, Dict, TextIO, Tuple, Optional, Any, Union
11+
from typing import Any, Dict, List, Optional, TextIO, Tuple, Union
1312

1413
# Import hardcoded version information from version.py
1514
root_directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../")
1615
sys.path.append(root_directory) # Include the root directory
17-
import version
16+
import version # noqa: E402
1817

1918
# $DOCS_URL/path/to/page.html(#fragment-tag)
2019
GODOT_DOCS_PATTERN = re.compile(r"^\$DOCS_URL/(.*)\.html(#.*)?$")
@@ -706,7 +705,7 @@ def main() -> None:
706705
# <https://github.com/python/cpython/issues/73245>
707706
if should_color and sys.stdout.isatty() and sys.platform == "win32":
708707
try:
709-
from ctypes import windll, byref, WinError # type: ignore
708+
from ctypes import WinError, byref, windll # type: ignore
710709
from ctypes.wintypes import DWORD # type: ignore
711710

712711
stdout_handle = windll.kernel32.GetStdHandle(DWORD(-11))
@@ -1413,7 +1412,7 @@ def make_rst_class(class_def: ClassDef, state: State, dry_run: bool, output_dir:
14131412
operator_anchor = f".. _class_{class_name}_operator_{sanitize_operator_name(m.name, state)}"
14141413
for parameter in m.parameters:
14151414
operator_anchor += f"_{parameter.type_name.type_name}"
1416-
operator_anchor += f":\n\n"
1415+
operator_anchor += ":\n\n"
14171416
f.write(operator_anchor)
14181417

14191418
f.write(".. rst-class:: classref-operator\n\n")
@@ -1553,7 +1552,7 @@ def make_method_signature(
15531552
out += f":ref:`{op_name}<class_{class_def.name}_{ref_type}_{sanitize_operator_name(definition.name, state)}"
15541553
for parameter in definition.parameters:
15551554
out += f"_{parameter.type_name.type_name}"
1556-
out += f">`"
1555+
out += ">`"
15571556
elif ref_type == "method":
15581557
ref_type_qualifier = ""
15591558
if definition.name.startswith("_"):

editor/SCsub

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ Import("env")
44

55
env.editor_sources = []
66

7-
import os
87
import glob
8+
import os
9+
910
import editor_builders
10-
import methods
1111

12+
import methods
1213

1314
if env.editor_build:
1415
# Generate doc data paths

0 commit comments

Comments
 (0)