From 8ba3ef40ed2caabecd39f295a4568f84a4fd3319 Mon Sep 17 00:00:00 2001 From: Colin Taylor Date: Thu, 28 Dec 2023 14:51:28 -0500 Subject: [PATCH] Add prettier for non-python formatting Adding prettier for consistent formatting of non-python files. Ruff format only applies to python files, however, other files in the repo still have similar concerns (consistency, whitespace thrashing, etc). Prettier addresses this concern in the same way as ruff; minimal configurability to prevent bikeshedding. All non-conformant files have been formatted to pass the pre-commit hook. Very few changes were needed; several yaml files were modified to have consistent whitespace and indentation, including the pre-commit configuration file. Modern text editors and IDEs (efficiently) support prettier via plugin; this is recommended for local formatting. A cli tool is available, however, prettier itself is written in javascript so it is only accessible via npm/yarn (`npx prettier`/`yarn dlx prettier`). While this is unfortunate, there are very few tools that format general source files, and none within the python ecosystem. Pre-commit does address this capability gap indirectly. It can be run via `pre-commit run prettier`, either with the `--all-files` flag or by adding a modified file to your working tree. While suboptimal, this does allow local formatting/validation if needed. --- .github/workflows/publish.yml | 52 ++++++------ .github/workflows/test.yml | 150 +++++++++++++++++----------------- .pre-commit-config.yaml | 13 ++- .prettierignore | 16 ++++ .prettierrc.toml | 4 + .readthedocs.yml | 8 +- docs/versionhistory.rst | 5 ++ 7 files changed, 139 insertions(+), 109 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc.toml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a8003f40..f0db13f9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,20 +14,20 @@ jobs: runs-on: ubuntu-latest environment: release steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: 3.x - - name: Install dependencies - run: pip install build - - name: Create packages - run: python -m build - - name: Archive packages - uses: actions/upload-artifact@v3 - with: - name: dist - path: dist + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.x + - name: Install dependencies + run: pip install build + - name: Create packages + run: python -m build + - name: Archive packages + uses: actions/upload-artifact@v3 + with: + name: dist + path: dist publish: name: Publish build artifacts to the PyPI @@ -37,10 +37,10 @@ jobs: permissions: id-token: write steps: - - name: Retrieve packages - uses: actions/download-artifact@v3 - - name: Upload packages - uses: pypa/gh-action-pypi-publish@release/v1 + - name: Retrieve packages + uses: actions/download-artifact@v3 + - name: Upload packages + uses: pypa/gh-action-pypi-publish@release/v1 release: name: Create a GitHub release @@ -49,11 +49,11 @@ jobs: permissions: contents: write steps: - - uses: actions/checkout@v4 - - id: changelog - uses: agronholm/release-notes@v1 - with: - path: docs/versionhistory.rst - - uses: ncipollo/release-action@v1 - with: - body: ${{ steps.changelog.outputs.changelog }} + - uses: actions/checkout@v4 + - id: changelog + uses: agronholm/release-notes@v1 + with: + path: docs/versionhistory.rst + - uses: ncipollo/release-action@v1 + with: + body: ${{ steps.changelog.outputs.changelog }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1cfe7454..974bc730 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,23 +15,23 @@ jobs: tests-changed: ${{ steps.changed-files.outputs.tests_any_changed }} docs-changed: ${{ steps.changed-files.outputs.doc_any_changed }} steps: - - uses: actions/checkout@v4 - - name: Get changed files by category - id: changed-files - uses: tj-actions/changed-files@v37 - with: - files_yaml: | - workflow: - - .github/workflows/test.yml - pyproject: - - pyproject.toml - src: - - src/** - tests: - - tests/** - doc: - - README.rst - - docs/** + - uses: actions/checkout@v4 + - name: Get changed files by category + id: changed-files + uses: tj-actions/changed-files@v37 + with: + files_yaml: | + workflow: + - .github/workflows/test.yml + pyproject: + - pyproject.toml + src: + - src/** + tests: + - tests/** + doc: + - README.rst + - docs/** pyright: runs-on: ubuntu-latest @@ -42,19 +42,19 @@ jobs: || (needs.changed-files.outputs.src-changed == 'true') }} steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: 3.x - - uses: actions/cache@v3 - with: - path: ~/.cache/pip - key: pip-pyright - - name: Install dependencies - run: pip install -e . pyright pytest - - name: Run pyright - run: pyright --verifytypes anyio + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.x + - uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: pip-pyright + - name: Install dependencies + run: pip install -e . pyright pytest + - name: Run pyright + run: pyright --verifytypes anyio test: strategy: @@ -63,14 +63,14 @@ jobs: os: [ubuntu-latest] python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", pypy-3.10] include: - - os: macos-latest - python-version: "3.8" - - os: macos-latest - python-version: "3.11" - - os: windows-latest - python-version: "3.8" - - os: windows-latest - python-version: "3.11" + - os: macos-latest + python-version: "3.8" + - os: macos-latest + python-version: "3.11" + - os: windows-latest + python-version: "3.8" + - os: windows-latest + python-version: "3.11" runs-on: ${{ matrix.os }} needs: changed-files if: | @@ -81,28 +81,28 @@ jobs: || (needs.changed-files.outputs.tests-changed == 'true') }} steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - allow-prereleases: true - cache: pip - cache-dependency-path: pyproject.toml - - name: Install dependencies - run: pip install -e .[test] - - name: Test with pytest - run: | - coverage run -m pytest -v - coverage xml - timeout-minutes: 5 - env: - PYTEST_DISABLE_PLUGIN_AUTOLOAD: 1 - - name: Upload Coverage - uses: coverallsapp/github-action@v2 - with: - parallel: true - file: coverage.xml + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + allow-prereleases: true + cache: pip + cache-dependency-path: pyproject.toml + - name: Install dependencies + run: pip install -e .[test] + - name: Test with pytest + run: | + coverage run -m pytest -v + coverage xml + timeout-minutes: 5 + env: + PYTEST_DISABLE_PLUGIN_AUTOLOAD: 1 + - name: Upload Coverage + uses: coverallsapp/github-action@v2 + with: + parallel: true + file: coverage.xml docs: runs-on: ubuntu-latest @@ -115,24 +115,24 @@ jobs: || (needs.changed-files.outputs.docs-changed == 'true') }} steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: "3.11" - cache: pip - cache-dependency-path: pyproject.toml - - name: Install dependencies - run: pip install -e .[doc] - - name: Build documentation - run: sphinx-build -W docs build/sphinx + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: pip + cache-dependency-path: pyproject.toml + - name: Install dependencies + run: pip install -e .[doc] + - name: Build documentation + run: sphinx-build -W docs build/sphinx coveralls: name: Finish Coveralls needs: test runs-on: ubuntu-latest steps: - - name: Finished - uses: coverallsapp/github-action@v2 - with: - parallel-finished: true + - name: Finished + uses: coverallsapp/github-action@v2 + with: + parallel-finished: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 81a24cba..35efdc17 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ repos: - id: debug-statements - id: end-of-file-fixer - id: mixed-line-ending - args: [ "--fix=lf" ] + args: [--fix=lf] - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit @@ -22,6 +22,11 @@ repos: args: [--fix, --show-fixes] - id: ruff-format + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.7.1 + hooks: + - id: prettier + - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.8.0 hooks: @@ -34,6 +39,6 @@ repos: - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.10.0 hooks: - - id: rst-backticks - - id: rst-directive-colons - - id: rst-inline-touching-normal + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..9936e797 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,16 @@ +# macOS resource forks +._* +.DS_Store + +# Build artifacts +/build +/dist + +# Generated environments +/venv + +# Cache files +/.hypothesis +/.mypy_cache +/.pytest_cache +/.ruff_cache diff --git a/.prettierrc.toml b/.prettierrc.toml new file mode 100644 index 00000000..a7987905 --- /dev/null +++ b/.prettierrc.toml @@ -0,0 +1,4 @@ +trailingComma = "none" +tabWidth = 2 +semi = false +printWidth = 100 diff --git a/.readthedocs.yml b/.readthedocs.yml index 48ac4e1d..01a0d446 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -10,7 +10,7 @@ sphinx: fail_on_warning: true python: - install: - - method: pip - path: . - extra_requirements: [doc] + install: + - method: pip + path: . + extra_requirements: [doc] diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst index 475613ac..d9f70fae 100644 --- a/docs/versionhistory.rst +++ b/docs/versionhistory.rst @@ -1,6 +1,11 @@ Version history =============== +**UNRELEASED** + +- Add `Prettier `_ to the pre-commit configuration to enforce + consistent formatting of non-python files (PR by Colin Taylor) + This library adheres to `Semantic Versioning 2.0 `_. **4.2.0**