From b110eea5992b57b0e84e1b350119b49230e6f574 Mon Sep 17 00:00:00 2001 From: Justin Flannery Date: Sat, 6 Jan 2024 11:44:49 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Python=203.12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #310 --- .github/dependabot.yaml | 8 - .github/workflows/docker.yaml | 17 +- .github/workflows/lint.yaml | 21 +- .github/{ => workflows}/matchers/flake8.json | 0 .github/{ => workflows}/matchers/mypy.json | 0 .github/{ => workflows}/matchers/python.json | 0 .github/workflows/publish.yaml | 28 +- .github/workflows/release.yaml | 37 +- .github/workflows/tests.yaml | 13 +- .pre-commit-config.yaml | 5 +- .releaserc.js | 61 - .releaserc.json | 46 + Dockerfile | 18 +- docs/contributing.md | 222 ++-- mkdocs.yml | 6 + pyproject.toml | 167 +-- requirements.txt | 118 ++ requirements/requirements-all.py3.10.txt | 172 +++ requirements/requirements-all.py3.11.txt | 166 +++ requirements/requirements-all.py3.12.txt | 166 +++ requirements/requirements-all.py3.8.txt | 183 +++ requirements/requirements-all.py3.9.txt | 182 +++ requirements/requirements-dev.txt | 1103 ------------------ requirements/requirements-docs.txt | 233 ++++ requirements/requirements-lint.txt | 15 + requirements/requirements-prod.txt | 376 ------ requirements/requirements-test.txt | 228 ++++ 27 files changed, 1836 insertions(+), 1755 deletions(-) rename .github/{ => workflows}/matchers/flake8.json (100%) rename .github/{ => workflows}/matchers/mypy.json (100%) rename .github/{ => workflows}/matchers/python.json (100%) delete mode 100644 .releaserc.js create mode 100644 .releaserc.json create mode 100644 requirements.txt create mode 100644 requirements/requirements-all.py3.10.txt create mode 100644 requirements/requirements-all.py3.11.txt create mode 100644 requirements/requirements-all.py3.12.txt create mode 100644 requirements/requirements-all.py3.8.txt create mode 100644 requirements/requirements-all.py3.9.txt delete mode 100644 requirements/requirements-dev.txt create mode 100644 requirements/requirements-docs.txt create mode 100644 requirements/requirements-lint.txt delete mode 100644 requirements/requirements-prod.txt create mode 100644 requirements/requirements-test.txt diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml index 41b1ef1f..94236e81 100644 --- a/.github/dependabot.yaml +++ b/.github/dependabot.yaml @@ -4,20 +4,14 @@ updates: directory: / schedule: interval: monthly - labels: - - dependencies - package-ecosystem: pip directory: /.github/workflows schedule: interval: monthly - labels: - - dependencies - package-ecosystem: pip directory: /docs schedule: interval: monthly - labels: - - dependencies - package-ecosystem: pip directory: / schedule: @@ -25,5 +19,3 @@ updates: versioning-strategy: lockfile-only allow: - dependency-type: all - labels: - - dependencies diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index a362ce85..115b8877 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -16,22 +16,21 @@ 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 QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: - python-version: "3.9" + python-version: "3.11" - name: Install Hatch run: | - python -m pip install --upgrade pip - python -m pip install -q hatch - hatch env create + python -m pip install -q --upgrade pip wheel + python -m pip install -q hatch pre-commit hatch --version - name: Declare Version Variable run: | @@ -41,7 +40,7 @@ jobs: echo PACKAGE_NAME=${PACKAGE_NAME} >> $GITHUB_ENV - name: Docker Image Building and Publishing id: docker_build - uses: docker/build-push-action@v3 + 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 5073e4af..e492bb91 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -11,32 +11,31 @@ 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.10 - uses: actions/setup-python@v4 + - name: Set up Python Environment + uses: actions/setup-python@v5 with: - python-version: "3.9" + python-version: "3.11" - name: Install Hatch run: | - python -m pip install --upgrade pip - python -m pip install -q hatch - hatch 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 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 if: | 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 aa8bd85a..6324238e 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -13,24 +13,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.9" + python-version: "3.11" - name: Install Hatch run: | python -m pip install --upgrade pip - python -m pip install -q hatch - hatch 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 }} @@ -41,23 +40,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.9" + python-version: "3.11" - name: Install Hatch run: | - python -m pip install --upgrade pip - python -m pip install -q hatch - hatch 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: @@ -71,7 +69,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 9f0714cf..63b4557f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -9,23 +9,30 @@ 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 + ref: main - 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.9" + python-version: "3.11" - name: Install Hatch run: | python -m pip install --upgrade pip - python -m pip install -q hatch - hatch env create + python -m pip install -q hatch pre-commit + hatch -v env create 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] @@ -41,23 +48,23 @@ jobs: contents: write steps: - name: Checkout Latest Changes - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.ref }} fetch-depth: 0 - name: Set up Python Environment - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: - python-version: "3.9" + python-version: "3.11" - name: Install Hatch run: | - python -m pip install --upgrade pip - python -m pip install -q hatch - hatch env create + python -m pip install --upgrade pip wheel + python -m pip install -q hatch pre-commit + hatch env create docs hatch --version - name: Set Up GitHub Actions User run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - name: Deploy Documentation Changes - run: hatch run docs-deploy --force + run: hatch run docs:gh-deploy --force diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 3d30514c..90a19038 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -27,6 +27,7 @@ jobs: fail-fast: true matrix: include: + - { name: Python 3.12, python: "3.12" } - { name: Python 3.11, python: "3.11" } - { name: Python 3.10, python: "3.10" } - { name: Python 3.9, python: "3.9" } @@ -35,20 +36,20 @@ jobs: CAMPLY_LOG_HANDLER: PYTHON 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:matrix + echo "::add-matcher::.github/workflows/matchers/python.json" + hatch run +py=${{ matrix.python }} all:cov echo "::remove-matcher owner=python::" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 78697ec0..60170c65 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,6 +12,7 @@ repos: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml + exclude: mkdocs.yml - id: check-ast - id: check-docstring-first - id: check-merge-conflict @@ -42,13 +43,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 db22972e..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: - "๐Ÿ”– camply ${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..135310a6 --- /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": "๐Ÿ”– camply ${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 9bf0c5e4..c707e6be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,17 @@ -FROM python:3.9-slim - -COPY pyproject.toml /tmp/camply/pyproject.toml -COPY README.md /tmp/camply/README.md -COPY camply/ /tmp/camply/camply/ +FROM python:3.11-slim MAINTAINER Justin Flannery LABEL description="camply, the campsite finder" -COPY requirements/requirements-prod.txt /tmp/camply/requirements.txt +COPY requirements.txt /tmp/project/requirements.txt +RUN pip install -r /tmp/project/requirements.txt + +COPY README.md /tmp/project/README.md +COPY pyproject.toml /tmp/project/pyproject.toml +COPY camply /tmp/project/camply -RUN python -m pip install -r /tmp/camply/requirements.txt && \ - python -m pip install /tmp/camply --no-dependencies && \ - rm -rf /tmp/camply/ +RUN pip install /tmp/project && \ + rm -rf /tmp/project ENV HOME=/home/camply RUN mkdir ${HOME} diff --git a/docs/contributing.md b/docs/contributing.md index b85904f9..85b02f27 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -1,65 +1,143 @@ # Contributing -## Quickstart - -```shell -pipx install pre-commit -pipx install hatch -pre-commit install -hatch env create -hatch shell +## Environment Setup + +> TIP: **pipx** +> +> This documentaion uses [pipx] to +> install and manage non-project command line tools like `hatch` and +> `pre-commit`. If you don't already have `pipx` installed, make sure to +> see their [documentation](https://pypa.github.io/pipx/installation/). +> If you prefer not to use `pipx`, you can use `pip` instead. + +1. Install [hatch](https://hatch.pypa.io/latest/) + + ```shell + pipx install hatch + ``` + + > NOTE: **pre-commit** + > + > Hatch will attempt to set up pre-commit hooks for you using + > [pre-commit]. If you don't already, + > make sure to install pre-commit as well: `pipx install pre-commit` + +2. Build the Virtual Environment + + ```shell + hatch env create + ``` + +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: + + ```shell + hatch env find test + ``` + +4. Activate the Virtual Environment + + ```shell + hatch shell + ``` + +## 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 | +| Update Requirements Lock Files | `hatch run gen:reqs` | Updating lock file using `pip-compile` | +| Upgrade Dependencies | `hatch run gen:reqs-update` | Updating lock file using `pip-compile` and `--update` flag | +| 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. Its 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. + +Hatch has a variety of environments, to see them simply ask hatch: + +```bash exec="on" result="markdown" source="tabbed-left" tabs="hatch CLI|Output" +hatch env show ``` -## Tools +That above command will tell you that there are five environments that +you can use: + +- `default` +- `docs` +- `gen` +- `lint` +- `test` + +Each of these environments has a set of commands that you can run. +To see the commands for a specific environment, run: -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/). +```bash exec="on" result="markdown" source="tabbed-left" tabs="hatch CLI|Output" +hatch env show default +``` + +Here we can see that the `default` environment has the following commands: -### pre-commit +- `cov` +- `test` -[pre-commit] is a tool to manage git-hooks scripts, which are useful -for identifying simple issues before submission to code review. +The one that we're interested in is `cov`, which will run the tests +for the project. -```commandline -pipx install pre-commit -pre-commit install +```bash +hatch run cov ``` -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. +Since `cov` is in the default environment, we can run it without +specifying the environment. However, to run the `serve` command in the +`docs` environment, we need to specify the environment: -### hatch +```bash +hatch run docs:serve +``` -[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. +You can see what scripts are available using the `env show` command -```commandline -pipx install hatch -hatch env create -hatch run test +```bash exec="on" result="markdown" source="tabbed-left" tabs="hatch CLI|Output" +hatch env show docs ``` -## Commit Message Format +## Committing Code + +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,49 +149,43 @@ Bug fix commits would look like this: ๐Ÿ› Bug Fix Description ``` -## Scripts - -All common scripts for this repository are managed by [hatch](#hatch). +If you're working on a feature that introduces breaking changes, your +commit message might look like: -```shell -hatch run