From 8e54d7a74d3b9e1ffaf863702d2999077d4bbc74 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Fri, 7 Jun 2024 16:31:02 -0700 Subject: [PATCH] Use poetry I'm not sure about this... --- .gitignore | 1 + Makefile | 76 +++++++++++++++----------------------------- pyproject.toml | 26 +++++++++------ requirements-dev.txt | 6 ---- tox.ini | 17 ---------- 5 files changed, 43 insertions(+), 83 deletions(-) delete mode 100644 requirements-dev.txt delete mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index b121d11..61ae24a 100644 --- a/.gitignore +++ b/.gitignore @@ -140,3 +140,4 @@ cython_debug/ tags unhacs.txt +poetry.lock diff --git a/Makefile b/Makefile index 6041451..a16dbb7 100644 --- a/Makefile +++ b/Makefile @@ -5,69 +5,43 @@ ENV := env .PHONY: default default: test -# Creates virtualenv -$(ENV): - python3 -m venv $(ENV) - -# Install package and dependencies in virtualenv -$(ENV)/bin/$(NAME): $(ENV) - $(ENV)/bin/pip install -r requirements-dev.txt - -# Install tox into virtualenv for running tests -$(ENV)/bin/tox: $(ENV) - $(ENV)/bin/pip install tox - -# Install wheel for building packages -$(ENV)/bin/wheel: $(ENV) - $(ENV)/bin/pip install wheel - -# Install twine for uploading packages -$(ENV)/bin/twine: $(ENV) - $(ENV)/bin/pip install twine - -# Installs dev requirements to virtualenv -.PHONY: devenv -devenv: $(ENV)/bin/$(NAME) - -# Generates a smaller env for running tox, which builds it's own env -.PHONY: test-env -test-env: $(ENV)/bin/tox - -# Generates a small build env for building and uploading dists -.PHONY: build-env -build-env: $(ENV)/bin/twine $(ENV)/bin/wheel - # Runs package .PHONY: run -run: $(ENV)/bin/$(NAME) - $(ENV)/bin/$(NAME) +run: + poetry run $(NAME) list -# Runs tests with tox +.PHONY: install +install: + poetry install + +.PHONY: devenv +devenv: install + +# Runs tests .PHONY: test -test: $(ENV)/bin/tox - $(ENV)/bin/tox +test: + poetry run pytest # Builds wheel for package to upload .PHONY: build -build: $(ENV)/bin/wheel - $(ENV)/bin/python setup.py sdist - $(ENV)/bin/python setup.py bdist_wheel +build: + poetry build # Verify that the python version matches the git tag so we don't push bad shas .PHONY: verify-tag-version verify-tag-version: $(eval TAG_NAME = $(shell [ -n "$(DRONE_TAG)" ] && echo $(DRONE_TAG) || git describe --tags --exact-match)) - test "v$(shell python setup.py -V)" = "$(TAG_NAME)" + test "v$(shell poetry version | awk '{print $$2}')" = "$(TAG_NAME)" -# Uses twine to upload to pypi +# Upload to pypi .PHONY: upload -upload: verify-tag-version build $(ENV)/bin/twine - $(ENV)/bin/twine upload dist/* +upload: verify-tag-version build + poetry publish # Uses twine to upload to test pypi .PHONY: upload-test -upload-test: verify-tag-version build $(ENV)/bin/twine - $(ENV)/bin/twine upload --repository-url https://test.pypi.org/legacy/ dist/* +upload-test: verify-tag-version build + poetry publish --repository testpypi # Cleans all build, runtime, and test artifacts .PHONY: clean @@ -79,20 +53,20 @@ clean: # Cleans dist and env .PHONY: dist-clean dist-clean: clean - rm -fr ./dist $(ENV) + rm -fr ./dist # Install pre-commit hooks .PHONY: install-hooks install-hooks: devenv - $(ENV)/bin/pre-commit install -f --install-hooks + pre-commit install -f --install-hooks # Generates test coverage .coverage: - $(ENV)/bin/tox + poetry run pytest # Builds coverage html htmlcov/index.html: .coverage - $(ENV)/bin/coverage html + poetry run coverage html # Opens coverage html in browser (on macOS and some Linux systems) .PHONY: open-coverage @@ -106,7 +80,7 @@ docs-clean: # Builds docs docs/build/html/index.html: - $(ENV)/bin/tox -e docs + @echo TODO: Make docs # Shorthand for building docs .PHONY: docs diff --git a/pyproject.toml b/pyproject.toml index a0a6609..8a52e20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,16 +1,24 @@ [build-system] -requires = ["setuptools", "wheel"] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" -[project] +[tool.poetry] name = "unhacs" version = "0.1.0" -description = "" -authors = [{name = "Ian Fijolek", email = "ian@iamthefij.com"}] -requires-python = ">=3.8" +description = "Command line interface to install Home Assistant Community Store packages" +authors = ["Ian Fijolek "] +license = "MIT" +readme = "README.md" -dependencies = [ - "requests" -] +[tool.poetry.dependencies] +python = "^3.11" +requests = "^2.32.3" -[project.scripts] +[tool.poetry.group.dev.dependencies] +black = "^24.4.2" +mypy = "^1.10.0" +pre-commit = "^3.7.1" +types-requests = "^2.32.0.20240602" + +[tool.poetry.scripts] unhacs = 'unhacs.main:main' diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 6b6f737..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,6 +0,0 @@ --e . -pytest -coverage -pre-commit -mypy -types-requests diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 82b243f..0000000 --- a/tox.ini +++ /dev/null @@ -1,17 +0,0 @@ -[tox] -envlist = py3,pypy3 - -[testenv] -deps = - -rrequirements-dev.txt -commands = - coverage erase - coverage run --source=unhacs/ -m pytest --capture=no -vv {posargs:tests} - coverage report -m --fail-under 70 - pre-commit run --all-files - -[testenv:pre-commit] -deps = - pre-commit -commands = - pre-commit {posargs}