Skip to content

Commit e0d363a

Browse files
committed
Integrate .pre-commit-config.yaml
1 parent c414c2b commit e0d363a

Some content is hidden

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

45 files changed

+426
-1015
lines changed

.github/workflows/static_checks.yml

+21-42
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,27 @@ concurrency:
77

88
jobs:
99
static-checks:
10-
name: Format (clang-format, black format, file format)
11-
runs-on: ubuntu-20.04
10+
name: Format (clang-format, ruff format, file format)
11+
runs-on: ubuntu-22.04
1212
steps:
1313
- name: Checkout
1414
uses: actions/checkout@v4
15-
16-
# Azure repositories are not reliable, we need to prevent Azure giving us packages.
17-
- name: Make apt sources.list use the default Ubuntu repositories
18-
run: |
19-
sudo rm -f /etc/apt/sources.list.d/*
20-
sudo cp -f misc/ci/sources.list /etc/apt/sources.list
21-
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
22-
sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main"
23-
sudo apt-get update
24-
25-
- name: Install dependencies
26-
run: |
27-
sudo apt-get install -qq dos2unix recode clang-format-15 libxml2-utils python3-pip moreutils
28-
sudo update-alternatives --remove-all clang-format || true
29-
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 100
30-
sudo pip3 install black==22.3.0 pygments pytest==7.1.2 mypy==0.971
31-
32-
- name: File formatting checks (file_format.sh)
33-
run: |
34-
bash ./misc/scripts/file_format.sh
35-
36-
- name: Header guards formatting checks (header_guards.sh)
37-
run: |
38-
bash ./misc/scripts/header_guards.sh
39-
40-
- name: Python style checks via black (black_format.sh)
41-
run: |
42-
bash ./misc/scripts/black_format.sh
43-
44-
- name: Python scripts static analysis (mypy_check.sh)
45-
run: |
46-
bash ./misc/scripts/mypy_check.sh
47-
48-
- name: Bindings generation checks (ensures get_file_list returns all generated files)
49-
run: |
50-
python ./misc/scripts/check_get_file_list.py
51-
52-
- name: Style checks via clang-format (clang_format.sh)
53-
run: |
54-
bash ./misc/scripts/clang_format.sh
15+
with:
16+
fetch-depth: 2
17+
18+
- name: Get changed files
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
run: |
22+
if [ "${{ github.event_name }}" == "pull_request" ]; then
23+
files=$(git diff-tree --no-commit-id --name-only -r HEAD^1..HEAD 2> /dev/null || true)
24+
elif [ "${{ github.event_name }}" == "push" -a "${{ github.event.forced }}" == "false" -a "${{ github.event.created }}" == "false" ]; then
25+
files=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.before }}..${{ github.event.after }} 2> /dev/null || true)
26+
fi
27+
files=$(echo "$files" | grep -v 'thirdparty' | xargs -I {} sh -c 'echo "\"./{}\""' | tr '\n' ' ')
28+
echo "CHANGED_FILES=$files" >> $GITHUB_ENV
29+
30+
- name: Style checks via pre-commit
31+
uses: pre-commit/action@v3.0.1
32+
with:
33+
extra_args: --verbose --hook-stage manual --files ${{ env.CHANGED_FILES }}

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
include/gen
99
src/gen
1010

11-
# Build configuarion.
11+
# Build configuration.
1212
/custom.py
1313

1414
# Misc

.pre-commit-config.yaml

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
default_language_version:
2+
python: python3
3+
4+
exclude: |
5+
(?x)^(
6+
gdextension/extension_api\.json|
7+
gdextension/gdextension_interface\.h
8+
)$
9+
10+
repos:
11+
- repo: https://github.com/pre-commit/mirrors-clang-format
12+
rev: v17.0.6
13+
hooks:
14+
- id: clang-format
15+
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
rev: v0.4.4
18+
hooks:
19+
- id: ruff
20+
args: [--fix]
21+
- id: ruff-format
22+
23+
- repo: https://github.com/pre-commit/mirrors-mypy
24+
rev: v0.971
25+
hooks:
26+
- id: mypy
27+
files: \.py$
28+
types_or: [text]
29+
30+
- repo: https://github.com/codespell-project/codespell
31+
rev: v2.3.0
32+
hooks:
33+
- id: codespell
34+
additional_dependencies: [tomli]
35+
36+
- repo: local
37+
hooks:
38+
- id: copyright-headers
39+
name: copyright-headers
40+
language: python
41+
entry: python misc/scripts/copyright_headers.py
42+
files: \.(c|h)pp$
43+
exclude: ^test/
44+
45+
- id: header-guards
46+
name: header-guards
47+
language: python
48+
entry: python misc/scripts/header_guards.py
49+
files: \.hpp$
50+
exclude: ^test/
51+
52+
- id: file-format
53+
name: file-format
54+
language: python
55+
entry: python misc/scripts/file_format.py
56+
types_or: [text]
57+
58+
- id: check-get-file-list
59+
name: check-get-file-list
60+
language: python
61+
entry: python misc/scripts/check_get_file_list.py
62+
pass_filenames: false
63+
always_run: true
64+
stages: [manual]

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# godot-cpp cmake arguments
55
# GODOT_GDEXTENSION_DIR: Path to the directory containing GDExtension interface header and API JSON file
6-
# GODOT_CPP_SYSTEM_HEADERS Mark the header files as SYSTEM. This may be useful to supress warnings in projects including this one.
6+
# GODOT_CPP_SYSTEM_HEADERS Mark the header files as SYSTEM. This may be useful to suppress warnings in projects including this one.
77
# GODOT_CPP_WARNING_AS_ERROR Treat any warnings as errors
88
# GODOT_CUSTOM_API_FILE: Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)
99
# FLOAT_PRECISION: Floating-point precision level ("single", "double")

SConstruct

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
#!/usr/bin/env python
22

33
import os
4-
import platform
5-
import sys
6-
import subprocess
7-
from binding_generator import scons_generate_bindings, scons_emit_files
8-
94

105
EnsureSConsVersion(4, 0)
116

127

138
try:
149
Import("env")
15-
except:
10+
except Exception:
1611
# Default tools with no platform defaults to gnu toolchain.
1712
# We apply platform specific toolchains via our custom tools.
1813
env = Environment(tools=["default"], PLATFORM="")
@@ -23,7 +18,7 @@ env.PrependENVPath("PATH", os.getenv("PATH"))
2318
customs = ["custom.py"]
2419
try:
2520
customs += Import("customs")
26-
except:
21+
except Exception:
2722
pass
2823
profile = ARGUMENTS.get("profile", "")
2924
if profile:

binding_generator.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def generate_builtin_class_vararg_method_implements_header(builtin_classes):
591591
result.append(f"#define {header_guard}")
592592
result.append("")
593593
for builtin_api in builtin_classes:
594-
if not "methods" in builtin_api:
594+
if "methods" not in builtin_api:
595595
continue
596596
class_name = builtin_api["name"]
597597
for method in builtin_api["methods"]:
@@ -1513,7 +1513,7 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
15131513
for field in expanded_format.split(";"):
15141514
field_type = field.strip().split(" ")[0].split("::")[0]
15151515
if field_type != "" and not is_included_type(field_type) and not is_pod_type(field_type):
1516-
if not field_type in used_classes:
1516+
if field_type not in used_classes:
15171517
used_classes.append(field_type)
15181518

15191519
result.append("")
@@ -2127,7 +2127,7 @@ def generate_global_constant_binds(api, output_dir):
21272127
header.append(f'VARIANT_ENUM_CAST({enum_def["name"]});')
21282128

21292129
# Variant::Type is not a global enum, but only one line, it is worth to place in this file instead of creating new file.
2130-
header.append(f"VARIANT_ENUM_CAST(godot::Variant::Type);")
2130+
header.append("VARIANT_ENUM_CAST(godot::Variant::Type);")
21312131

21322132
header.append("")
21332133

@@ -2583,7 +2583,7 @@ def is_packed_array(type_name):
25832583

25842584
def needs_copy_instead_of_move(type_name):
25852585
"""
2586-
Those are types which need initialised data or we'll get warning spam so need a copy instead of move.
2586+
Those are types which need initialized data or we'll get warning spam so need a copy instead of move.
25872587
"""
25882588
return type_name in [
25892589
"Dictionary",
@@ -2691,7 +2691,7 @@ def correct_default_value(value, type_name):
26912691
if value == "":
26922692
return f"{type_name}()"
26932693
if value.startswith("Array["):
2694-
return f"{{}}"
2694+
return "{}"
26952695
if value.startswith("&"):
26962696
return value[1::]
26972697
if value.startswith("^"):
@@ -2707,7 +2707,7 @@ def correct_typed_array(type_name):
27072707

27082708
def correct_type(type_name, meta=None, use_alias=True):
27092709
type_conversion = {"float": "double", "int": "int64_t", "Nil": "Variant"}
2710-
if meta != None:
2710+
if meta is not None:
27112711
if "int" in meta:
27122712
return f"{meta}_t"
27132713
elif meta in type_conversion:
@@ -2818,7 +2818,6 @@ def get_operator_id_name(op):
28182818
"or": "or",
28192819
"xor": "xor",
28202820
"not": "not",
2821-
"and": "and",
28222821
"in": "in",
28232822
}
28242823
return op_id_map[op]

include/godot_cpp/variant/array_helpers.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31+
#ifndef GODOT_ARRAY_HELPERS_HPP
32+
#define GODOT_ARRAY_HELPERS_HPP
33+
3134
namespace godot {
3235
namespace helpers {
3336
template <typename T, typename ValueT>
@@ -48,3 +51,5 @@ T append_all(T appendable) {
4851
}
4952
} // namespace helpers
5053
} // namespace godot
54+
55+
#endif // GODOT_ARRAY_HELPERS_HPP

include/godot_cpp/variant/color_names.inc.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31+
#ifndef GODOT_COLOR_NAMES_INC_HPP
32+
#define GODOT_COLOR_NAMES_INC_HPP
33+
3134
namespace godot {
3235

3336
// Names from https://en.wikipedia.org/wiki/X11_color_names
@@ -189,3 +192,5 @@ static NamedColor named_colors[] = {
189192
};
190193

191194
} // namespace godot
195+
196+
#endif // GODOT_COLOR_NAMES_INC_HPP

include/godot_cpp/variant/rect2.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ struct _NO_DISCARD_ Rect2 {
146146
return size.x > 0.0f && size.y > 0.0f;
147147
}
148148

149-
// Returns the instersection between two Rect2s or an empty Rect2 if there is no intersection
149+
// Returns the intersection between two Rect2s or an empty Rect2 if there is no intersection
150150
inline Rect2 intersection(const Rect2 &p_rect) const {
151151
Rect2 new_rect = p_rect;
152152

include/godot_cpp/variant/rect2i.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct _NO_DISCARD_ Rect2i {
8989
return size.x > 0 && size.y > 0;
9090
}
9191

92-
// Returns the instersection between two Rect2is or an empty Rect2i if there is no intersection
92+
// Returns the intersection between two Rect2is or an empty Rect2i if there is no intersection
9393
inline Rect2i intersection(const Rect2i &p_rect) const {
9494
Rect2i new_rect = p_rect;
9595

misc/hooks/README.md

-37
This file was deleted.

misc/hooks/canonicalize_filename.sh

-48
This file was deleted.

0 commit comments

Comments
 (0)