Skip to content

Commit

Permalink
Tidy schema linting (#136)
Browse files Browse the repository at this point in the history
Signed-off-by: Antony Milne <[email protected]>
Co-authored-by: Maximilian Schulz <[email protected]>
Co-authored-by: Maximilian Schulz <[email protected]>
  • Loading branch information
3 people authored Nov 2, 2023
1 parent 01e240b commit b81139b
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 15 deletions.
1 change: 0 additions & 1 deletion .github/workflows/check-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ jobs:
hatch version patch,dev
hatch run changelog:add
hatch run schema
hatch run lint || hatch run lint
git config user.email "[email protected]"
git config user.name "Vizro Team"
git add -A
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/lint-vizro-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,5 @@ jobs:
- name: Install Hatch
run: pip install --upgrade hatch

- name: List dependencies
run: hatch run all.py${{ matrix.python-version }}:pip freeze

- name: Lint
run: hatch run all.py${{ matrix.python-version }}:lint
run: hatch run lint:lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨
- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Removed
- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Added
- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Changed
- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Deprecated
- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Fixed
- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Security
- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
11 changes: 8 additions & 3 deletions vizro-ai/hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ scripts = {add = "scriv create --add"}
[envs.default]
dependencies = [
"devtools[pygments]",
"pre-commit",
"coverage[toml]>=6.5",
"pytest",
"toml",
Expand All @@ -30,11 +29,10 @@ cov-report = [
"- coverage combine",
"coverage report"
]
lint = "SKIP=gitleaks pre-commit run {args} --all-files"
lint = "hatch run lint:lint {args:--all-files}"
prep-release = [
"hatch version release",
"hatch run changelog:scriv collect --add",
"hatch run lint || hatch run lint",
"hatch run changelog:add",
'echo "Now raise a PR to merge into main with title: Release of vizro-ai $(hatch version)"'
]
Expand All @@ -61,5 +59,12 @@ dependencies = [
detached = true
scripts = {serve = "mkdocs serve"}

[envs.lint]
dependencies = [
"pre-commit"
]
detached = true
scripts = {lint = "SKIP=gitleaks pre-commit run {args:--all-files}"}

[version]
path = "src/vizro_ai/__init__.py"
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨
- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Removed
- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Added
- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Changed
- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Deprecated
- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Fixed
- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Security
- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
2 changes: 1 addition & 1 deletion vizro-core/docs/pages/development/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ line-length = 120
Linting checks are enforced in CI. To run pre-commit hooks locally, there are two options:

1. Run `hatch run pre-commit install` to automatically run the hooks on every commit (you can always skip the checks with `git commit --no-verify`). In case this fails due to `gitleaks`, please read below for an explanation and how to install `go`.
2. Run `hatch run lint` to run `pre-commit` hooks on all files. (You can run eg `hatch run lint mypy` to only run specific linters, here mypy.)
2. Run `hatch run lint` to run `pre-commit` hooks on all files. (You can run e.g. `hatch run lint mypy -a` to only run specific linters, here mypy, on all files.)

Note that Hatch's `default` environment specifies `pre-commit` as a dependency but otherwise _does not_ specify dependencies for linting tools such as `black`. These are controlled by [.pre-commit-config.yaml](https://github.com/mckinsey/vizro/blob/main/.pre-commit-config.yaml) and can be updated when required with `pre-commit autoupdate`.

Expand Down
13 changes: 9 additions & 4 deletions vizro-core/hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ scripts = {add = "scriv create --add"}
[envs.default]
dependencies = [
"devtools[pygments]",
"pre-commit",
"coverage[toml]>=6.5",
"pytest",
"pytest-mock",
Expand All @@ -41,19 +40,18 @@ cov-report = [
"coverage report"
]
example = "cd examples/{args:default}; python app.py"
lint = "SKIP=gitleaks pre-commit run {args} --all-files"
lint = "hatch run lint:lint {args:--all-files}"
prep-release = [
"hatch version release",
"hatch run changelog:scriv collect --add",
"rm -rf schemas/*json",
"schema",
"git add schemas",
"hatch run lint || hatch run lint",
"hatch run changelog:add",
'echo "Now raise a PR to merge into main with title: Release of vizro-core $(hatch version)"'
]
pypath = "python -c 'import sys; print(sys.executable)'"
schema = "python schemas/generate.py {args}"
schema = ["python schemas/generate.py {args}", 'hatch run lint --files="schemas/$(hatch version).json" > /dev/null']
secrets = "pre-commit run gitleaks --all-files"
test = [
"test-unit",
Expand All @@ -80,6 +78,13 @@ dependencies = [
detached = true
scripts = {serve = "mkdocs serve"}

[envs.lint]
dependencies = [
"pre-commit"
]
detached = true
scripts = {lint = "SKIP=gitleaks pre-commit run {args:--all-files}"}

[publish.index]
disable = true

Expand Down
2 changes: 0 additions & 2 deletions vizro-core/schemas/generate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Script to generate JSON schema. For more information, run `hatch run schema --help`."""
import argparse
import json
import subprocess
import sys
from pathlib import Path

Expand All @@ -22,4 +21,3 @@
print("JSON schema is up to date.") # noqa: T201
else:
schema_path.write_text(schema_json)
subprocess.run("hatch run lint", shell=True, stdout=subprocess.DEVNULL) # nosec

0 comments on commit b81139b

Please sign in to comment.