Skip to content

Commit 2372189

Browse files
pradyunsgjorisvandenbossche
authored andcommitted
Add prettier to pre-commit hooks
Prettier provides the same experience as Python's Black, when working on web-related stuff.
1 parent 1e3a8fa commit 2372189

15 files changed

+322
-321
lines changed

.github/workflows/tests.yml

+167-172
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,56 @@ env:
66
COVERAGE_THRESHOLD: 60
77

88
jobs:
9-
109
lint:
11-
1210
runs-on: ubuntu-latest
1311
strategy:
1412
matrix:
1513
python-version: [3.8]
1614

1715
steps:
18-
- uses: actions/checkout@v2
19-
20-
- name: Set up Python ${{ matrix.python-version }}
21-
uses: actions/setup-python@v1
22-
with:
23-
python-version: ${{ matrix.python-version }}
24-
25-
- name: Set up Node/yarn
26-
uses: actions/setup-node@v1
27-
with:
28-
node-version: '16.x'
29-
30-
- name: Cache python wheels
31-
uses: actions/cache@v2
32-
with:
33-
path: ~/.cache/pip
34-
key: |
35-
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py', 'docs/requirements.txt') }}
36-
restore-keys: |
37-
${{ runner.os }}-pip-${{ matrix.python-version }}-
38-
${{ runner.os }}-pip-
39-
40-
- name: Cache node_modules
41-
uses: actions/cache@v2
42-
with:
43-
path: 'node_modules'
44-
key: |
45-
${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
46-
47-
- name: Install dependencies
48-
run: |
49-
python -m pip install --upgrade pip setuptools wheel
50-
python -m pip install --upgrade pre-commit
51-
python -m pip install -e .
52-
yarn --frozen-lockfile
53-
54-
- name: Lint
55-
run: |
56-
pre-commit run --all-files
16+
- uses: actions/checkout@v2
17+
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v1
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: Set up Node/yarn
24+
uses: actions/setup-node@v1
25+
with:
26+
node-version: "16.x"
27+
28+
- name: Cache python wheels
29+
uses: actions/cache@v2
30+
with:
31+
path: ~/.cache/pip
32+
key: |
33+
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py', 'docs/requirements.txt') }}
34+
restore-keys: |
35+
${{ runner.os }}-pip-${{ matrix.python-version }}-
36+
${{ runner.os }}-pip-
37+
38+
- name: Cache node_modules
39+
uses: actions/cache@v2
40+
with:
41+
path: "node_modules"
42+
key: |
43+
${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
44+
45+
- name: Install dependencies
46+
run: |
47+
python -m pip install --upgrade pip setuptools wheel
48+
python -m pip install --upgrade pre-commit
49+
python -m pip install -e .
50+
yarn --frozen-lockfile
51+
52+
- name: Lint
53+
run: |
54+
pre-commit run --all-files
5755
5856
# Build docs on a number of Python versions. In the future this can be
5957
# where tests go.
6058
tests:
61-
6259
runs-on: ubuntu-latest
6360
strategy:
6461
matrix:
@@ -68,49 +65,48 @@ jobs:
6865
dev: true
6966

7067
steps:
71-
- uses: actions/checkout@v2
72-
73-
- name: Set up Python ${{ matrix.python-version }}
74-
uses: actions/setup-python@v1
75-
with:
76-
python-version: ${{ matrix.python-version }}
77-
78-
- name: Cache python wheels
79-
uses: actions/cache@v2
80-
with:
81-
path: ~/.cache/pip
82-
key: |
83-
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py', 'docs/requirements.txt') }}
84-
restore-keys: |
85-
${{ runner.os }}-pip-${{ matrix.python-version }}-
86-
${{ runner.os }}-pip-
87-
88-
- name: Install dependencies
89-
run: |
90-
python -m pip install --upgrade pip setuptools wheel
91-
python -m pip install -e .[coverage]
92-
93-
- name: Install pre-release dependencies
94-
if: ${{ matrix.dev }}
95-
run: pip install --upgrade --pre sphinx jinja2
96-
97-
# Build the docs
98-
- name: Build docs to store
99-
run: |
100-
export PATH="$HOME/miniconda/bin:$PATH"
101-
sphinx-build -b html docs/ docs/_build/html -W --keep-going
102-
103-
# Run tests under coverage
104-
- name: Run the tests
105-
run: pytest --cov pydata_sphinx_theme --cov-branch --cov-report term-missing:skip-covered --cov-fail-under ${{ env.COVERAGE_THRESHOLD }}
106-
107-
- name: Upload coverage
108-
if: ${{ always() }}
109-
run: codecov
68+
- uses: actions/checkout@v2
69+
70+
- name: Set up Python ${{ matrix.python-version }}
71+
uses: actions/setup-python@v1
72+
with:
73+
python-version: ${{ matrix.python-version }}
74+
75+
- name: Cache python wheels
76+
uses: actions/cache@v2
77+
with:
78+
path: ~/.cache/pip
79+
key: |
80+
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py', 'docs/requirements.txt') }}
81+
restore-keys: |
82+
${{ runner.os }}-pip-${{ matrix.python-version }}-
83+
${{ runner.os }}-pip-
84+
85+
- name: Install dependencies
86+
run: |
87+
python -m pip install --upgrade pip setuptools wheel
88+
python -m pip install -e .[coverage]
89+
90+
- name: Install pre-release dependencies
91+
if: ${{ matrix.dev }}
92+
run: pip install --upgrade --pre sphinx jinja2
93+
94+
# Build the docs
95+
- name: Build docs to store
96+
run: |
97+
export PATH="$HOME/miniconda/bin:$PATH"
98+
sphinx-build -b html docs/ docs/_build/html -W --keep-going
99+
100+
# Run tests under coverage
101+
- name: Run the tests
102+
run: pytest --cov pydata_sphinx_theme --cov-branch --cov-report term-missing:skip-covered --cov-fail-under ${{ env.COVERAGE_THRESHOLD }}
103+
104+
- name: Upload coverage
105+
if: ${{ always() }}
106+
run: codecov
110107

111108
# Run local Lighthouse audit against built site
112109
audit:
113-
114110
runs-on: ubuntu-latest
115111
strategy:
116112
matrix:
@@ -124,98 +120,97 @@ jobs:
124120
PA11Y_BUILD: /tmp/pa11y/pa11y-${{ github.run_number }}
125121

126122
steps:
127-
- uses: actions/checkout@v2
128-
129-
- name: Set up Python ${{ matrix.python-version }}
130-
uses: actions/setup-python@v1
131-
with:
132-
python-version: ${{ matrix.python-version }}
133-
134-
- name: Set up Node/yarn
135-
uses: actions/setup-node@v1
136-
with:
137-
node-version: '16.x'
138-
139-
- name: Cache python wheels
140-
uses: actions/cache@v2
141-
with:
142-
path: ~/.cache/pip
143-
key: |
144-
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py', 'docs/requirements.txt') }}
145-
restore-keys: |
146-
${{ runner.os }}-pip-${{ matrix.python-version }}-
147-
${{ runner.os }}-pip-
148-
149-
- name: Cache node_modules
150-
uses: actions/cache@v2
151-
with:
152-
path: 'node_modules'
153-
key: |
154-
${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
155-
156-
- name: Install dependencies
157-
run: |
158-
python -m pip install --upgrade pip wheel setuptools
159-
python -m pip install -e .[coverage]
160-
yarn --frozen-lockfile
161-
162-
# Build the docs
163-
- name: Build docs to store
164-
run: |
165-
export PATH="$HOME/miniconda/bin:$PATH"
166-
sphinx-build -b html docs/ docs/_build/html -W --keep-going
167-
168-
# Serve the docs and wait to be ready
169-
- name: Serve the built site
170-
run: |
171-
nohup python docs/serve.py --port=${PORT} --host=${HOST} &
172-
curl --retry 10 --retry-connrefused --retry-max-time 60 ${URL}/index.html
173-
174-
# Run the audit
175-
# TODO: use the hosted API with a secret? would allow for comparison over time...
176-
- name: Make folder for Lighthouse reports
177-
run: mkdir -p /tmp/lighthouse/lighthouse-${{ github.run_number }}
178-
179-
- name: Run Lighthouse on Site
180-
id: lighthouse
181-
uses: foo-software/[email protected]
182-
with:
183-
# TODO: generate this list to audit all html pages
184-
urls: >-
185-
${{ env.URL }}/index.html,
186-
${{ env.URL }}/demo/api.html,
187-
${{ env.URL }}/demo/demo.html,
188-
${{ env.URL }}/demo/example_pandas.html,
189-
${{ env.URL }}/user_guide/accessibility.html
190-
outputDirectory: /tmp/lighthouse/lighthouse-${{ github.run_number }}
191-
verbose: true
192-
193-
- name: Run the accessibility audit
194-
run: python docs/a11y.py --no-serve
195-
196-
# Check the audit for threshold values
197-
# TODO: write this someplace after a PR is merged, and load?
198-
- name: Assess Lighthouse Check results
199-
uses: foo-software/[email protected]
200-
with:
201-
lighthouseCheckResults: ${{ steps.lighthouse.outputs.lighthouseCheckResults }}
202-
minAccessibilityScore: "96"
203-
minBestPracticesScore: "85"
204-
minPerformanceScore: "10"
205-
minSeoScore: "80"
206-
if: always()
207-
208-
- name: Publish Audit reports
209-
uses: actions/upload-artifact@v2
210-
with:
211-
name: Pa11y and Lighthouse ${{ github.run_number }}
212-
path: |
213-
/tmp/pa11y
214-
/tmp/lighthouse
215-
if: always()
123+
- uses: actions/checkout@v2
216124

217-
publish:
125+
- name: Set up Python ${{ matrix.python-version }}
126+
uses: actions/setup-python@v1
127+
with:
128+
python-version: ${{ matrix.python-version }}
218129

130+
- name: Set up Node/yarn
131+
uses: actions/setup-node@v1
132+
with:
133+
node-version: "16.x"
134+
135+
- name: Cache python wheels
136+
uses: actions/cache@v2
137+
with:
138+
path: ~/.cache/pip
139+
key: |
140+
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py', 'docs/requirements.txt') }}
141+
restore-keys: |
142+
${{ runner.os }}-pip-${{ matrix.python-version }}-
143+
${{ runner.os }}-pip-
144+
145+
- name: Cache node_modules
146+
uses: actions/cache@v2
147+
with:
148+
path: "node_modules"
149+
key: |
150+
${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
151+
152+
- name: Install dependencies
153+
run: |
154+
python -m pip install --upgrade pip wheel setuptools
155+
python -m pip install -e .[coverage]
156+
yarn --frozen-lockfile
157+
158+
# Build the docs
159+
- name: Build docs to store
160+
run: |
161+
export PATH="$HOME/miniconda/bin:$PATH"
162+
sphinx-build -b html docs/ docs/_build/html -W --keep-going
163+
164+
# Serve the docs and wait to be ready
165+
- name: Serve the built site
166+
run: |
167+
nohup python docs/serve.py --port=${PORT} --host=${HOST} &
168+
curl --retry 10 --retry-connrefused --retry-max-time 60 ${URL}/index.html
169+
170+
# Run the audit
171+
# TODO: use the hosted API with a secret? would allow for comparison over time...
172+
- name: Make folder for Lighthouse reports
173+
run: mkdir -p /tmp/lighthouse/lighthouse-${{ github.run_number }}
174+
175+
- name: Run Lighthouse on Site
176+
id: lighthouse
177+
uses: foo-software/[email protected]
178+
with:
179+
# TODO: generate this list to audit all html pages
180+
urls: >-
181+
${{ env.URL }}/index.html,
182+
${{ env.URL }}/demo/api.html,
183+
${{ env.URL }}/demo/demo.html,
184+
${{ env.URL }}/demo/example_pandas.html,
185+
${{ env.URL }}/user_guide/accessibility.html
186+
outputDirectory: /tmp/lighthouse/lighthouse-${{ github.run_number }}
187+
verbose: true
188+
189+
- name: Run the accessibility audit
190+
run: python docs/a11y.py --no-serve
191+
192+
# Check the audit for threshold values
193+
# TODO: write this someplace after a PR is merged, and load?
194+
- name: Assess Lighthouse Check results
195+
uses: foo-software/[email protected]
196+
with:
197+
lighthouseCheckResults: ${{ steps.lighthouse.outputs.lighthouseCheckResults }}
198+
minAccessibilityScore: "96"
199+
minBestPracticesScore: "85"
200+
minPerformanceScore: "10"
201+
minSeoScore: "80"
202+
if: always()
203+
204+
- name: Publish Audit reports
205+
uses: actions/upload-artifact@v2
206+
with:
207+
name: Pa11y and Lighthouse ${{ github.run_number }}
208+
path: |
209+
/tmp/pa11y
210+
/tmp/lighthouse
211+
if: always()
212+
213+
publish:
219214
name: Publish to PyPi
220215
needs: [lint, tests]
221216
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')

.pre-commit-config.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ repos:
1010
entry: bash -c "yarn build:production"
1111
files: ^src/*
1212

13+
- repo: https://github.com/pre-commit/mirrors-prettier
14+
rev: v2.4.1
15+
hooks:
16+
- id: prettier
17+
# Exclude the HTML, since it doesn't understand Jinja2
18+
exclude: .+((\.html)|index\.(.+)\.css)$
19+
1320
- repo: https://github.com/psf/black
1421
rev: 20.8b1
1522
hooks:

0 commit comments

Comments
 (0)