Skip to content

Commit

Permalink
Add prettier to pre-commit hooks
Browse files Browse the repository at this point in the history
Prettier provides the same experience as Python's Black, when working on
web-related stuff.
  • Loading branch information
pradyunsg authored and jorisvandenbossche committed Nov 22, 2021
1 parent 1e3a8fa commit 2372189
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 321 deletions.
339 changes: 167 additions & 172 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,56 @@ env:
COVERAGE_THRESHOLD: 60

jobs:

lint:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Set up Node/yarn
uses: actions/setup-node@v1
with:
node-version: '16.x'

- name: Cache python wheels
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: |
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py', 'docs/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip-
- name: Cache node_modules
uses: actions/cache@v2
with:
path: 'node_modules'
key: |
${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade pre-commit
python -m pip install -e .
yarn --frozen-lockfile
- name: Lint
run: |
pre-commit run --all-files
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Set up Node/yarn
uses: actions/setup-node@v1
with:
node-version: "16.x"

- name: Cache python wheels
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: |
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py', 'docs/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip-
- name: Cache node_modules
uses: actions/cache@v2
with:
path: "node_modules"
key: |
${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade pre-commit
python -m pip install -e .
yarn --frozen-lockfile
- name: Lint
run: |
pre-commit run --all-files
# Build docs on a number of Python versions. In the future this can be
# where tests go.
tests:

runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -68,49 +65,48 @@ jobs:
dev: true

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Cache python wheels
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: |
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py', 'docs/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -e .[coverage]
- name: Install pre-release dependencies
if: ${{ matrix.dev }}
run: pip install --upgrade --pre sphinx jinja2

# Build the docs
- name: Build docs to store
run: |
export PATH="$HOME/miniconda/bin:$PATH"
sphinx-build -b html docs/ docs/_build/html -W --keep-going
# Run tests under coverage
- name: Run the tests
run: pytest --cov pydata_sphinx_theme --cov-branch --cov-report term-missing:skip-covered --cov-fail-under ${{ env.COVERAGE_THRESHOLD }}

- name: Upload coverage
if: ${{ always() }}
run: codecov
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Cache python wheels
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: |
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py', 'docs/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -e .[coverage]
- name: Install pre-release dependencies
if: ${{ matrix.dev }}
run: pip install --upgrade --pre sphinx jinja2

# Build the docs
- name: Build docs to store
run: |
export PATH="$HOME/miniconda/bin:$PATH"
sphinx-build -b html docs/ docs/_build/html -W --keep-going
# Run tests under coverage
- name: Run the tests
run: pytest --cov pydata_sphinx_theme --cov-branch --cov-report term-missing:skip-covered --cov-fail-under ${{ env.COVERAGE_THRESHOLD }}

- name: Upload coverage
if: ${{ always() }}
run: codecov

# Run local Lighthouse audit against built site
audit:

runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -124,98 +120,97 @@ jobs:
PA11Y_BUILD: /tmp/pa11y/pa11y-${{ github.run_number }}

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Set up Node/yarn
uses: actions/setup-node@v1
with:
node-version: '16.x'

- name: Cache python wheels
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: |
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py', 'docs/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip-
- name: Cache node_modules
uses: actions/cache@v2
with:
path: 'node_modules'
key: |
${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel setuptools
python -m pip install -e .[coverage]
yarn --frozen-lockfile
# Build the docs
- name: Build docs to store
run: |
export PATH="$HOME/miniconda/bin:$PATH"
sphinx-build -b html docs/ docs/_build/html -W --keep-going
# Serve the docs and wait to be ready
- name: Serve the built site
run: |
nohup python docs/serve.py --port=${PORT} --host=${HOST} &
curl --retry 10 --retry-connrefused --retry-max-time 60 ${URL}/index.html
# Run the audit
# TODO: use the hosted API with a secret? would allow for comparison over time...
- name: Make folder for Lighthouse reports
run: mkdir -p /tmp/lighthouse/lighthouse-${{ github.run_number }}

- name: Run Lighthouse on Site
id: lighthouse
uses: foo-software/[email protected]
with:
# TODO: generate this list to audit all html pages
urls: >-
${{ env.URL }}/index.html,
${{ env.URL }}/demo/api.html,
${{ env.URL }}/demo/demo.html,
${{ env.URL }}/demo/example_pandas.html,
${{ env.URL }}/user_guide/accessibility.html
outputDirectory: /tmp/lighthouse/lighthouse-${{ github.run_number }}
verbose: true

- name: Run the accessibility audit
run: python docs/a11y.py --no-serve

# Check the audit for threshold values
# TODO: write this someplace after a PR is merged, and load?
- name: Assess Lighthouse Check results
uses: foo-software/[email protected]
with:
lighthouseCheckResults: ${{ steps.lighthouse.outputs.lighthouseCheckResults }}
minAccessibilityScore: "96"
minBestPracticesScore: "85"
minPerformanceScore: "10"
minSeoScore: "80"
if: always()

- name: Publish Audit reports
uses: actions/upload-artifact@v2
with:
name: Pa11y and Lighthouse ${{ github.run_number }}
path: |
/tmp/pa11y
/tmp/lighthouse
if: always()
- uses: actions/checkout@v2

publish:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Set up Node/yarn
uses: actions/setup-node@v1
with:
node-version: "16.x"

- name: Cache python wheels
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: |
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py', 'docs/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip-
- name: Cache node_modules
uses: actions/cache@v2
with:
path: "node_modules"
key: |
${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel setuptools
python -m pip install -e .[coverage]
yarn --frozen-lockfile
# Build the docs
- name: Build docs to store
run: |
export PATH="$HOME/miniconda/bin:$PATH"
sphinx-build -b html docs/ docs/_build/html -W --keep-going
# Serve the docs and wait to be ready
- name: Serve the built site
run: |
nohup python docs/serve.py --port=${PORT} --host=${HOST} &
curl --retry 10 --retry-connrefused --retry-max-time 60 ${URL}/index.html
# Run the audit
# TODO: use the hosted API with a secret? would allow for comparison over time...
- name: Make folder for Lighthouse reports
run: mkdir -p /tmp/lighthouse/lighthouse-${{ github.run_number }}

- name: Run Lighthouse on Site
id: lighthouse
uses: foo-software/[email protected]
with:
# TODO: generate this list to audit all html pages
urls: >-
${{ env.URL }}/index.html,
${{ env.URL }}/demo/api.html,
${{ env.URL }}/demo/demo.html,
${{ env.URL }}/demo/example_pandas.html,
${{ env.URL }}/user_guide/accessibility.html
outputDirectory: /tmp/lighthouse/lighthouse-${{ github.run_number }}
verbose: true

- name: Run the accessibility audit
run: python docs/a11y.py --no-serve

# Check the audit for threshold values
# TODO: write this someplace after a PR is merged, and load?
- name: Assess Lighthouse Check results
uses: foo-software/[email protected]
with:
lighthouseCheckResults: ${{ steps.lighthouse.outputs.lighthouseCheckResults }}
minAccessibilityScore: "96"
minBestPracticesScore: "85"
minPerformanceScore: "10"
minSeoScore: "80"
if: always()

- name: Publish Audit reports
uses: actions/upload-artifact@v2
with:
name: Pa11y and Lighthouse ${{ github.run_number }}
path: |
/tmp/pa11y
/tmp/lighthouse
if: always()

publish:
name: Publish to PyPi
needs: [lint, tests]
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ repos:
entry: bash -c "yarn build:production"
files: ^src/*

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.4.1
hooks:
- id: prettier
# Exclude the HTML, since it doesn't understand Jinja2
exclude: .+((\.html)|index\.(.+)\.css)$

- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
Expand Down
Loading

0 comments on commit 2372189

Please sign in to comment.