Skip to content

Commit a7514ed

Browse files
committed
Show elapsed time for build and publishing
1 parent 2135304 commit a7514ed

File tree

7 files changed

+177
-3
lines changed

7 files changed

+177
-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+
uv pip install --system -U tox-uv
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: 16 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
@@ -702,6 +702,7 @@ def translation_branch(self):
702702
def build(self):
703703
"""Build this version/language doc."""
704704
logging.info("Build start.")
705+
start_time = perf_counter()
705706
sphinxopts = list(self.language.sphinxopts)
706707
sphinxopts.extend(["-q"])
707708
if self.language.tag != "en":
@@ -778,7 +779,7 @@ def is_mac():
778779
setup_switchers(
779780
self.versions, self.languages, self.checkout / "Doc" / "build" / "html"
780781
)
781-
logging.info("Build done.")
782+
logging.info("Build done (%s).", format_seconds(perf_counter() - start_time))
782783

783784
def build_venv(self):
784785
"""Build a venv for the specific Python version.
@@ -800,6 +801,7 @@ def build_venv(self):
800801
def copy_build_to_webroot(self):
801802
"""Copy a given build to the appropriate webroot with appropriate rights."""
802803
logging.info("Publishing start.")
804+
start_time = perf_counter()
803805
self.www_root.mkdir(parents=True, exist_ok=True)
804806
if self.language.tag == "en":
805807
target = self.www_root / self.version.name
@@ -912,7 +914,9 @@ def copy_build_to_webroot(self):
912914
purge(*prefixes)
913915
for prefix in prefixes:
914916
purge(*[prefix + p for p in changed])
915-
logging.info("Publishing done")
917+
logging.info(
918+
"Publishing done (%s).", format_seconds(perf_counter() - start_time)
919+
)
916920

917921
def should_rebuild(self):
918922
state = self.load_state()
@@ -1147,6 +1151,15 @@ def build_docs(args) -> bool:
11471151
return all_built_successfully
11481152

11491153

1154+
@cache
1155+
def format_seconds(seconds: float) -> str:
1156+
minutes = int(seconds // 60)
1157+
seconds = round(seconds % 60)
1158+
if minutes == 0:
1159+
return f"{seconds}s"
1160+
return f"{minutes}m {seconds}s"
1161+
1162+
11501163
def main():
11511164
"""Script entry point."""
11521165
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, "1m 0s"),
15+
(185, "3m 5s"),
16+
(454, "7m 34s"),
17+
(7456, "124m 16s"),
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)