Skip to content

Commit 879433e

Browse files
authored
Merge pull request #188 from hugovk/log-elapsed-time
2 parents e1b1138 + b0921bd commit 879433e

File tree

7 files changed

+181
-2
lines changed

7 files changed

+181
-2
lines changed

.github/workflows/lint.yml

+22
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

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
11+
jobs:
12+
test:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
python-version: ["3.10", "3.11", "3.12", "3.13"]
18+
os: [ubuntu-latest]
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
allow-prereleases: true
28+
29+
- name: Install uv
30+
uses: hynek/setup-cached-uv@v2
31+
32+
- name: Tox tests
33+
run: |
34+
uvx --with tox-uv tox -e py

.pre-commit-config.yaml

+47
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.29.2
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.2.3
28+
hooks:
29+
- id: pyproject-fmt
30+
31+
- repo: https://github.com/abravalheri/validate-pyproject
32+
rev: v0.19
33+
hooks:
34+
- id: validate-pyproject
35+
36+
- repo: https://github.com/tox-dev/tox-ini-fmt
37+
rev: 1.4.0
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

+24-2
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ def translation_branch(self):
701701
def build(self):
702702
"""Build this version/language doc."""
703703
logging.info("Build start.")
704+
start_time = perf_counter()
704705
sphinxopts = list(self.language.sphinxopts)
705706
sphinxopts.extend(["-q"])
706707
if self.language.tag != "en":
@@ -777,7 +778,7 @@ def is_mac():
777778
setup_switchers(
778779
self.versions, self.languages, self.checkout / "Doc" / "build" / "html"
779780
)
780-
logging.info("Build done.")
781+
logging.info("Build done (%s).", format_seconds(perf_counter() - start_time))
781782

782783
def build_venv(self):
783784
"""Build a venv for the specific Python version.
@@ -800,6 +801,7 @@ def build_venv(self):
800801
def copy_build_to_webroot(self, http: urllib3.PoolManager) -> None:
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, http: urllib3.PoolManager) -> None:
912914
purge(http, *prefixes)
913915
for prefix in prefixes:
914916
purge(http, *[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()
@@ -1141,8 +1145,24 @@ def parse_languages_from_config():
11411145
return languages
11421146

11431147

1148+
def format_seconds(seconds: float) -> str:
1149+
hours, remainder = divmod(seconds, 3600)
1150+
minutes, seconds = divmod(remainder, 60)
1151+
hours, minutes, seconds = int(hours), int(minutes), round(seconds)
1152+
1153+
match (hours, minutes, seconds):
1154+
case 0, 0, s:
1155+
return f"{s}s"
1156+
case 0, m, s:
1157+
return f"{m}m {s}s"
1158+
case h, m, s:
1159+
return f"{h}h {m}m {s}s"
1160+
1161+
11441162
def build_docs(args) -> bool:
11451163
"""Build all docs (each language and each version)."""
1164+
logging.info("Full build start.")
1165+
start_time = perf_counter()
11461166
http = urllib3.PoolManager()
11471167
versions = parse_versions_from_devguide(http)
11481168
languages = parse_languages_from_config()
@@ -1205,6 +1225,8 @@ def build_docs(args) -> bool:
12051225
)
12061226
proofread_canonicals(args.www_root, args.skip_cache_invalidation, http)
12071227

1228+
logging.info("Full build done (%s).", format_seconds(perf_counter() - start_time))
1229+
12081230
return all_built_successfully
12091231

12101232

pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tool.pytest.ini_options]
2+
pythonpath = [ "." ]
3+
testpaths = [ "tests" ]

tests/test_build_docs.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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, "2h 4m 16s"),
18+
(30.1, "30s"),
19+
(60.2, "1m 0s"),
20+
(185.3, "3m 5s"),
21+
(454.4, "7m 34s"),
22+
(7456.5, "2h 4m 16s"),
23+
],
24+
)
25+
def test_format_seconds(seconds: float, expected: str) -> None:
26+
assert format_seconds(seconds) == expected

tox.ini

+25
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}
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)