Skip to content

Commit 9e27f12

Browse files
committed
chore: pyproject, pre-commit
1 parent 9485f40 commit 9e27f12

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

.husky/pre-commit

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ then
88
echo "Re-building JS and PY assets using JS script."
99
npm run transpile-and-build-assets
1010
fi
11+
pwd
1112

12-
if -d .venv/bin/activate
13+
if test -f .venv/bin/activate
1314
then
14-
echo "Python virtual environment not found. Running build scripts."
15+
echo "Python virtual environment found. Running build scripts"
1516
echo "Re-building JS and PY assets using JS script."
1617
source .venv/bin/activate
1718
# Note: resolved (no include statements) schemas have to exist by this time
18-
datamodel-codegen --input ./dist/js/schema/ --input-file-type jsonschema --output ./dist/py --class-name ESSE --output-model-type pydantic_v2.BaseModel --use-field-description --use-double-quotes --enable-version-header --disable-timestamp --use-title-as-nam
19+
pre-commit run --all-files
20+
#git add dist/py
1921
else
20-
echo "Python virtual environment found. Create one in '.venv'."
22+
echo "ERROR: Python virtual environment found. Create one in '.venv' and install '.[all]'"
2123
exit 1
2224
fi
2325

2426
npx lint-staged --allow-empty
2527

2628
npm run lint:fix
2729
npm run transpile
28-
git add dist
30+
#git add dist/js
2931

.pre-commit-config.yaml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,31 @@ repos:
33
rev: 2023.6.13
44
hooks:
55
- id: ruff
6-
exclude: ^src/py/mat3ra/esse/data
6+
exclude: ^src/py/mat3ra/esse/data|^dist*
77
- id: black
8-
exclude: ^src/py/mat3ra/esse/data
8+
exclude: ^src/py/mat3ra/esse/data|^dist*
99
- repo: local
1010
hooks:
1111
# Note: only python 3.8.12 is tested for the model generation
1212
- id: generate-python-modules
1313
name: Regenerate data modules classes from static assets
1414
# yamllint disable rule:line-length
1515
entry: |
16-
bash -c 'datamodel-codegen --input ./dist/js/schema/ --input-file-type jsonschema --output ./dist/py --class-name ESSE --output-model-type pydantic_v2.BaseModel --use-field-description --use-double-quotes --enable-version-header --disable-timestamp'
17-
# Move 3rd party modules to a separate directory with a PEP8 compliant name
18-
mkdir -p ./dist/py/third_party
19-
mv ./dist/py/3pse/* ./dist/py/third_party/
20-
rmdir ./dist/py/3pse
16+
bash -c 'if ! [ "$(git diff --cached --name-only | grep "schema/")" ]; then echo "Skipping model generation because schemas were not changed."; exit 0; fi && \
17+
datamodel-codegen \
18+
--input ./dist/js/schema/ \
19+
--input-file-type jsonschema \
20+
--output ./dist/py \
21+
--output-model-type pydantic_v2.BaseModel \
22+
--use-field-description \
23+
--use-double-quotes \
24+
--enable-version-header \
25+
--use-title-as-name \
26+
--class-name ESSE \
27+
--disable-timestamp && \
28+
# Move 3rd party modules to a separate directory with a PEP8 compliant name
29+
rm -rf ./dist/py/third_party && \
30+
mv ./dist/py/3pse ./dist/py/third_party'
2131
language: system
2232
pass_filenames: false
2333
verbose: true

build_schemas.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,3 @@
5858
Path(full_path).parent.mkdir(parents=True, exist_ok=True)
5959
with open(full_path, "w") as f:
6060
f.write(json.dumps(example, sort_keys=True, indent=4, separators=(",", ": ")))
61-

pyproject.toml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ classifiers = [
1717
dependencies = [
1818
"exabyte-json-include>=2023.12.23.post0",
1919
"jsonschema>=2.6.0",
20-
"datamodel-code-generator==0.21.5",
20+
"datamodel-code-generator>=0.25.5",
2121
# "python-slugify==2.0.1",
2222
# PyYAML install could be problematic, see https://github.com/yaml/pyyaml/issues/601
2323
# To avoid "AttributeError: cython_sources", consider "cython<3.0.0", the below might be needed:
@@ -59,7 +59,22 @@ git_describe_command = "git describe --tags --long"
5959
# local_scheme = "no-local-version"
6060

6161
[tool.setuptools.packages.find]
62-
where = ["src/py"]
62+
where = [
63+
"src/py",
64+
]
65+
66+
[tool.setuptools.package-data]
67+
"*" = [
68+
# NOTE: may be needed to allow for the `models` link in the `src/py` directory
69+
# "dist/py/**"
70+
]
71+
72+
[tool.setuptools.exclude-package-data]
73+
"*" = [
74+
# Since models inside `src/py` is a link, exclusion is needed
75+
# to avoid `doesn't exist or not a regular file` error
76+
"models"
77+
]
6378

6479
[tool.black]
6580
line-length = 120

0 commit comments

Comments
 (0)