diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 39abab7c..00000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,19 +0,0 @@ -# Description - -Please include a summary of the changes and a link/description of the related issue. -Please also include relevant motivation and context. - - -# Has This Been Tested? - -Please describe the tests that you ran to verify your changes. Provide instructions to reproduce. - -Please also list any relevant details for your test configuration - - -# Checklist: - -- [ ] I've read the [contributing guidelines](https://juftin.com/lunchable/contributing) of this project -- [ ] I've installed and used `.pre_commit` on all my code -- [ ] I have documented my code, particularly in hard-to-understand areas -- [ ] I have made any necessary corresponding changes to the documentation diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 5cc44ffc..2907657e 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -10,35 +10,34 @@ on: - Dockerfile jobs: docker-ci-test: - runs-on: ubuntu-latest - steps: - - name: Set up Github Workspace - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - name: Install Hatch - run: | - python -m pip install --upgrade pip - python -m pip install -q hatch - hatch -v env create - hatch --version - - name: Declare Version Variable - run: | - PACKAGE_VERSION=$(hatch version) - PACKAGE_NAME=$(hatch project metadata | jq -r .name) - echo PACKAGE_VERSION=${PACKAGE_VERSION} >> $GITHUB_ENV - echo PACKAGE_NAME=${PACKAGE_NAME} >> $GITHUB_ENV - - name: Docker Image Building and Publishing - id: docker_build - uses: docker/build-push-action@v3 - with: - push: false - tags: juftin/${{ env.PACKAGE_NAME }}:latest + runs-on: ubuntu-latest + steps: + - name: Set up Github Workspace + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + - name: Install Hatch + run: | + python -m pip install -q --upgrade pip wheel + python -m pip install -q hatch pre-commit + hatch --version + - name: Declare Version Variable + run: | + PACKAGE_VERSION=$(hatch version) + PACKAGE_NAME=$(hatch project metadata | jq -r .name) + echo PACKAGE_VERSION=${PACKAGE_VERSION} >> $GITHUB_ENV + echo PACKAGE_NAME=${PACKAGE_NAME} >> $GITHUB_ENV + - name: Docker Image Building and Publishing + id: docker_build + uses: docker/build-push-action@v5 + with: + push: false + tags: juftin/${{ env.PACKAGE_NAME }}:latest diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 62e3441b..27d62785 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -9,37 +9,36 @@ jobs: runs-on: ubuntu-latest steps: - name: Set up Github Workspace - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Set up Python Environment 3.11 - uses: actions/setup-python@v4 + - name: Set up Python Environment + uses: actions/setup-python@v5 with: python-version: '3.11' - name: Install Hatch run: | - python -m pip install --upgrade pip - python -m pip install -q hatch - hatch -v env create + python -m pip install --upgrade pip wheel + python -m pip install -q hatch pre-commit hatch --version - name: Lint id: lint continue-on-error: true run: | - echo "::add-matcher::.github/matchers/flake8.json" - hatch run lint + echo "::add-matcher::.github/workflows/matchers/flake8.json" + hatch run lint:style echo "::remove-matcher owner=flake8::" - - name: Code Checker + - name: Type Checking id: check continue-on-error: true run: | - echo "::add-matcher::.github/matchers/mypy.json" - hatch run check + echo "::add-matcher::.github/workflows/matchers/mypy.json" + hatch run lint:typing echo "::remove-matcher owner=mypy::" - - name: Raise Errors For Linting Failures + - name: Raise Errors For Failures if: | steps.lint.outcome != 'success' || - steps.check.outcome != 'success' + steps.check.outcome != 'success' run: | echo "Lint: ${{ steps.lint.outcome }}" echo "Check: ${{ steps.check.outcome }}" diff --git a/.github/matchers/flake8.json b/.github/workflows/matchers/flake8.json similarity index 100% rename from .github/matchers/flake8.json rename to .github/workflows/matchers/flake8.json diff --git a/.github/matchers/mypy.json b/.github/workflows/matchers/mypy.json similarity index 100% rename from .github/matchers/mypy.json rename to .github/workflows/matchers/mypy.json diff --git a/.github/matchers/python.json b/.github/workflows/matchers/python.json similarity index 100% rename from .github/matchers/python.json rename to .github/workflows/matchers/python.json diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index bf50bb49..f8246408 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -12,24 +12,23 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out the repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 2 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.11' - name: Install Hatch run: | python -m pip install --upgrade pip - python -m pip install -q hatch - hatch -v env create + python -m pip install -q hatch pre-commit hatch --version - name: Build package run: | hatch build - name: Publish package on PyPI - uses: pypa/gh-action-pypi-publish@v1.8.6 + uses: pypa/gh-action-pypi-publish@v1.8.11 with: user: __token__ password: ${{ secrets.PYPI_TOKEN }} @@ -40,23 +39,22 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out the repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 2 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.11' - name: Install Hatch run: | - python -m pip install --upgrade pip - python -m pip install -q hatch - hatch -v env create + python -m pip install -q --upgrade pip wheel + python -m pip install -q hatch pre-commit hatch --version - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v3 - name: Login to DockerHub uses: docker/login-action@v2 with: @@ -70,7 +68,7 @@ jobs: echo PACKAGE_NAME=${PACKAGE_NAME} >> $GITHUB_ENV - name: Docker Image Building and Publishing id: docker_build - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5 with: push: true tags: juftin/${{ env.PACKAGE_NAME }}:latest,juftin/${{ env.PACKAGE_NAME }}:${{ env.PACKAGE_VERSION }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9946807f..b1e017f0 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -7,23 +7,28 @@ jobs: name: Release if: github.repository_owner == 'juftin' runs-on: ubuntu-latest + permissions: + contents: write + issues: write + pull-requests: write steps: - - name: Checkout - uses: actions/checkout@v3 + - name: Check out the repository + uses: actions/checkout@v4 + with: + fetch-depth: 2 - name: Setup Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.11' - name: Install Hatch run: | python -m pip install --upgrade pip - python -m pip install -q hatch - hatch -v env create + python -m pip install -q hatch pre-commit hatch --version - name: Release - run: hatch run semantic-release + run: hatch run gen:release env: GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} GIT_AUTHOR_NAME: github-actions[bot] @@ -49,13 +54,13 @@ jobs: git push --set-upstream origin gh-pages || true git checkout main -- - name: Checkout gh-pages Branch - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: ${{ github.workspace }}/github-pages ref: gh-pages fetch-depth: 0 - name: Set up Python Environment - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.11' - name: Install Hatch @@ -63,12 +68,11 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install -q hatch - hatch -v env create hatch --version - name: Documentation Generation working-directory: ${{ github.workspace }}/main run: | - hatch run docs-build + hatch run docs:build - name: Setup Git Config run: | git config --global user.name "github-actions[bot]" diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a3f08c3e..4b4252de 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -28,24 +28,27 @@ jobs: - {name: Python 3.10, python: '3.10'} - {name: Python 3.9, python: '3.9'} - {name: Python 3.8, python: '3.8'} + concurrency: + group: ${{ github.workflow }}-${{ matrix.python }}-${{ github.ref }} + cancel-in-progress: true steps: - name: Set up Github Workspace - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Python Environment ${{ matrix.python }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} - name: Install Hatch run: | - python -m pip install --upgrade pip - python -m pip install -q hatch + python -m pip install -q --upgrade pip wheel + python -m pip install -q hatch pre-commit hatch --version - name: Test Suite run: | - echo "::add-matcher::.github/matchers/python.json" - hatch run +py=${{ matrix.python }} test:test + echo "::add-matcher::.github/workflows/matchers/python.json" + hatch run +py=${{ matrix.python }} all:cov echo "::remove-matcher owner=python::" env: VCR_RECORD_MODE: none diff --git a/.gitignore b/.gitignore index 4d240bcf..29d7d906 100644 --- a/.gitignore +++ b/.gitignore @@ -104,7 +104,7 @@ celerybeat.pid *.sage.py # Environments -*.env +.env .venv env/ venv/ @@ -133,13 +133,9 @@ dmypy.json # IDE Files .idea/ -/env.bash -# NodeJS +# Node.js node_modules/ # Lunchable Data lunchable/data/ - -# Requirements Files -requirements/*.bak diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6b72433f..8bd7f737 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,13 +40,13 @@ repos: - id: format name: format description: Runs Code Auto-Formatters - entry: hatch run format + entry: hatch run lint:fmt language: system pass_filenames: false - id: lint name: lint description: Runs Code Linters - entry: hatch run format + entry: hatch run lint:style language: system pass_filenames: false require_serial: false diff --git a/.releaserc.js b/.releaserc.js deleted file mode 100644 index 524ef6dc..00000000 --- a/.releaserc.js +++ /dev/null @@ -1,61 +0,0 @@ -const path = require("path"); -const fs = require("fs"); - -const semantic_release_dir = path.resolve(__dirname, ".github/semantic_release"); -const release_note_path = path.join(semantic_release_dir, "release_notes.hbs"); -const release_note_template = fs.readFileSync(release_note_path, "utf-8"); - -module.exports = { - branches: [ - "main", - "master", - "next", - "next-major", - "+([0-9])?(.{+([0-9]),x}).x", - { - name: "beta", - prerelease: true, - }, - { - name: "alpha", - prerelease: true, - }, - ], - plugins: [ - [ - "semantic-release-gitmoji", - { - releaseNotes: { - template: release_note_template, - }, - }, - ], - [ - "@semantic-release/exec", - { - prepareCmd: "hatch version ${nextRelease.version} && hatch build", - }, - ], - [ - "@semantic-release/git", - { - assets: ["pyproject.toml", "*/_version.py"], - message: - "๐Ÿ”– lunchable ${nextRelease.version}\n\n${nextRelease.notes}\n[skip ci]", - }, - ], - [ - "@semantic-release/github", - { - assets: [ - { - path: "dist/*.whl", - }, - { - path: "dist/*.tar.gz", - }, - ], - }, - ], - ], -}; diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 00000000..76124b14 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,46 @@ +{ + "branches": [ + "main", + "master", + "next", + "next-major", + "+([0-9])?(.{+([0-9]),x}).x", + { + "name": "beta", + "prerelease": true + }, + { + "name": "alpha", + "prerelease": true + } + ], + "plugins": [ + "semantic-release-gitmoji", + [ + "@semantic-release/exec", + { + "prepareCmd": "hatch version ${nextRelease.version} && hatch build" + } + ], + [ + "@semantic-release/git", + { + "assets": ["pyproject.toml", "*/__about__.py"], + "message": "๐Ÿ”– lunchable ${nextRelease.version}\n\n${nextRelease.notes}\n[skip ci]" + } + ], + [ + "@semantic-release/github", + { + "assets": [ + { + "path": "dist/*.whl" + }, + { + "path": "dist/*.tar.gz" + } + ] + } + ] + ] +} diff --git a/Dockerfile b/Dockerfile index 0f7584bc..52f44e10 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,15 +3,17 @@ FROM ${BASE_IMAGE:-python:3.11-slim} MAINTAINER Justin Flannery "juftin@juftin.com" -RUN python -m pip install --upgrade pip -COPY pyproject.toml README.md /tmp/lunchable/ -COPY lunchable/ /tmp/lunchable/lunchable/ -COPY requirements/requirements-prod.txt /tmp/lunchable/requirements.txt -RUN pip install -r /tmp/lunchable/requirements.txt -RUN pip install /tmp/lunchable/[all] && rm -rf /tmp/lunchable - RUN apt-get update && apt-get install -y jq && apt-get clean +COPY requirements.txt /tmp/project/requirements.txt +COPY README.md /tmp/project/README.md +COPY pyproject.toml /tmp/project/pyproject.toml +COPY lunchable /tmp/project/lunchable + +RUN pip install -r /tmp/project/requirements.txt +RUN pip install /tmp/project && \ + rm -rf /tmp/project + SHELL ["/bin/bash", "-c"] RUN _LUNCHABLE_COMPLETE=bash_source lunchable > ${HOME}/.lunchable-complete.bash && \ diff --git a/docs/source/contributing.md b/docs/source/contributing.md index cbf55ac7..608ce697 100644 --- a/docs/source/contributing.md +++ b/docs/source/contributing.md @@ -1,65 +1,79 @@ # Contributing -## Quickstart - -```shell -pipx install pre-commit -pipx install hatch -pre-commit install -hatch env create -hatch shell -``` +## Environment Setup -## Tools +1. Install [hatch](https://github.com/pypa/hatch) -This project makes use of a couple tools to streamline the development process: -[pre-commit](https://pre-commit.com/) and [hatch](https://hatch.pypa.io/). + ```shell + pipx install hatch + ``` -### pre-commit +2. Build the Virtual Environment -[pre-commit] is a tool to manage git-hooks scripts, which are useful -for identifying simple issues before submission to code review. + ```shell + hatch env create + ``` -```commandline -pipx install pre-commit -pre-commit install -``` +3. If you need to, you can link a hatch virtual environment to your IDE. + They can be located by name with the `env find` command: -To use pre-commit, you must first install it. [pipx] is preferred, but you can also install with -`pip`. Once [pre-commit] is installed, run `pre-commit install` to install the git-hooks scripts -into the local repository. Done, now pre-commit will run automatically on git commit. To run it -manually on your changed files run `pre-commit run` on your command line. + ```shell + hatch env find default + ``` -### hatch +4. Activate the Virtual Environment -[hatch](https://hatch.pypa.io/) is a tool to manage the packaging and distribution of Python packages. It also -used to manage the virtual environment for the project and running common scripts. + ```shell + hatch shell + ``` -```commandline -pipx install hatch -hatch env create -hatch run test -``` +## Using Hatch + +### Hatch Cheat Sheet + +| Command Description | Command | Notes | +| ------------------------------ | --------------------------- | ---------------------------------------------------------- | +| Run Tests | `hatch run cov` | Runs tests with `pytest` and `coverage` | +| Run Formatting | `hatch run lint:fmt` | Runs `ruff` code formatter | +| Run Linting | `hatch run lint:all` | Runs `ruff` and `mypy` linters / type checkers | +| Run Type Checking | `hatch run lint:typing` | Runs `mypy` type checker | +| Serve the Documentation | `hatch run docs:serve` | Serve the documentation using MkDocs | +| Run the `pre-commit` Hooks | `hatch run lint:precommit` | Runs the `pre-commit` hooks on all files | + +### Hatch Explanation + +Hatch is a Python package manager. It's most basic use is as a standardized build-system. +However, hatch also has some extra features which this project takes advantage of. +These features include virtual environment management and the organization of common +scripts like linting and testing. All the operations in hatch take place in one +of its managed virtual environments. + +## Committing Code -## Commit Message Format +This project uses [pre-commit] to run a set of +checks on the code before it is committed. The pre-commit hooks are +installed by hatch automatically when you run it for the first time. -Releases for this project are handled entirely by CI/CD via Pull requests being merged into -the `main` branch. Contributions follow the [gitmoji] standards with [conventional commits], -orchestration is handled by the [semantic-release] tool. +This project uses [semantic-versioning] standards, managed by [semantic-release]. +Releases for this project are handled entirely by CI/CD via pull requests being +merged into the `main` branch. Contributions follow the [gitmoji] standards +with [conventional commits]. -While you can denote other changes on your commit messages with gitmoji, the following +While you can denote other changes on your commit messages with [gitmoji], the following commit message emoji prefixes are the only ones to trigger new releases: -| Emoji | Shortcode | Description | Semver | -| ----- | ----------- | --------------------------- | ------ | -| ๐Ÿ’ฅ | :boom: | Introduce breaking changes. | Major | -| โœจ | :sparkles: | Introduce new features. | Minor | -| ๐Ÿ› | :bug: | Fix a bug. | Patch | -| ๐Ÿš‘ | :ambulance: | Critical hotfix. | Patch | -| ๐Ÿ”’ | :lock: | Fix security issues. | Patch | +| Emoji | Shortcode | Description | Semver | +| ----- | ------------- | --------------------------- | ------ | +| ๐Ÿ’ฅ | \:boom\: | Introduce breaking changes. | Major | +| โœจ | \:sparkles\: | Introduce new features. | Minor | +| ๐Ÿ› | \:bug\: | Fix a bug. | Patch | +| ๐Ÿš‘ | \:ambulance\: | Critical hotfix. | Patch | +| ๐Ÿ”’ | \:lock\: | Fix security issues. | Patch | -Most features can be squash merged into a single commit. If you're working on a -feature, your commit message might look like: +Most features can be squash merged into a single commit on a pull-request. +When merging multiple commits, they will be summarized into a single release. + +If you're working on a new feature, your commit message might look like: ```text โœจ New Feature Description @@ -71,43 +85,43 @@ Bug fix commits would look like this: ๐Ÿ› Bug Fix Description ``` -## Scripts +If you're working on a feature that introduces breaking changes, your +commit message might look like: + +```text +๐Ÿ’ฅ Breaking Change Description +``` -All common scripts for this repository are managed by [hatch](#hatch). +Other commits that don't trigger a release might look like this: -```shell -hatch run