Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pre-commit #33

Merged
merged 5 commits into from
Jul 6, 2024
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
19 changes: 19 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: checks

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.9"
- uses: pre-commit/[email protected]
with:
extra_args: --all-files
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
)$
4 changes: 3 additions & 1 deletion .vscode-default/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 0 additions & 1 deletion docs/src/basic_tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ Basic Tutorials

tutorials/image_io_and_manipulation
tutorials/compute_shader

9 changes: 7 additions & 2 deletions examples/print/print.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand All @@ -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.
Expand All @@ -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")
Expand Down
1 change: 0 additions & 1 deletion src/sgl/device/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# SPDX-License-Identifier: Apache-2.0

4 changes: 3 additions & 1 deletion src/sgl/device/tests/slang/test_float16.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions tools/pymacro.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,30 @@
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


HEADER_START_RE = re.compile(r"^\s*\/\*\s*<<<PYMACRO\s*$")
HEADER_END_RE = re.compile(r"^\s*>>>\s*\*\/\s*$")
FOOTER_RE = re.compile(r"^\s*\/\*\s+<<<PYMACROEND>>>\s*\*\/\s*$")


class State(Enum):
IDLE = 1
HEADER = 2
CONTENT = 3


def process_file(path: Path):

state = State.IDLE
Expand All @@ -42,15 +46,15 @@ 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
# print("header_start", header_line_index, m)
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)
Expand All @@ -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
Expand All @@ -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)
5 changes: 4 additions & 1 deletion tools/run_clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
DEFAULT_SLANG_EXTENSIONS = "slang,slangh"
DEFAULT_CLANG_FORMAT_IGNORE = ".clang-format-ignore"


class ExitStatus:
SUCCESS = 0
DIFF = 1
Expand Down Expand Up @@ -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
Expand All @@ -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 = []
Expand Down Expand Up @@ -442,7 +445,7 @@ def main():
recursive=args.recursive,
exclude=excludes,
extensions=args.extensions.split(","),
whitelist=whitelist
whitelist=whitelist,
)

if not files:
Expand Down
Loading