Skip to content

Commit

Permalink
Merge branch 'main' into work/incorrect-make-help
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau authored Dec 9, 2024
2 parents ba2d4b7 + 533a546 commit 8c63349
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
- id: fix-byte-order-marker
- id: mixed-line-ending
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.8.1"
rev: "v0.8.2"
hooks:
# Run the linter
- id: ruff
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ publish-pypi: clean package-pip lint-twine ##- Publish Python packages to pypi

# Used for installing build dependencies in CI.
.PHONY: install-build-deps
install-build-deps:
install-build-deps: install-lint-build-deps
ifeq ($(shell which apt-get),)
$(warning Cannot install build dependencies without apt.)
else ifeq ($(wildcard /usr/include/libxml2/libxml/xpath.h),)
Expand All @@ -37,3 +37,7 @@ else ifeq ($(wildcard /usr/include/libxslt/xslt.h),)
else ifeq ($(wildcard /usr/share/doc/python3-venv/copyright),)
sudo $(APT) install python3-venv
endif

# If additional build dependencies need installing in order to build the linting env.
.PHONY: install-lint-build-deps
install-lint-build-deps:
66 changes: 60 additions & 6 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ setup-tests: install-uv install-build-deps ##- Set up a testing environment with
uv sync --frozen

.PHONY: setup-lint
setup-lint: install-uv install-shellcheck ##- Set up a linting-only environment
uv sync --frozen --no-dev --no-install-workspace --extra lint --extra types
setup-lint: install-uv install-shellcheck install-lint-build-deps ##- Set up a linting-only environment
uv sync --frozen --no-install-workspace --extra lint --extra types

.PHONY: setup-docs
setup-docs: install-uv ##- Set up a documentation-only environment
Expand All @@ -72,7 +72,7 @@ clean: ## Clean up the development environment
autoformat: format # Hidden alias for 'format'

.PHONY: format-ruff
format-ruff: ##- Automatically format with ruff
format-ruff: install-ruff ##- Automatically format with ruff
success=true
ruff check --fix $(SOURCES) || success=false
ruff format $(SOURCES)
Expand All @@ -83,43 +83,91 @@ format-codespell: ##- Fix spelling issues with codespell
uv run codespell --toml pyproject.toml --write-changes $(SOURCES)

.PHONY: lint-ruff
lint-ruff: ##- Lint with ruff
lint-ruff: install-ruff ##- Lint with ruff
ifneq ($(CI),)
@echo ::group::$@
endif
ruff check $(SOURCES)
ruff format --diff $(SOURCES)
ifneq ($(CI),)
@echo ::endgroup::
endif

.PHONY: lint-codespell
lint-codespell: ##- Check spelling with codespell
ifneq ($(CI),)
@echo ::group::$@
endif
uv run codespell --toml pyproject.toml $(SOURCES)
ifneq ($(CI),)
@echo ::endgroup::
endif

.PHONY: lint-mypy
lint-mypy: ##- Check types with mypy
ifneq ($(CI),)
@echo ::group::$@
endif
uv run mypy --show-traceback --show-error-codes $(PROJECT)
ifneq ($(CI),)
@echo ::endgroup::
endif

.PHONY: lint-pyright
lint-pyright: ##- Check types with pyright
ifneq ($(CI),)
@echo ::group::$@
endif
ifneq ($(shell which pyright),) # Prefer the system pyright
pyright --pythonpath .venv/bin/python
else
# Fix for a bug in npm
[ -d "/home/ubuntu/.npm/_cacache" ] && chown -R 1000:1000 "/home/ubuntu/.npm" || true
uv run pyright
uv run pyright --pythonpath .venv/bin/python
endif
ifneq ($(CI),)
@echo ::endgroup::
endif

.PHONY: lint-shellcheck
lint-shellcheck: ##- Lint shell scripts
ifneq ($(CI),)
@echo ::group::$@
endif
git ls-files | file --mime-type -Nnf- | grep shellscript | cut -f1 -d: | xargs -r shellcheck
ifneq ($(CI),)
@echo ::endgroup::
endif

.PHONY: lint-yaml
lint-yaml: ##- Lint YAML files with yamllint
ifneq ($(CI),)
@echo ::group::$@
endif
uv run --extra lint yamllint .
ifneq ($(CI),)
@echo ::endgroup::
endif

.PHONY: lint-docs
lint-docs: ##- Lint the documentation
ifneq ($(CI),)
@echo ::group::$@
endif
uv run --extra docs sphinx-lint --max-line-length 88 --enable all $(DOCS)
ifneq ($(CI),)
@echo ::endgroup::
endif

.PHONY: lint-twine
lint-twine: pack-pip ##- Lint Python packages with twine
ifneq ($(CI),)
@echo ::group::$@
endif
uv tool run twine check dist/*
ifneq ($(CI),)
@echo ::endgroup::
endif

.PHONY: test
test: ## Run all tests
Expand Down Expand Up @@ -150,7 +198,13 @@ docs-auto: ## Build and host docs with sphinx-autobuild

.PHONY: pack-pip
pack-pip: ##- Build packages for pip (sdist, wheel)
ifneq ($(CI),)
@echo ::group::$@
endif
uv build .
ifneq ($(CI),)
@echo ::endgroup::
endif

# Below are intermediate targets for setup. They are not included in help as they should
# not be used independently.
Expand Down Expand Up @@ -198,5 +252,5 @@ else ifneq ($(shell which snap),)
else ifneq ($(shell which brew),)
brew install shellcheck
else
$(warning Codespell not installed. Please install it yourself.)
$(warning Shellcheck not installed. Please install it yourself.)
endif
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ lint = [
]
types = [
"mypy[reports]~=1.13.0",
"pyright==1.1.389",
"pyright==1.1.390",
"types-Pygments",
"types-colorama",
"types-setuptools",
Expand Down Expand Up @@ -61,7 +61,7 @@ dev-dependencies = [
"pytest-mock~=3.12",
"yamllint~=1.34",
"mypy[reports]~=1.13.0",
"pyright==1.1.389",
"pyright==1.1.390",
"types-Pygments",
"types-colorama",
"types-setuptools",
Expand Down
12 changes: 6 additions & 6 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8c63349

Please sign in to comment.