diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b3330f8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# https://editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[Makefile] +indent_style = tab + +[*.{yml,yaml}] +indent_size = 2 diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 565f1bf..f2f5e93 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -1,122 +1,88 @@ name: Python -on: - push: +on: [push] jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.10", "3.11", "3.12"] - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Build project - run: make build - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: dist-${{ matrix.python-version }} - path: dist - test: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.10", "3.11", "3.12"] - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Test project - run: make test - mypy: + pre-commit: runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.10", "3.11", "3.12"] steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Run mypy - run: make mypy - flake8: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.13 + - name: Install pre-commit + run: pip install pre-commit + - name: Run pre-commit 'manual' hooks + run: pre-commit run --color=always + --all-files + --hook-stage manual + --show-diff-on-failure + --verbose + build: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.10", "3.11", "3.12"] + python-version: ["3.11", "3.12", "3.13"] steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Run flake8 - run: make flake8 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Build project + run: make build + - uses: actions/upload-artifact@v4 + with: + name: dist-${{ matrix.python-version }} + path: dist run: needs: [build] runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.10", "3.11", "3.12"] + python-version: ["3.11", "3.12", "3.13"] steps: - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - name: dist-${{ matrix.python-version }} - - name: Install package - run: pip install *.whl - - name: Run package - run: python -m template + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: dist-${{ matrix.python-version }} + - name: Install package + run: pip install *.whl + - name: Run project + run: python -m template run-windows: needs: [build] runs-on: windows-latest strategy: matrix: - python-version: ["3.10", "3.11", "3.12"] + python-version: ["3.11", "3.12", "3.13"] steps: - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - name: dist-${{ matrix.python-version }} - - name: Install package - run: pip install (get-item .\*.whl) - - name: Run package - run: python -m template + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: dist-${{ matrix.python-version }} + - name: Install package + run: pip install (get-item .\*.whl) + - name: Run package + run: python -m template run-macos: needs: [build] runs-on: macos-latest strategy: matrix: - python-version: ["3.10", "3.11", "3.12"] + python-version: ["3.11", "3.12", "3.13"] steps: - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - name: dist-${{ matrix.python-version }} - - name: Install package - run: pip install *.whl - - name: Run package - run: python -m template + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: dist-${{ matrix.python-version }} + - name: Install package + run: pip install *.whl + - name: Run package + run: python -m template diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 34c95f5..906f5c5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,30 +1,30 @@ default: - image: ubuntu:latest - before_script: | - apt-get update - apt-get install -y python3-venv make + image: alpine:latest + before_script: apk add python3 make build: stage: build script: make build artifacts: paths: - - dist/ - -test: - stage: test - script: make test - needs: [] -mypy: - stage: test - script: make mypy - needs: [] -flake8: + - dist/ +pre-commit: + image: python:latest stage: test - script: make flake8 needs: [] + variables: + PRE_COMMIT_HOME: ${CI_PROJECT_DIR}/.cache/pre-commit + cache: + key: pre-commit + paths: ["${PRE_COMMIT_HOME}"] + before_script: pip install pre-commit + script: pre-commit run --color=always + --all-files + --hook-stage manual + --show-diff-on-failure + --verbose install: stage: test script: - - python3 -m venv .venv - - .venv/bin/pip install dist/*.whl + - python3 -m venv .venv + - .venv/bin/pip install dist/*.whl diff --git a/.gitlint b/.gitlint new file mode 100644 index 0000000..3070793 --- /dev/null +++ b/.gitlint @@ -0,0 +1,15 @@ +[general] +ignore=body-is-missing +verbosity=3 + +[title-max-length] +line-length=80 + +[title-min-length] +min-length=5 + +[body-max-line-length] +line-length=120 + +[body-min-length] +min-length=5 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..3adceb5 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,82 @@ +default_install_hook_types: [commit-msg, pre-commit, pre-merge-commit, pre-push] +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-added-large-files + args: [--maxkb=100] + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-illegal-windows-names + - id: check-json + - id: check-merge-conflict + - id: check-shebang-scripts-are-executable + - id: check-symlinks + - id: check-toml + - id: check-xml + - id: check-yaml + - id: destroyed-symlinks + - id: detect-private-key + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: mixed-line-ending + args: [--fix=lf] + - id: name-tests-test + - id: pretty-format-json + args: [--autofix, --ident=4, --no-sort-keys] + - id: requirements-txt-fixer + - id: trailing-whitespace + args: [--markdown-linebreak-ext=md] +- repo: https://github.com/asottile/pyupgrade + rev: v3.19.0 + hooks: + - id: pyupgrade +- repo: https://github.com/editorconfig-checker/editorconfig-checker.python + rev: 3.0.3 + hooks: + - id: editorconfig-checker +- repo: https://github.com/jorisroovers/gitlint + rev: v0.19.1 + hooks: + - id: gitlint + - id: gitlint-ci +- repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.43.0 + hooks: + - id: markdownlint +- repo: https://github.com/adrienverge/yamllint + rev: v1.35.1 + hooks: + - id: yamllint +- repo: https://github.com/rstcheck/rstcheck + rev: v6.2.4 + hooks: + - id: rstcheck +- repo: https://github.com/psf/black + rev: 24.10.0 + hooks: + - id: black + args: [--line-length=79] +- repo: https://github.com/PyCQA/isort + rev: 5.13.2 + hooks: + - id: isort + args: [--filter-files, --profile=black, --verbose, --color, --jobs=-1] +- repo: https://github.com/pycqa/flake8 + rev: 7.1.1 + hooks: + - id: flake8 + args: [--ignore=E203, --color=always] # spacing around ':' slicing-syntax +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.13.0 + hooks: + - id: mypy + args: [--strict, --show-error-context, --pretty] +- repo: local + hooks: + - id: pytest + name: pytest + entry: make test + language: system + pass_filenames: false + types: [python] diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000..5fe5547 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,16 @@ +extends: default +rules: + document-end: + present: false + document-start: + present: false + indentation: + spaces: 2 + indent-sequences: false + key-duplicates: {} + line-length: + max: 80 + level: warning + quoted-strings: + required: only-when-needed + trailing-spaces: {} diff --git a/Makefile b/Makefile index 7fcd5aa..ec30754 100644 --- a/Makefile +++ b/Makefile @@ -1,39 +1,22 @@ -VENV := venv +VENV := .venv PY := python3 -override VENV_OK := $(VENV)/bin/activate override PYTHON := $(VENV)/bin/python3 -override PIP := $(VENV)/bin/pip -override MYPY := $(VENV)/bin/mypy -override FLAKE8 := $(VENV)/bin/flake8 -.PHONY: build install uninstall run test mypy flake8 clean +.PHONY: build test -$(VENV_OK): requirements.txt pyproject.toml +$(VENV): pyproject.toml $(PY) -m venv $(VENV) - $(PIP) install -r $< + $(PYTHON) -m pip install -e .[dev] -dist/: $(VENV_OK) src/ README.* LICENSE +$(VENV)/bin/build: $(VENV) + $(PYTHON) -m pip install build +dist/: $(VENV)/bin/build src/ README.* LICENSE rm -rf dist $(PYTHON) -m build build: dist/ -install: build - $(PY) -m pip install --user dist/*.whl - -uninstall: - $(PY) -m pip uninstall template - -run: $(VENV_OK) - $(PYTHON) -m template - -test: $(VENV_OK) - $(PYTHON) -m unittest discover -v -s tests -t . - -mypy: $(VENV_OK) - $(MYPY) --strict src tests - -flake8: $(VENV_OK) - $(FLAKE8) src tests +test: $(VENV) + $(PYTHON) -m pytest --color=yes tests clean: find . -name __pycache__ -exec rm -rf {} + diff --git a/pyproject.toml b/pyproject.toml index 3ed53a0..5444c9d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,12 +10,12 @@ authors = [{ name = "GereonV", email = "72784429+GereonV@users.noreply.github.co # maintainers # keywords classifiers = [ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "License :: OSI Approved :: The Unlicense (Unlicense)", - "Operating System :: OS Independent", - "Programming Language :: Python :: 3.10", - "Topic :: Software Development", + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "License :: OSI Approved :: The Unlicense (Unlicense)", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3.10", + "Topic :: Software Development", ] urls.Homepage = "https://github.com/GereonV/templates" # urls.Documentation = "https://readthedocs.org" @@ -25,5 +25,5 @@ urls.Issues = "https://github.com/GereonV/templates/issues" # Entry points scripts = { template = "template:main" } dependencies = [] -# optional-dependencies +optional-dependencies.dev = ["pytest"] dynamic = [] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 1d4503e..0000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -build -mypy -flake8 --e . diff --git a/src/template/__init__.py b/src/template/__init__.py index 3e2e83a..f3b5a00 100644 --- a/src/template/__init__.py +++ b/src/template/__init__.py @@ -6,9 +6,7 @@ # def invoke[**Ts, R](...): ... def invoke( - f: typing.Callable[Ts, R], - *args: Ts.args, - **kwargs: Ts.kwargs + f: typing.Callable[Ts, R], *args: Ts.args, **kwargs: Ts.kwargs ) -> R: return f(*args, **kwargs) diff --git a/src/template/__main__.py b/src/template/__main__.py index 6cae476..1be9f8d 100644 --- a/src/template/__main__.py +++ b/src/template/__main__.py @@ -1,2 +1,3 @@ from template import main + main()