From 8b1a33ec1e165a71c7a8044dc0ab83cde2a7338f Mon Sep 17 00:00:00 2001 From: jo Date: Thu, 22 Jun 2023 16:06:41 +0200 Subject: [PATCH] chore: rework dev setup --- .flake8 | 5 + .github/ISSUE_TEMPLATE.md | 6 -- .github/workflows/code_style.yml | 22 ----- .github/workflows/lint.yml | 24 +++++ .github/workflows/release-please.yml | 6 +- .github/workflows/release.yml | 6 +- .../workflows/{bot_stale.yml => stale.yml} | 2 +- .github/workflows/{unit_test.yml => test.yml} | 26 ++--- .gitlab-ci.yml | 53 ++++------- .pre-commit-config.yaml | 1 - Makefile | 94 ++++--------------- docs/conf.py | 2 +- pyproject.toml | 7 ++ requirements/base.txt | 1 - requirements/test.txt | 4 - setup.cfg | 19 ---- setup.py | 45 +++++---- tox.ini | 2 +- 18 files changed, 121 insertions(+), 204 deletions(-) create mode 100644 .flake8 delete mode 100644 .github/ISSUE_TEMPLATE.md delete mode 100644 .github/workflows/code_style.yml create mode 100644 .github/workflows/lint.yml rename .github/workflows/{bot_stale.yml => stale.yml} (96%) rename .github/workflows/{unit_test.yml => test.yml} (53%) delete mode 100644 requirements/base.txt delete mode 100644 requirements/test.txt delete mode 100644 setup.cfg mode change 100755 => 100644 setup.py diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..09ecbe1 --- /dev/null +++ b/.flake8 @@ -0,0 +1,5 @@ +[flake8] +extend-ignore = + E501 +extend-exclude = + docs diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 24e79d0..0000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/.github/workflows/code_style.yml b/.github/workflows/code_style.yml deleted file mode 100644 index 03ed9ba..0000000 --- a/.github/workflows/code_style.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Code Style - -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup python - uses: actions/setup-python@v4 - with: - python-version: 3.9 - architecture: x64 - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements/test.txt - pip install tox tox-gh-actions - sudo apt install build-essential - - name: pre-commit with tox - run: tox -e pre-commit diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..db52637 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,24 @@ +name: Lint + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup python + uses: actions/setup-python@v4 + with: + python-version: 3.x + + - name: Install dependencies + run: pip install pre-commit + + - name: Run pre-commit + run: pre-commit run --all-files --show-diff-on-failure diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 609550f..b11e876 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -1,8 +1,8 @@ +name: Release please + on: push: - branches: - - main -name: release-please + branches: [main] jobs: release-please: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 820b3a7..1cf9e6e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,12 +13,10 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.x" + python-version: 3.x - name: Install dependencies - run: | - pip install --upgrade pip - pip install --upgrade build twine + run: pip install build twine - name: Build run: python3 -m build diff --git a/.github/workflows/bot_stale.yml b/.github/workflows/stale.yml similarity index 96% rename from .github/workflows/bot_stale.yml rename to .github/workflows/stale.yml index 322b4a7..466d9cb 100644 --- a/.github/workflows/bot_stale.yml +++ b/.github/workflows/stale.yml @@ -1,4 +1,4 @@ -name: "Close stale issues" +name: Close stale issues on: schedule: diff --git a/.github/workflows/unit_test.yml b/.github/workflows/test.yml similarity index 53% rename from .github/workflows/unit_test.yml rename to .github/workflows/test.yml index bb3de0e..7fe78db 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/test.yml @@ -1,28 +1,30 @@ -name: Unit Tests +name: Test -on: [push, pull_request] +on: + push: + branches: [main] + pull_request: + branches: [main] jobs: - build: + test: runs-on: ubuntu-latest + strategy: matrix: python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + name: Python ${{ matrix.python-version }} steps: - uses: actions/checkout@v3 + - name: Setup python uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - architecture: x64 + - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements/test.txt - pip install tox tox-gh-actions - sudo apt install build-essential - - name: Test with tox + run: pip install tox tox-gh-actions + + - name: Run tox run: tox - env: - PLATFORM: ${{ matrix.platform }} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 39f0eba..56d02f1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,42 +1,29 @@ -stages: - - test - -.tests_template: &tests_template - before_script: - - pip install tox - - apk add build-base git - stage: test - script: tox +default: tags: - hc-bladerunner -python37: - <<: *tests_template - image: python:3.7-alpine - script: tox -e py37 +stages: + - test -python38: - <<: *tests_template - image: python:3.8-alpine - script: tox -e py38 +pre-commit: + stage: test -python39: - <<: *tests_template - image: python:3.9-alpine - script: tox -e py39 + image: python:3.11-alpine + before_script: + - apk add build-base git + - pip install pre-commit + script: + - pre-commit run --all-files --show-diff-on-failure -python310: - <<: *tests_template - image: python:3.10-alpine - script: tox -e py310 +test: + stage: test -python311: - <<: *tests_template - image: python:3.11-alpine - script: tox -e py311 + parallel: + matrix: + - python_version: ["3.7", "3.8", "3.9", "3.10", "3.11"] -test-style: - <<: *tests_template - image: python:3.9-alpine + image: python:${python_version}-alpine + before_script: + - pip install tox script: - - tox -e pre-commit + - tox -e ${python_version} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eb75a7e..d759c06 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,7 +38,6 @@ repos: rev: 5.12.0 hooks: - id: isort - args: [--profile=black] - repo: https://github.com/psf/black rev: 23.3.0 diff --git a/Makefile b/Makefile index cb8a27a..b994d90 100644 --- a/Makefile +++ b/Makefile @@ -1,85 +1,23 @@ -.PHONY: clean clean-test clean-pyc clean-build docs help -.DEFAULT_GOAL := help +SHELL := bash +.PHONY: test coverage docs clean -define BROWSER_PYSCRIPT -import os, webbrowser, sys +venv: + python3 -m venv venv + venv/bin/pip install -e .[docs,test] -try: - from urllib import pathname2url -except: - from urllib.request import pathname2url +test: venv + venv/bin/pytest -v -webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) -endef -export BROWSER_PYSCRIPT +coverage: venv + venv/bin/coverage run -m pytest -v + venv/bin/coverage report --show-missing + venv/bin/coverage html + xdg-open htmlcov/index.html -define PRINT_HELP_PYSCRIPT -import re, sys - -for line in sys.stdin: - match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) - if match: - target, help = match.groups() - print("%-20s %s" % (target, help)) -endef -export PRINT_HELP_PYSCRIPT - -BROWSER := python -c "$$BROWSER_PYSCRIPT" - -help: - @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) - -clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts - -clean-build: ## remove build artifacts - rm -fr build/ - rm -fr dist/ - rm -fr .eggs/ - find . -name '*.egg-info' -exec rm -fr {} + - find . -name '*.egg' -exec rm -f {} + - -clean-pyc: ## remove Python file artifacts - find . -name '*.pyc' -exec rm -f {} + - find . -name '*.pyo' -exec rm -f {} + - find . -name '*~' -exec rm -f {} + - find . -name '__pycache__' -exec rm -fr {} + - -clean-test: ## remove test and coverage artifacts - rm -fr .tox/ - rm -f .coverage - rm -fr htmlcov/ - rm -fr .pytest_cache - -lint: ## check code with pre-commit - tox -e pre-commit - -test: ## run tests quickly with the default Python - py.test - -test-all: ## run tests on every Python version with tox - tox - -coverage: ## check code coverage quickly with the default Python - coverage run --source hcloud -m pytest - coverage report -m - coverage html - $(BROWSER) htmlcov/index.html - -docs: ## generate Sphinx HTML documentation, including API docs +docs: $(MAKE) -C docs clean $(MAKE) -C docs html - $(BROWSER) docs/_build/html/index.html - -servedocs: docs ## compile the docs watching for changes - watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D . - -release: dist ## package and upload a release - twine upload dist/* - -dist: clean ## builds source and wheel package - python setup.py sdist - python setup.py bdist_wheel - ls -l dist + xdg-open docs/_build/html/index.html -install: clean ## install the package to the active Python's site-packages - python setup.py install +clean: + git clean -xdf diff --git a/docs/conf.py b/docs/conf.py index 549d7cd..b56f284 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # hcloud documentation build configuration file, created by # sphinx-quickstart on Fri Jun 9 13:47:02 2017. diff --git a/pyproject.toml b/pyproject.toml index 9787c3b..3a814f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,10 @@ +[tool.isort] +profile = "black" +combine_as_imports = true + +[tool.coverage.run] +source = ["hcloud"] + [build-system] requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" diff --git a/requirements/base.txt b/requirements/base.txt deleted file mode 100644 index 9c558e3..0000000 --- a/requirements/base.txt +++ /dev/null @@ -1 +0,0 @@ -. diff --git a/requirements/test.txt b/requirements/test.txt deleted file mode 100644 index 3f71ee4..0000000 --- a/requirements/test.txt +++ /dev/null @@ -1,4 +0,0 @@ --r base.txt - -pytest -tox==3.23.1 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 0b67081..0000000 --- a/setup.cfg +++ /dev/null @@ -1,19 +0,0 @@ -[bdist_wheel] -universal = 1 - - -[pep8] -ignore = E501,E722,W503 - -[flake8] -ignore = E501,E722,W503 -exclude = - .git, - docs, - - -[aliases] -test = pytest - -[tool:pytest] -collect_ignore = ['setup.py'] diff --git a/setup.py b/setup.py old mode 100755 new mode 100644 index d6ddfec..8b4c974 --- a/setup.py +++ b/setup.py @@ -1,7 +1,3 @@ -#!/usr/bin/env python - -"""The setup script.""" - from setuptools import find_packages, setup with open("README.rst") as readme_file: @@ -10,17 +6,26 @@ with open("CHANGELOG.rst") as changelog_file: changelog = changelog_file.read() -requirements = ["python-dateutil>=2.7.5", "requests>=2.20"] - -extras_require = {"docs": ["Sphinx==1.8.1", "sphinx-rtd-theme==0.4.2"]} - version = {} with open("hcloud/__version__.py") as fp: exec(fp.read(), version) setup( + name="hcloud", + version=version["VERSION"], + keywords="hcloud hetzner cloud", + description="Official Hetzner Cloud python library", + long_description=readme + "\n\n" + changelog, author="Hetzner Cloud GmbH", author_email="support-cloud@hetzner.com", + url="https://github.com/hetznercloud/hcloud-python", + project_urls={ + "Bug Tracker": "https://github.com/hetznercloud/hcloud-python/issues", + "Documentation": "https://hcloud-python.readthedocs.io/en/stable/", + "Changelog": "https://github.com/hetznercloud/hcloud-python/blob/main/CHANGELOG.md", + "Source Code": "https://github.com/hetznercloud/hcloud-python", + }, + license="MIT license", classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", @@ -34,17 +39,21 @@ "Programming Language :: Python :: 3.11", ], python_requires=">=3.7", - description="Official Hetzner Cloud python library", - install_requires=requirements, - extras_require=extras_require, - license="MIT license", - long_description=readme + "\n\n" + changelog, + install_requires=[ + "python-dateutil>=2.7.5", + "requests>=2.20", + ], + extras_require={ + "docs": [ + "sphinx==1.8.1", + "sphinx-rtd-theme==0.4.2", + ], + "test": [ + "coverage>=7.2.7,<7.3", + "pytest>=7.3.2,<7.4", + ], + }, include_package_data=True, - keywords="hcloud hetzner cloud", - name="hcloud", packages=find_packages(exclude=["examples", "tests*", "docs"]), - test_suite="tests", - url="https://github.com/hetznercloud/hcloud-python", - version=version["VERSION"], zip_safe=False, ) diff --git a/tox.ini b/tox.ini index cae4dcf..191a98d 100644 --- a/tox.ini +++ b/tox.ini @@ -8,7 +8,7 @@ commands = pre-commit run --verbose --all-files --show-diff-on-failure [testenv] passenv = FAKE_API_ENDPOINT deps = - -r{toxinidir}/requirements/test.txt + -e.[test] commands = pytest tests/unit {posargs}