diff --git a/.github/workflows/check-release.yml b/.github/workflows/check-release.yml index aa18ce55c..e9b4dad9b 100644 --- a/.github/workflows/check-release.yml +++ b/.github/workflows/check-release.yml @@ -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 "145135826+vizro-svc@users.noreply.github.com" git config user.name "Vizro Team" git add -A diff --git a/.github/workflows/lint-vizro-all.yml b/.github/workflows/lint-vizro-all.yml index ea820acd9..1e1060b52 100644 --- a/.github/workflows/lint-vizro-all.yml +++ b/.github/workflows/lint-vizro-all.yml @@ -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 diff --git a/vizro-ai/changelog.d/20231102_143844_maximilian_schulz_schema_linting.md b/vizro-ai/changelog.d/20231102_143844_maximilian_schulz_schema_linting.md new file mode 100644 index 000000000..f1f65e73c --- /dev/null +++ b/vizro-ai/changelog.d/20231102_143844_maximilian_schulz_schema_linting.md @@ -0,0 +1,48 @@ + + + + + + + + + diff --git a/vizro-ai/hatch.toml b/vizro-ai/hatch.toml index 65a6479ff..e9f6bf866 100644 --- a/vizro-ai/hatch.toml +++ b/vizro-ai/hatch.toml @@ -11,7 +11,6 @@ scripts = {add = "scriv create --add"} [envs.default] dependencies = [ "devtools[pygments]", - "pre-commit", "coverage[toml]>=6.5", "pytest", "toml", @@ -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)"' ] @@ -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" diff --git a/vizro-core/changelog.d/20231031_095110_antony.milne_schema_linting.md b/vizro-core/changelog.d/20231031_095110_antony.milne_schema_linting.md new file mode 100644 index 000000000..f1f65e73c --- /dev/null +++ b/vizro-core/changelog.d/20231031_095110_antony.milne_schema_linting.md @@ -0,0 +1,48 @@ + + + + + + + + + diff --git a/vizro-core/docs/pages/development/contributing.md b/vizro-core/docs/pages/development/contributing.md index ecf432fce..aa880efe2 100644 --- a/vizro-core/docs/pages/development/contributing.md +++ b/vizro-core/docs/pages/development/contributing.md @@ -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`. diff --git a/vizro-core/hatch.toml b/vizro-core/hatch.toml index bb9d66cc7..cec84e1da 100644 --- a/vizro-core/hatch.toml +++ b/vizro-core/hatch.toml @@ -16,7 +16,6 @@ scripts = {add = "scriv create --add"} [envs.default] dependencies = [ "devtools[pygments]", - "pre-commit", "coverage[toml]>=6.5", "pytest", "pytest-mock", @@ -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", @@ -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 diff --git a/vizro-core/schemas/generate.py b/vizro-core/schemas/generate.py index c7b9ad381..e0bd86a63 100644 --- a/vizro-core/schemas/generate.py +++ b/vizro-core/schemas/generate.py @@ -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 @@ -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