Skip to content

Commit

Permalink
Integrate .pre-commit-config.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Repiteo committed Jun 24, 2024
1 parent c414c2b commit e0d363a
Show file tree
Hide file tree
Showing 45 changed files with 426 additions and 1,015 deletions.
63 changes: 21 additions & 42 deletions .github/workflows/static_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,27 @@ concurrency:

jobs:
static-checks:
name: Format (clang-format, black format, file format)
runs-on: ubuntu-20.04
name: Format (clang-format, ruff format, file format)
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

# Azure repositories are not reliable, we need to prevent Azure giving us packages.
- name: Make apt sources.list use the default Ubuntu repositories
run: |
sudo rm -f /etc/apt/sources.list.d/*
sudo cp -f misc/ci/sources.list /etc/apt/sources.list
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main"
sudo apt-get update
- name: Install dependencies
run: |
sudo apt-get install -qq dos2unix recode clang-format-15 libxml2-utils python3-pip moreutils
sudo update-alternatives --remove-all clang-format || true
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-15 100
sudo pip3 install black==22.3.0 pygments pytest==7.1.2 mypy==0.971
- name: File formatting checks (file_format.sh)
run: |
bash ./misc/scripts/file_format.sh
- name: Header guards formatting checks (header_guards.sh)
run: |
bash ./misc/scripts/header_guards.sh
- name: Python style checks via black (black_format.sh)
run: |
bash ./misc/scripts/black_format.sh
- name: Python scripts static analysis (mypy_check.sh)
run: |
bash ./misc/scripts/mypy_check.sh
- name: Bindings generation checks (ensures get_file_list returns all generated files)
run: |
python ./misc/scripts/check_get_file_list.py
- name: Style checks via clang-format (clang_format.sh)
run: |
bash ./misc/scripts/clang_format.sh
with:
fetch-depth: 2

- name: Get changed files
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
files=$(git diff-tree --no-commit-id --name-only -r HEAD^1..HEAD 2> /dev/null || true)
elif [ "${{ github.event_name }}" == "push" -a "${{ github.event.forced }}" == "false" -a "${{ github.event.created }}" == "false" ]; then
files=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.before }}..${{ github.event.after }} 2> /dev/null || true)
fi
files=$(echo "$files" | grep -v 'thirdparty' | xargs -I {} sh -c 'echo "\"./{}\""' | tr '\n' ' ')
echo "CHANGED_FILES=$files" >> $GITHUB_ENV
- name: Style checks via pre-commit
uses: pre-commit/action@v3.0.1
with:
extra_args: --verbose --hook-stage manual --files ${{ env.CHANGED_FILES }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
include/gen
src/gen

# Build configuarion.
# Build configuration.
/custom.py

# Misc
Expand Down
64 changes: 64 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
default_language_version:
python: python3

exclude: |
(?x)^(
gdextension/extension_api\.json|
gdextension/gdextension_interface\.h
)$
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.6
hooks:
- id: clang-format

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
hooks:
- id: mypy
files: \.py$
types_or: [text]

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies: [tomli]

- repo: local
hooks:
- id: copyright-headers
name: copyright-headers
language: python
entry: python misc/scripts/copyright_headers.py
files: \.(c|h)pp$
exclude: ^test/

- id: header-guards
name: header-guards
language: python
entry: python misc/scripts/header_guards.py
files: \.hpp$
exclude: ^test/

- id: file-format
name: file-format
language: python
entry: python misc/scripts/file_format.py
types_or: [text]

- id: check-get-file-list
name: check-get-file-list
language: python
entry: python misc/scripts/check_get_file_list.py
pass_filenames: false
always_run: true
stages: [manual]
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# godot-cpp cmake arguments
# GODOT_GDEXTENSION_DIR: Path to the directory containing GDExtension interface header and API JSON file
# GODOT_CPP_SYSTEM_HEADERS Mark the header files as SYSTEM. This may be useful to supress warnings in projects including this one.
# GODOT_CPP_SYSTEM_HEADERS Mark the header files as SYSTEM. This may be useful to suppress warnings in projects including this one.
# GODOT_CPP_WARNING_AS_ERROR Treat any warnings as errors
# GODOT_CUSTOM_API_FILE: Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)
# FLOAT_PRECISION: Floating-point precision level ("single", "double")
Expand Down
9 changes: 2 additions & 7 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#!/usr/bin/env python

import os
import platform
import sys
import subprocess
from binding_generator import scons_generate_bindings, scons_emit_files


EnsureSConsVersion(4, 0)


try:
Import("env")
except:
except Exception:
# Default tools with no platform defaults to gnu toolchain.
# We apply platform specific toolchains via our custom tools.
env = Environment(tools=["default"], PLATFORM="")
Expand All @@ -23,7 +18,7 @@ env.PrependENVPath("PATH", os.getenv("PATH"))
customs = ["custom.py"]
try:
customs += Import("customs")
except:
except Exception:
pass
profile = ARGUMENTS.get("profile", "")
if profile:
Expand Down
13 changes: 6 additions & 7 deletions binding_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def generate_builtin_class_vararg_method_implements_header(builtin_classes):
result.append(f"#define {header_guard}")
result.append("")
for builtin_api in builtin_classes:
if not "methods" in builtin_api:
if "methods" not in builtin_api:
continue
class_name = builtin_api["name"]
for method in builtin_api["methods"]:
Expand Down Expand Up @@ -1513,7 +1513,7 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
for field in expanded_format.split(";"):
field_type = field.strip().split(" ")[0].split("::")[0]
if field_type != "" and not is_included_type(field_type) and not is_pod_type(field_type):
if not field_type in used_classes:
if field_type not in used_classes:
used_classes.append(field_type)

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

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

header.append("")

Expand Down Expand Up @@ -2583,7 +2583,7 @@ def is_packed_array(type_name):

def needs_copy_instead_of_move(type_name):
"""
Those are types which need initialised data or we'll get warning spam so need a copy instead of move.
Those are types which need initialized data or we'll get warning spam so need a copy instead of move.
"""
return type_name in [
"Dictionary",
Expand Down Expand Up @@ -2691,7 +2691,7 @@ def correct_default_value(value, type_name):
if value == "":
return f"{type_name}()"
if value.startswith("Array["):
return f"{{}}"
return "{}"
if value.startswith("&"):
return value[1::]
if value.startswith("^"):
Expand All @@ -2707,7 +2707,7 @@ def correct_typed_array(type_name):

def correct_type(type_name, meta=None, use_alias=True):
type_conversion = {"float": "double", "int": "int64_t", "Nil": "Variant"}
if meta != None:
if meta is not None:
if "int" in meta:
return f"{meta}_t"
elif meta in type_conversion:
Expand Down Expand Up @@ -2818,7 +2818,6 @@ def get_operator_id_name(op):
"or": "or",
"xor": "xor",
"not": "not",
"and": "and",
"in": "in",
}
return op_id_map[op]
Expand Down
5 changes: 5 additions & 0 deletions include/godot_cpp/variant/array_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef GODOT_ARRAY_HELPERS_HPP
#define GODOT_ARRAY_HELPERS_HPP

namespace godot {
namespace helpers {
template <typename T, typename ValueT>
Expand All @@ -48,3 +51,5 @@ T append_all(T appendable) {
}
} // namespace helpers
} // namespace godot

#endif // GODOT_ARRAY_HELPERS_HPP
5 changes: 5 additions & 0 deletions include/godot_cpp/variant/color_names.inc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef GODOT_COLOR_NAMES_INC_HPP
#define GODOT_COLOR_NAMES_INC_HPP

namespace godot {

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

} // namespace godot

#endif // GODOT_COLOR_NAMES_INC_HPP
2 changes: 1 addition & 1 deletion include/godot_cpp/variant/rect2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ struct _NO_DISCARD_ Rect2 {
return size.x > 0.0f && size.y > 0.0f;
}

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

Expand Down
2 changes: 1 addition & 1 deletion include/godot_cpp/variant/rect2i.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct _NO_DISCARD_ Rect2i {
return size.x > 0 && size.y > 0;
}

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

Expand Down
37 changes: 0 additions & 37 deletions misc/hooks/README.md

This file was deleted.

48 changes: 0 additions & 48 deletions misc/hooks/canonicalize_filename.sh

This file was deleted.

Loading

0 comments on commit e0d363a

Please sign in to comment.