nmhit 0.1.4__tar.gz → 0.1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nmhit-0.1.5/.pre-commit-hooks.yaml +10 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/CMakeLists.txt +1 -1
- {nmhit-0.1.4 → nmhit-0.1.5}/PKG-INFO +1 -1
- {nmhit-0.1.4 → nmhit-0.1.5}/pyproject.toml +4 -1
- nmhit-0.1.5/python/nmhit/_cli.py +79 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/.clang-format +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/.github/workflows/ci.yml +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/.github/workflows/release.yml +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/.gitignore +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/.pre-commit-config.yaml +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/CONTRIBUTING.md +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/README.md +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/cmake/nmhit.pc.in +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/cmake/nmhitConfig.cmake.in +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/generated/Lexer.cpp +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/generated/Lexer.h +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/generated/Parser.cpp +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/generated/Parser.h +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/generated/location.hh +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/include/nmhit/BraceExpr.h +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/include/nmhit/Node.h +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/include/nmhit/TypeRegistry.h +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/include/nmhit/nmhit.h +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/python/nmhit/__init__.py +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/python/nmhit/py.typed +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/python/src/_nmhit.cpp +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/python/tests/test_nmhit.py +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/src/BraceExpr.cpp +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/src/Lexer.l +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/src/Node.cpp +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/src/ParseDriver.h +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/src/Parser.y +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/tests/CMakeLists.txt +0 -0
- {nmhit-0.1.4 → nmhit-0.1.5}/tests/test_hit.cpp +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
- id: nmhit-format
|
|
2
|
+
name: nmhit-format
|
|
3
|
+
description: >-
|
|
4
|
+
Reformat NEML2-dialect HIT input files in place via nmhit's reparse/render
|
|
5
|
+
round-trip. Files without the `# neml2` dialect marker on their first
|
|
6
|
+
non-blank line are silently skipped.
|
|
7
|
+
entry: nmhit-format
|
|
8
|
+
language: python
|
|
9
|
+
files: \.i$
|
|
10
|
+
types: [text]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
cmake_minimum_required(VERSION 3.20)
|
|
2
2
|
# Keep this version in sync with [project] version in pyproject.toml.
|
|
3
|
-
project(neml2-hit VERSION 0.1.
|
|
3
|
+
project(neml2-hit VERSION 0.1.5 LANGUAGES CXX)
|
|
4
4
|
|
|
5
5
|
set(CMAKE_CXX_STANDARD 17)
|
|
6
6
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
@@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "nmhit"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.5" # Keep in sync with VERSION in CMakeLists.txt.
|
|
8
8
|
description = "Python bindings for the nmhit NEML2-flavored HIT parser"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -18,6 +18,9 @@ classifiers = [
|
|
|
18
18
|
[project.optional-dependencies]
|
|
19
19
|
dev = ["pytest>=7"]
|
|
20
20
|
|
|
21
|
+
[project.scripts]
|
|
22
|
+
nmhit-format = "nmhit._cli:format_files"
|
|
23
|
+
|
|
21
24
|
[tool.scikit-build]
|
|
22
25
|
cmake.build-type = "Release"
|
|
23
26
|
cmake.args = ["-DNMHIT_BUILD_TESTS=OFF", "-DNMHIT_BUILD_PYTHON=ON", "-DCMAKE_POSITION_INDEPENDENT_CODE=ON"]
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Command-line entry points for nmhit.
|
|
2
|
+
|
|
3
|
+
Currently provides a single command, ``nmhit-format``, which reparses each
|
|
4
|
+
input file with nmhit and writes the canonical render back in place. The
|
|
5
|
+
intended use is as a pre-commit hook on NEML2-flavored HIT input files.
|
|
6
|
+
|
|
7
|
+
Dialect opt-in
|
|
8
|
+
--------------
|
|
9
|
+
|
|
10
|
+
nmhit can parse plain MOOSE-HIT as well as NEML2-flavored HIT. To distinguish
|
|
11
|
+
the two without ambiguity, NEML2 input files declare their dialect by writing
|
|
12
|
+
the line ``# neml2`` as the first non-blank line of the file. The neml2-langserv
|
|
13
|
+
VS Code extension uses the same marker to decide whether to attach. The
|
|
14
|
+
formatter follows suit: files whose first non-blank line is not ``# neml2``
|
|
15
|
+
are silently skipped, even if they match the hook's ``files:`` pattern.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import argparse
|
|
21
|
+
import sys
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
from . import parse_file
|
|
25
|
+
|
|
26
|
+
DIALECT_MARKER = "# neml2"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _is_neml2(path: Path) -> bool:
|
|
30
|
+
"""Return True iff the first non-blank line of *path* is exactly the
|
|
31
|
+
NEML2 dialect marker.
|
|
32
|
+
"""
|
|
33
|
+
try:
|
|
34
|
+
with path.open() as f:
|
|
35
|
+
for line in f:
|
|
36
|
+
stripped = line.strip()
|
|
37
|
+
if not stripped:
|
|
38
|
+
continue
|
|
39
|
+
return stripped == DIALECT_MARKER
|
|
40
|
+
except OSError:
|
|
41
|
+
return False
|
|
42
|
+
return False
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def format_files(argv: list[str] | None = None) -> int:
|
|
46
|
+
"""Entry point for ``nmhit-format``.
|
|
47
|
+
|
|
48
|
+
Reparses each NEML2-marked input file and rewrites it in place if the
|
|
49
|
+
canonical render differs from the original. Returns 1 when any file was
|
|
50
|
+
modified (so the script exits non-zero under pre-commit, signalling that
|
|
51
|
+
a reformat happened and the commit should be retried), 0 otherwise.
|
|
52
|
+
"""
|
|
53
|
+
parser = argparse.ArgumentParser(
|
|
54
|
+
prog="nmhit-format",
|
|
55
|
+
description=(
|
|
56
|
+
"Reformat NEML2-dialect HIT input files in place. Files without "
|
|
57
|
+
"the `# neml2` dialect marker on their first non-blank line are "
|
|
58
|
+
"skipped silently."
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
parser.add_argument("files", nargs="+", help="HIT input files to format")
|
|
62
|
+
args = parser.parse_args(argv)
|
|
63
|
+
|
|
64
|
+
changed = 0
|
|
65
|
+
for arg in args.files:
|
|
66
|
+
path = Path(arg)
|
|
67
|
+
if not _is_neml2(path):
|
|
68
|
+
continue
|
|
69
|
+
src = path.read_text()
|
|
70
|
+
new = parse_file(path).render()
|
|
71
|
+
if new != src:
|
|
72
|
+
path.write_text(new)
|
|
73
|
+
print(f"reformatted {arg}", file=sys.stderr)
|
|
74
|
+
changed += 1
|
|
75
|
+
return 1 if changed else 0
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
raise SystemExit(format_files())
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|