build:
	rm -rf dist/*
	uv build

format:
	uv run autoflake --in-place -r --remove-all-unused-imports --remove-unused-variables src/
	uv run autopep8 --recursive --in-place --select W292,W293,W391,E121,E122,E123,E126,E128,E129,E131,E202,E225,E226,E241,E301,E302,E303,E704,E731 src/
	uv run ruff check --config pyproject.toml --fix src/
	# Same line length as Black
	uv run isort --line-length 88 src/

test:
	uv run nose2

lint:
	uv run autoflake --check-diff -r --quiet \
		--remove-all-unused-imports \
		--remove-unused-variables \
		--remove-duplicate-keys \
		src/
	uv run flake8 src/ \
	  --extend-exclude venv \
		--count \
		--show-source \
		--statistics \
		--max-line-length=120 \
		--ignore=E501,W503,E126 \
		--indent-size=2
	# Config file is specified for brevity
	uv run ruff check --config pyproject.toml src/
	uv run isort \
	  --check \
		--diff \
		--line-length 120 \
		src/
	uv run pylint \
	  --rcfile=.pylintrc \
	  --indent-string="  " \
	  --output-format=colorized \
		src/

clean:
	rm -rf dist/

run:
	uv run -- quvm

#dockerbuild:
#	docker build -t quvm .

publish-testpypi: export UV_PUBLISH_TOKEN = $(shell cat token-testpypi.txt)
publish-testpypi: build
	@if [ -z "$$UV_PUBLISH_TOKEN" ]; then \
		echo "Error: UV_PUBLISH_TOKEN is empty or not set. Create or symlink token-testpypi.txt." >&2; \
		exit 1; \
	fi
	uv publish --index testpypi

publish-pypi: export UV_PUBLISH_TOKEN = $(shell cat token-pypi.txt)
publish-pypi: build
	@if [ -z "$$UV_PUBLISH_TOKEN" ]; then \
		echo "Error: UV_PUBLISH_TOKEN is empty or not set. Create or symlink token-pypi.txt." >&2; \
		exit 1; \
	fi
	uv publish
