release-gitter/Makefile

107 lines
2.6 KiB
Makefile
Raw Normal View History

2022-01-05 23:20:28 +00:00
OPEN_CMD := $(shell type xdg-open &> /dev/null && echo 'xdg-open' || echo 'open')
NAME := release-gitter
ENV := venv
2022-01-05 23:20:28 +00:00
.PHONY: default
default: test
2023-10-27 20:36:48 +00:00
# Creates de virtualenv
2022-01-05 23:20:28 +00:00
$(ENV):
python3 -m venv $(ENV)
# Install package and dependencies in virtualenv
$(ENV)/bin/$(NAME): $(ENV)
$(ENV)/bin/pip install -r requirements-dev.txt
2023-10-27 20:36:48 +00:00
# Install hatch into virtualenv for running tests
$(ENV)/bin/hatch: $(ENV)
$(ENV)/bin/pip install hatch
2022-01-05 23:20:28 +00:00
# Installs dev requirements to virtualenv
.PHONY: devenv
devenv: $(ENV)/bin/$(NAME)
2023-10-27 20:36:48 +00:00
# Runs tests for current python
2022-01-05 23:20:28 +00:00
.PHONY: test
2023-10-27 20:36:48 +00:00
test: $(ENV)/bin/hatch
$(ENV)/bin/hatch run +py=3 test:run
# Runs test matrix
.PHONY: test-matrix
test-matrix: $(ENV)/bin/hatch
$(ENV)/bin/hatch run test:run
2022-01-05 23:20:28 +00:00
# Builds wheel for package to upload
.PHONY: build
2023-10-27 20:36:48 +00:00
build: $(ENV)/bin/hatch
$(ENV)/bin/hatch build
2022-01-05 23:20:28 +00:00
# Verify that the python version matches the git tag so we don't push bad shas
.PHONY: verify-tag-version
verify-tag-version: $(ENV)/bin/hatch
2022-01-05 23:20:28 +00:00
$(eval TAG_NAME = $(shell [ -n "$(DRONE_TAG)" ] && echo $(DRONE_TAG) || git describe --tags --exact-match))
2023-10-27 20:36:48 +00:00
test "v$(shell $(ENV)/bin/hatch version)" = "$(TAG_NAME)"
2022-01-05 23:20:28 +00:00
2023-10-27 20:36:48 +00:00
# Upload to pypi
2022-01-05 23:20:28 +00:00
.PHONY: upload
2023-10-27 20:36:48 +00:00
upload: verify-tag-version build
$(ENV)/bin/hatch publish
2022-01-05 23:20:28 +00:00
# Uses twine to upload to test pypi
.PHONY: upload-test
2023-10-27 20:36:48 +00:00
upload-test: build
# Bump version to a post version based on num of commits since last tag to prevent overwriting
$(ENV)/bin/hatch version $(shell git describe --tags | sed 's/-[0-9a-z]*$$//')
2023-10-27 20:52:03 +00:00
$(ENV)/bin/hatch publish --repo test
2022-01-05 23:20:28 +00:00
# Cleans all build, runtime, and test artifacts
.PHONY: clean
clean:
2023-10-27 20:36:48 +00:00
rm -fr ./build *.egg-info ./htmlcov ./.coverage ./.pytest_cache
2022-01-05 23:20:28 +00:00
find . -name '*.pyc' -delete
find . -name '__pycache__' -delete
# Cleans dist and env
.PHONY: dist-clean
dist-clean: clean
2023-10-27 20:36:48 +00:00
-$(ENV)/bin/hatch env prune
2022-01-05 23:20:28 +00:00
rm -fr ./dist $(ENV)
2023-10-27 20:36:48 +00:00
# Run linters
.PHONY: lint
lint: $(ENV)/bin/hatch
$(ENV)/bin/hatch run lint:all
2022-01-05 23:20:28 +00:00
# Install pre-commit hooks
.PHONY: install-hooks
install-hooks: devenv
2023-10-27 20:36:48 +00:00
$(ENV)/bin/hatch run lint:install-hooks
2022-01-05 23:20:28 +00:00
# Generates test coverage
2023-10-27 20:36:48 +00:00
.coverage: test
2022-01-05 23:20:28 +00:00
# Builds coverage html
htmlcov/index.html: .coverage
2023-10-27 20:36:48 +00:00
$(ENV)/bin/hatch run coverage html
2022-01-05 23:20:28 +00:00
# Opens coverage html in browser (on macOS and some Linux systems)
.PHONY: open-coverage
open-coverage: htmlcov/index.html
$(OPEN_CMD) htmlcov/index.html
# Cleans out docs
.PHONY: docs-clean
docs-clean:
rm -fr docs/build/* docs/source/code/*
# Builds docs
docs/build/html/index.html:
2023-10-27 20:36:48 +00:00
$(ENV)/bin/hatch run docs:build
2022-01-05 23:20:28 +00:00
# Shorthand for building docs
.PHONY: docs
docs: docs/build/html/index.html
.PHONY: clean-all
clean-all: clean dist-clean docs-clean