Skip to content

Commit 5fba9e8

Browse files
committed
fixup! Show elapsed time for build and publishing
1 parent 871f161 commit 5fba9e8

File tree

7 files changed

+176
-3
lines changed

7 files changed

+176
-3
lines changed

.github/workflows/lint.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Lint
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
env:
6+
FORCE_COLOR: 1
7+
PIP_DISABLE_PIP_VERSION_CHECK: 1
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.x"
21+
cache: pip
22+
- uses: pre-commit/[email protected]

.github/workflows/test.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Test
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
permissions:
6+
contents: read
7+
8+
env:
9+
FORCE_COLOR: 1
10+
PIP_DISABLE_PIP_VERSION_CHECK: 1
11+
12+
jobs:
13+
test:
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
19+
os: [ubuntu-latest]
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
allow-prereleases: true
29+
30+
- name: Install uv
31+
uses: hynek/setup-cached-uv@v2
32+
33+
- name: Install dependencies
34+
run: |
35+
python -m pip install -U tox
36+
37+
- name: Tox tests
38+
run: |
39+
tox -e py

.pre-commit-config.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.6.0
4+
hooks:
5+
- id: check-added-large-files
6+
- id: check-case-conflict
7+
- id: check-merge-conflict
8+
- id: check-toml
9+
- id: check-yaml
10+
- id: debug-statements
11+
- id: end-of-file-fixer
12+
- id: forbid-submodules
13+
- id: requirements-txt-fixer
14+
- id: trailing-whitespace
15+
16+
- repo: https://github.com/python-jsonschema/check-jsonschema
17+
rev: 0.28.6
18+
hooks:
19+
- id: check-github-workflows
20+
21+
- repo: https://github.com/rhysd/actionlint
22+
rev: v1.7.1
23+
hooks:
24+
- id: actionlint
25+
26+
- repo: https://github.com/tox-dev/pyproject-fmt
27+
rev: 2.1.3
28+
hooks:
29+
- id: pyproject-fmt
30+
31+
- repo: https://github.com/abravalheri/validate-pyproject
32+
rev: v0.18
33+
hooks:
34+
- id: validate-pyproject
35+
36+
- repo: https://github.com/tox-dev/tox-ini-fmt
37+
rev: 1.3.1
38+
hooks:
39+
- id: tox-ini-fmt
40+
41+
- repo: meta
42+
hooks:
43+
- id: check-hooks-apply
44+
- id: check-useless-excludes
45+
46+
ci:
47+
autoupdate_schedule: quarterly

build_docs.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import json
2929
import logging
3030
import logging.handlers
31-
from functools import total_ordering
31+
from functools import total_ordering, cache
3232
from os import readlink
3333
import platform
3434
import re
@@ -779,7 +779,9 @@ def is_mac():
779779
setup_switchers(
780780
self.versions, self.languages, self.checkout / "Doc" / "build" / "html"
781781
)
782-
logging.info("Build done (%.1f minutes).", (perf_counter() - start_time) / 60)
782+
logging.info(
783+
"Build done (%.1f minutes).", format_seconds(perf_counter() - start_time)
784+
)
783785

784786
def build_venv(self):
785787
"""Build a venv for the specific Python version.
@@ -915,7 +917,8 @@ def copy_build_to_webroot(self):
915917
for prefix in prefixes:
916918
purge(*[prefix + p for p in changed])
917919
logging.info(
918-
"Publishing done (%.1f minutes).", (perf_counter() - start_time) / 60
920+
"Publishing done (%.1f minutes).",
921+
format_seconds(perf_counter() - start_time),
919922
)
920923

921924
def should_rebuild(self):
@@ -1151,6 +1154,15 @@ def build_docs(args) -> bool:
11511154
return all_built_successfully
11521155

11531156

1157+
@cache
1158+
def format_seconds(seconds: float) -> str:
1159+
minutes = int(seconds // 60)
1160+
seconds = round(seconds % 60)
1161+
if minutes == 0:
1162+
return f"{seconds}s"
1163+
return f"{minutes}m{seconds}s"
1164+
1165+
11541166
def main():
11551167
"""Script entry point."""
11561168
args = parse_args()

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[tool.pytest.ini_options]
2+
pythonpath = [
3+
".",
4+
]
5+
testpaths = [
6+
"tests",
7+
]

tests/test_build_docs.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
3+
from build_docs import format_seconds
4+
5+
6+
@pytest.mark.parametrize(
7+
"seconds, expected",
8+
[
9+
(0.4, "0s"),
10+
(0.5, "0s"),
11+
(0.6, "1s"),
12+
(1.5, "2s"),
13+
(30, "30s"),
14+
(60, "1m0s"),
15+
(185, "3m5s"),
16+
(454, "7m34s"),
17+
(7456, "124m16s"),
18+
],
19+
)
20+
def test_format_seconds(seconds: int, expected: str) -> None:
21+
assert format_seconds(seconds) == expected

tox.ini

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[tox]
2+
requires =
3+
tox>=4.2
4+
env_list =
5+
lint
6+
py{313, 312, 311, 310, 39}
7+
8+
[testenv]
9+
package = wheel
10+
wheel_build_env = .pkg
11+
skip_install = true
12+
deps =
13+
-r requirements.txt
14+
pytest
15+
commands =
16+
{envpython} -m pytest {posargs}
17+
18+
[testenv:lint]
19+
skip_install = true
20+
deps =
21+
pre-commit
22+
pass_env =
23+
PRE_COMMIT_COLOR
24+
commands =
25+
pre-commit run --all-files --show-diff-on-failure

0 commit comments

Comments
 (0)