Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: ️✅ Validate

on: [push, pull_request, merge_group]

jobs:
static-checks:
name: Code style and file formatting
runs-on: ubuntu-24.04
steps:
- name: Checkout project
uses: actions/checkout@v4.1.1

- name: Style checks via pre-commit
uses: pre-commit/action@v3.0.1
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
default_language_version:
python: python3

exclude: |
(?x)^(
tools/.*py|
build/cache.py|
build/common_compiler_flags.py
)

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

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

- repo: https://github.com/crate-ci/typos
rev: v1.29.4
hooks:
- id: typos
14 changes: 10 additions & 4 deletions build/git_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

base_folder = Path(__file__).resolve().parent


def get_git_tag():
git_tag = os.getenv("OPENVIC_TAG", "<tag missing>")
if os.path.exists(".git"):
Expand All @@ -14,24 +15,28 @@ def get_git_tag():
except (subprocess.CalledProcessError, OSError):
# `git` not found in PATH.
pass

return git_tag


def get_git_release():
git_release = os.getenv("OPENVIC_RELEASE", "<release missing>")
if os.path.exists(".git"):
try:
result = subprocess.check_output(["gh", "release", "list", "--json", "name", "-q", ".[0] | .name"], encoding="utf-8").strip()
result = subprocess.check_output(
["gh", "release", "list", "--json", "name", "-q", ".[0] | .name"], encoding="utf-8"
).strip()
if result != "":
git_release = result
except (subprocess.CalledProcessError, OSError):
# `gh` not found in PATH.
git_tag = get_git_tag()
if git_tag != "<tag missing>":
git_release = git_tag

return git_release


def get_git_hash():
# Parse Git hash if we're in a Git repo.
git_hash = "0000000000000000000000000000000000000000"
Expand Down Expand Up @@ -86,5 +91,6 @@ def get_git_hash():
"git_timestamp": git_timestamp,
}


def get_git_info():
return {**get_git_hash(), "git_tag": get_git_tag(), "git_release": get_git_release() }
return {**get_git_hash(), "git_tag": get_git_tag(), "git_release": get_git_release()}
11 changes: 6 additions & 5 deletions build/glob_recursive.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
def GlobRecursive(pattern, nodes=['.'], exclude=None):
import SCons
import glob
def GlobRecursive(pattern, nodes=["."], exclude=None):
import fnmatch

import SCons

fs = SCons.Node.FS.get_default_fs()
Glob = fs.Glob

Expand All @@ -11,11 +12,11 @@ def GlobRecursive(pattern, nodes=['.'], exclude=None):
results = []
for node in nodes:
nnodes = []
for f in Glob(str(node) + '/*', source=True):
for f in Glob(str(node) + "/*", source=True):
if type(f) is SCons.Node.FS.Dir:
nnodes.append(f)
results += GlobRecursive(pattern, nnodes)
results += Glob(str(node) + '/' + pattern, source=True)
results += Glob(str(node) + "/" + pattern, source=True)
if isinstance(exclude, list):
for val in results:
for pat in exclude:
Expand Down
11 changes: 6 additions & 5 deletions build/option_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Tuple, Iterable
import os

from SCons.Variables import Variables


class OptionsClass:
def __init__(self, args):
self.opts = None
Expand All @@ -9,15 +11,14 @@ def __init__(self, args):
self.saved_args = args.copy()

def Add(self, variableOrKey, *argv, **kwarg):

self.opt_list.append([variableOrKey, argv, kwarg])
# Neccessary to have our own build options without errors
# Necessary to have our own build options without errors
if isinstance(variableOrKey, str):
self.args.pop(variableOrKey, True)
else:
self.args.pop(variableOrKey[0], True)

def Make(self, customs : Iterable[str]):
def Make(self, customs):
self.args = self.saved_args
profile = self.args.get("profile", "")
if profile:
Expand All @@ -27,7 +28,7 @@ def Make(self, customs : Iterable[str]):
customs.append(profile + ".py")
self.opts = Variables(customs, self.args)
for opt in self.opt_list:
if opt[1] == None and opt[2] == None:
if opt[1] is None and opt[2] is None:
self.opts.Add(opt[0])
else:
self.opts.Add(opt[0], *opt[1], **opt[2])
Expand Down
46 changes: 46 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[tool.mypy]
ignore_missing_imports = true
disallow_any_generics = true
no_implicit_optional = true
pretty = true
show_column_numbers = true
warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
namespace_packages = true
explicit_package_bases = true

[tool.ruff]
extend-include = ["SConstruct", "SCsub"]
line-length = 120
target-version = "py37"

[tool.ruff.lint]
extend-select = [
"I", # isort
]

[tool.ruff.lint.per-file-ignores]
"{SConstruct,SCsub}" = [
"E402", # Module level import not at top of file
"F821", # Undefined name
]

[tool.typos]
files.extend-exclude = [".mailmap", "*.gitignore", "*.po", "*.pot", "*.rc"]
default.extend-ignore-re = [
"(?Rm)^.*(#|//)\\s*spellchecker:disable-line$", # Single line check disable
"(?s)(#|//)\\s*spellchecker:off.*?\\n\\s*(#|//)\\s*spellchecker:on", # Multiline check disable with // spellchecker:off // spellchecker:on (can also use #)
"(?s)(/\\*)\\s*spellchecker:off.*?\\s*spellchecker:on\\s*(\\*/)", # Multiline check disable with /* spellchecker:off ... spellchecker:on */
"uid://\\S+", # Ignore engine uids
"id=\"[^\"]+\"", # Ignore scene ids
"ExtResource\\(\"[^\"]+\"\\)", # Ignore scene ids
]
type.xml.locale = "en-us"
type.xml.check-filename = false
type.xml.extend-ignore-re = [
'<.* name="[^"]+".*>',
'\[(param|member|method)?.+\]',
]
[tool.typos.default.extend-identifiers]
PNGs = "PNGs"