diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3263332 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +# EditorConfig is awesome: https://editorconfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 2 +insert_final_newline = true + +[*.py] +indent_size = 4 + +[Makefile] +indent_style = tab diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 2b0a7de..4aab1bd 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -3,10 +3,9 @@ echo Running pre-commit hook # Run pre-commit, this checks if we changed any files and runs the checks. -# The files are then git-added FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') if [ -n "$FILES" ]; then - if ! make lint >/dev/null 2>&1; then + if ! task lint >/dev/null 2>&1; then echo "Error running make lint - please fix before committing" echo "if this is a mistake you can skip the checks with 'git commit --no-verify'" exit 1 diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 39c1be0..d6106d1 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -21,7 +21,7 @@ jobs: environment: release steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@main with: fetch-depth: 0 @@ -47,13 +47,16 @@ jobs: skipIfReleaseExists: true tag: ${{ env.REVISION }} - - name: Setup Rye - if: env.PREVIOUS_REVISION != env.REVISION - uses: nikaro/actions/setup-rye@main + - name: Install tools + run: | + echo "/home/linuxbrew/.linuxbrew/bin" >> "$GITHUB_PATH" + /home/linuxbrew/.linuxbrew/bin/brew install \ + go-task \ + rye \ - name: Build package if: env.PREVIOUS_REVISION != env.REVISION - run: make build + run: task build --yes - name: Publish package to PyPI if: env.PREVIOUS_REVISION != env.REVISION diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37e6a21..54cc8bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,9 @@ on: workflow_call: workflow_dispatch: +env: + TASK_X_REMOTE_TASKFILES: 1 + jobs: lint: name: Lint @@ -16,7 +19,7 @@ jobs: contents: read steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@main - name: Install tools run: | @@ -24,13 +27,18 @@ jobs: /home/linuxbrew/.linuxbrew/bin/brew install \ actionlint \ check-jsonschema \ - ruff \ + fd \ + go-task \ + jq \ + prettier \ rye \ + shellcheck \ + shfmt \ yamlfmt \ yamllint \ - name: Lint - run: make lint + run: task lint --yes test: name: Test @@ -39,19 +47,23 @@ jobs: contents: read steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@main - name: Install tools run: | echo "/home/linuxbrew/.linuxbrew/bin" >> "$GITHUB_PATH" /home/linuxbrew/.linuxbrew/bin/brew install \ + go-task \ rye \ - name: Install dependencies - run: make sync + run: task sync --yes + + - name: Test + run: task test --yes - name: Test - run: make test + run: task build --yes check: name: Check diff --git a/.gitignore b/.gitignore index 99e4ebd..9cce954 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ wheels/ .venv/ .python-version .sl/ +.task/ diff --git a/Makefile b/Makefile deleted file mode 100644 index 091b06a..0000000 --- a/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -.DEFAULT_GOAL := help - -init: ## Initialize repository - git config core.hooksPath .githooks - git config commit.template .gitmessage - -lock: ## Updates the lockfiles without installing dependencies - rye lock --all-features --update-all - -sync: ## Updates the virtualenv based on the pyproject.toml - rye sync --all-features --no-lock || rye sync --all-features --no-lock --force - -format: ## Run formatters - @echo Formatting... - # YAML - @yamlfmt . - # Python - @rye fmt - -lint: ## Run linters - @echo Linting... - # Renovate - @check-jsonschema --builtin-schema vendor.renovate ./.github/renovate*.json - # GitHub Actions - @check-jsonschema --builtin-schema vendor.github-workflows ./.github/workflows/*.yml - @actionlint - # YAML - @yamlfmt -lint . - @yamllint . - # Python - @rye fmt --check - @rye lint - @rye run type-check - -test: ## Run project test - rye test - -build: ## Build project - rye build - -clean: ## Remove build artifacts - rm -rf ./dist/ - find . -type d -name "__pycache__" | xargs rm -rf - -help: ## Show help message - @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% 0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) - -.PHONY: build format help init lint lock sync test diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..c33bdea --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,83 @@ +version: '3' + +set: [errexit, nounset, pipefail] +shopt: [globstar] + +includes: + lint: + taskfile: https://github.com/nikaro/meta/raw/main/taskfiles/lint.yml + internal: true + format: + taskfile: https://github.com/nikaro/meta/raw/main/taskfiles/format.yml + internal: true + +tasks: + init: + desc: Initialize repositry + cmds: + - git config core.hooksPath .githooks + - git config commit.template .gitmessage + + lock: + desc: Update lockfile + cmd: rye lock --all-features --update-all + + sync: + desc: Synchronize virtualenv with lockfile + cmd: rye sync --all-features --no-lock || rye sync --all-features --no-lock --force + + lint: + desc: Run linters + cmds: + - task: lint:default + - task: lint:python + + lint:python: + desc: Lint Python code + sources: + - ./src/**/*.py + cmds: + - rye fmt --check + - rye lint + - rye run type-check + + format: + desc: Run formatters + cmds: + - task: format:default + - task: format:python + + format:python: + desc: Format Python code + sources: + - ./src/**/*.py + - ./tests/**/*.py + cmds: + - rye fmt + + test: + desc: Run tests + sources: + - ./src/**/*.py + - ./tests/**/*.py + cmd: rye test + + build: + desc: Build project + sources: + - ./src/**/*.py + - ./tests/**/*.py + - ./pyproject.toml + - ./requirements.lock + generates: + - ./dist/*.whl + - ./dist/*.tar.gz + cmd: rye build + + clean: + desc: Cleanup workspace + cmds: + - rm -rf ./dist/ + - rm -rf ./.ruff_cache/ + - rm -rf ./.pytest_cache/ + - fd --type directory --no-ignore __pycache__ | xargs rm -rf