From b729981f1ed00aae37be0227508cadf9b2f8f821 Mon Sep 17 00:00:00 2001 From: Simon Kallweit Date: Sat, 6 Jul 2024 12:53:19 +0100 Subject: [PATCH 1/5] initial pre-commit config --- .pre-commit-config.yaml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..1f35ae08 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-symlinks + - id: check-merge-conflict + - id: check-yaml + - id: check-added-large-files +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v16.0.6 + hooks: + - id: clang-format +- repo: https://github.com/psf/black + rev: 24.4.2 + hooks: + - id: black + language_version: python3.9 +exclude: | + (?x)^( + .*\.ipynb| + build/.*| + external/.*| + src/sgl/python/py_doc.h + )$ From ac5aa10eba0120ca2e3a760791300312de6972c4 Mon Sep 17 00:00:00 2001 From: Simon Kallweit Date: Sat, 6 Jul 2024 12:57:25 +0100 Subject: [PATCH 2/5] formatting fixes --- .vscode-default/launch.json | 4 +++- docs/src/basic_tutorials.rst | 1 - examples/print/print.py | 9 +++++++-- setup.py | 8 +++++--- src/sgl/device/tests/__init__.py | 1 - src/sgl/device/tests/slang/test_float16.py | 4 +++- tools/pymacro.py | 15 ++++++++++----- tools/run_clang_format.py | 5 ++++- 8 files changed, 32 insertions(+), 15 deletions(-) diff --git a/.vscode-default/launch.json b/.vscode-default/launch.json index 4269e3b4..922b57c1 100644 --- a/.vscode-default/launch.json +++ b/.vscode-default/launch.json @@ -71,7 +71,9 @@ "windows": { "program": "${config:python.defaultInterpreterPath}" }, - "args": [ "${workspaceFolder}/scripts/internal/python/simple.py" ], + "args": [ + "${workspaceFolder}/scripts/internal/python/simple.py" + ], "stopAtEntry": false, "cwd": "${command:cmake.launchTargetDirectory}", "environment": [ diff --git a/docs/src/basic_tutorials.rst b/docs/src/basic_tutorials.rst index 9305df42..fefc2de3 100644 --- a/docs/src/basic_tutorials.rst +++ b/docs/src/basic_tutorials.rst @@ -8,4 +8,3 @@ Basic Tutorials tutorials/image_io_and_manipulation tutorials/compute_shader - diff --git a/examples/print/print.py b/examples/print/print.py index d49e4cce..95c550ff 100644 --- a/examples/print/print.py +++ b/examples/print/print.py @@ -3,10 +3,15 @@ EXAMPLE_DIR = Path(__file__).parent -device = sgl.Device(enable_print=True, compiler_options={"include_paths": [EXAMPLE_DIR]}) +device = sgl.Device( + enable_print=True, + compiler_options={ + "include_paths": [EXAMPLE_DIR], + }, +) program = device.load_program("print.slang", ["main"]) kernel = device.create_compute_kernel(program) -kernel.dispatch(thread_count=[2,2,1]) +kernel.dispatch(thread_count=[2, 2, 1]) device.flush_print() diff --git a/setup.py b/setup.py index 4dade2b0..0b3cca4c 100644 --- a/setup.py +++ b/setup.py @@ -21,11 +21,11 @@ SOURCE_DIR = Path(__file__).parent.resolve() if sys.platform.startswith("win"): - PLATFORM="windows" + PLATFORM = "windows" elif sys.platform.startswith("linux"): - PLATFORM="linux" + PLATFORM = "linux" elif sys.platform.startswith("darwin"): - PLATFORM="macos" + PLATFORM = "macos" else: raise Exception(f"Unsupported platform: {sys.platform}") @@ -41,6 +41,7 @@ "macos": "macos-clang", }[PLATFORM] + # A CMakeExtension needs a sourcedir instead of a file list. # The name must be the _single_ output extension from the CMake build. # If you need multiple extensions, see scikit-build. @@ -66,6 +67,7 @@ def build_extension(self, ext: CMakeExtension) -> None: env = os.environ.copy() if os.name == "nt": import setuptools.msvc + env = setuptools.msvc.msvc14_get_vc_env("x64") build_dir = str(SOURCE_DIR / "build/pip") diff --git a/src/sgl/device/tests/__init__.py b/src/sgl/device/tests/__init__.py index db439242..98813136 100644 --- a/src/sgl/device/tests/__init__.py +++ b/src/sgl/device/tests/__init__.py @@ -1,2 +1 @@ # SPDX-License-Identifier: Apache-2.0 - diff --git a/src/sgl/device/tests/slang/test_float16.py b/src/sgl/device/tests/slang/test_float16.py index 4682b3a0..683444ad 100644 --- a/src/sgl/device/tests/slang/test_float16.py +++ b/src/sgl/device/tests/slang/test_float16.py @@ -13,7 +13,9 @@ @pytest.mark.parametrize("view", ["uav", "srv"]) -@pytest.mark.parametrize("shader_model", helpers.all_shader_models_from(sgl.ShaderModel.sm_6_2)) +@pytest.mark.parametrize( + "shader_model", helpers.all_shader_models_from(sgl.ShaderModel.sm_6_2) +) @pytest.mark.parametrize("device_type", helpers.DEFAULT_DEVICE_TYPES) def test_float16(device_type, shader_model, view): device = helpers.get_device(device_type) diff --git a/tools/pymacro.py b/tools/pymacro.py index 6bd819d3..fe94df58 100644 --- a/tools/pymacro.py +++ b/tools/pymacro.py @@ -8,14 +8,16 @@ from enum import Enum from io import StringIO + class Capturing(list): def __enter__(self): self._stdout = sys.stdout sys.stdout = self._stringio = StringIO() return self + def __exit__(self, *args): self.extend(self._stringio.getvalue().splitlines()) - del self._stringio # free up some memory + del self._stringio # free up some memory sys.stdout = self._stdout @@ -23,11 +25,13 @@ def __exit__(self, *args): HEADER_END_RE = re.compile(r"^\s*>>>\s*\*\/\s*$") FOOTER_RE = re.compile(r"^\s*\/\*\s+<<>>\s*\*\/\s*$") + class State(Enum): IDLE = 1 HEADER = 2 CONTENT = 3 + def process_file(path: Path): state = State.IDLE @@ -42,7 +46,7 @@ def process_file(path: Path): if state == State.IDLE: lines_out.append(line) m = HEADER_START_RE.match(line) - if (m): + if m: # header_line_index = line_index script_lines = [] state = State.HEADER @@ -50,7 +54,7 @@ def process_file(path: Path): elif state == State.HEADER: lines_out.append(line) m = HEADER_END_RE.match(line) - if (m): + if m: # content_line_index = line_index state = State.CONTENT # print("content_start", content_line_index, m) @@ -65,7 +69,7 @@ def process_file(path: Path): script_lines.append(line) elif state == State.CONTENT: m = FOOTER_RE.match(line) - if (m): + if m: lines_out.append(line) # footer_line_index = line_index state = State.IDLE @@ -74,7 +78,8 @@ def process_file(path: Path): print("replaced\n\n") print("".join(lines_out)) - open(path,"w").writelines(lines_out) + open(path, "w").writelines(lines_out) + for path in sys.argv[1:]: process_file(path) diff --git a/tools/run_clang_format.py b/tools/run_clang_format.py index 4128376c..7830b04a 100644 --- a/tools/run_clang_format.py +++ b/tools/run_clang_format.py @@ -63,6 +63,7 @@ DEFAULT_SLANG_EXTENSIONS = "slang,slangh" DEFAULT_CLANG_FORMAT_IGNORE = ".clang-format-ignore" + class ExitStatus: SUCCESS = 0 DIFF = 1 @@ -94,6 +95,7 @@ def excludes_from_file(ignore_file): raise return [excludes, whitelist] + def is_child(path, files): if path in files: return True @@ -103,6 +105,7 @@ def is_child(path, files): return True return False + def list_files(files, recursive=False, extensions=None, exclude=None, whitelist=None): if extensions is None: extensions = [] @@ -442,7 +445,7 @@ def main(): recursive=args.recursive, exclude=excludes, extensions=args.extensions.split(","), - whitelist=whitelist + whitelist=whitelist, ) if not files: From 5e4eb0ad0c2c01098d5b69b62d0e477183db5217 Mon Sep 17 00:00:00 2001 From: Simon Kallweit Date: Sat, 6 Jul 2024 13:07:31 +0100 Subject: [PATCH 3/5] add github action to run pre-commit --- .github/workflows/pre-commit-checks.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/pre-commit-checks.yml diff --git a/.github/workflows/pre-commit-checks.yml b/.github/workflows/pre-commit-checks.yml new file mode 100644 index 00000000..6f0b4dd9 --- /dev/null +++ b/.github/workflows/pre-commit-checks.yml @@ -0,0 +1,19 @@ +name: pre-commit-checks + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.x" + - uses: pre-commit/action@v3.0.0 + with: + extra_args: --all-files From 253ea92623627ff610d6cd5cb3146d12712cb843 Mon Sep 17 00:00:00 2001 From: Simon Kallweit Date: Sat, 6 Jul 2024 14:36:16 +0100 Subject: [PATCH 4/5] use python 3.9 --- .github/workflows/pre-commit-checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit-checks.yml b/.github/workflows/pre-commit-checks.yml index 6f0b4dd9..83a461c7 100644 --- a/.github/workflows/pre-commit-checks.yml +++ b/.github/workflows/pre-commit-checks.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: "3.x" + python-version: "3.9" - uses: pre-commit/action@v3.0.0 with: extra_args: --all-files From d0aa5c892100a639191d64089f1e5cd7b32df333 Mon Sep 17 00:00:00 2001 From: Simon Kallweit Date: Sat, 6 Jul 2024 14:40:01 +0100 Subject: [PATCH 5/5] rename github action --- .github/workflows/{pre-commit-checks.yml => checks.yml} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{pre-commit-checks.yml => checks.yml} (90%) diff --git a/.github/workflows/pre-commit-checks.yml b/.github/workflows/checks.yml similarity index 90% rename from .github/workflows/pre-commit-checks.yml rename to .github/workflows/checks.yml index 83a461c7..26eeae53 100644 --- a/.github/workflows/pre-commit-checks.yml +++ b/.github/workflows/checks.yml @@ -1,4 +1,4 @@ -name: pre-commit-checks +name: checks on: push: @@ -7,7 +7,7 @@ on: branches: [ main ] jobs: - build: + pre-commit: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4