Skip to content

Show elapsed time for build and publishing #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 17, 2024
22 changes: 22 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Lint

on: [push, pull_request, workflow_dispatch]

env:
FORCE_COLOR: 1
PIP_DISABLE_PIP_VERSION_CHECK: 1

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
cache: pip
- uses: pre-commit/[email protected]
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Test

on: [push, pull_request, workflow_dispatch]

permissions:
contents: read

env:
FORCE_COLOR: 1
PIP_DISABLE_PIP_VERSION_CHECK: 1

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- name: Install uv
uses: hynek/setup-cached-uv@v2

- name: Install dependencies
run: |
uv pip install --system -U tox-uv

- name: Tox tests
run: |
tox -e py
47 changes: 47 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: forbid-submodules
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.6
hooks:
- id: check-github-workflows

- repo: https://github.com/rhysd/actionlint
rev: v1.7.1
hooks:
- id: actionlint

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 2.1.3
hooks:
- id: pyproject-fmt

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.18
hooks:
- id: validate-pyproject

- repo: https://github.com/tox-dev/tox-ini-fmt
rev: 1.3.1
hooks:
- id: tox-ini-fmt

- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes

ci:
autoupdate_schedule: quarterly
25 changes: 22 additions & 3 deletions build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import json
import logging
import logging.handlers
from functools import total_ordering
from functools import total_ordering, cache
from os import readlink
import platform
import re
Expand Down Expand Up @@ -702,6 +702,7 @@ def translation_branch(self):
def build(self):
"""Build this version/language doc."""
logging.info("Build start.")
start_time = perf_counter()
sphinxopts = list(self.language.sphinxopts)
sphinxopts.extend(["-q"])
if self.language.tag != "en":
Expand Down Expand Up @@ -778,7 +779,7 @@ def is_mac():
setup_switchers(
self.versions, self.languages, self.checkout / "Doc" / "build" / "html"
)
logging.info("Build done.")
logging.info("Build done (%s).", format_seconds(perf_counter() - start_time))

def build_venv(self):
"""Build a venv for the specific Python version.
Expand All @@ -800,6 +801,7 @@ def build_venv(self):
def copy_build_to_webroot(self):
"""Copy a given build to the appropriate webroot with appropriate rights."""
logging.info("Publishing start.")
start_time = perf_counter()
self.www_root.mkdir(parents=True, exist_ok=True)
if self.language.tag == "en":
target = self.www_root / self.version.name
Expand Down Expand Up @@ -912,7 +914,9 @@ def copy_build_to_webroot(self):
purge(*prefixes)
for prefix in prefixes:
purge(*[prefix + p for p in changed])
logging.info("Publishing done")
logging.info(
"Publishing done (%s).", format_seconds(perf_counter() - start_time)
)

def should_rebuild(self):
state = self.load_state()
Expand Down Expand Up @@ -1147,6 +1151,21 @@ def build_docs(args) -> bool:
return all_built_successfully


@cache
def format_seconds(seconds: float) -> str:
hours, remainder = divmod(seconds, 3600)
minutes, seconds = divmod(remainder, 60)
hours, minutes, seconds = int(hours), int(minutes), round(seconds)

match (hours, minutes, seconds):
case 0, 0, s:
return f"{s}s"
case 0, m, s:
return f"{m}m {s}s"
case h, m, s:
return f"{h}h {m}m {s}s"


def main():
"""Script entry point."""
args = parse_args()
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[tool.pytest.ini_options]
pythonpath = [
".",
]
testpaths = [
"tests",
]
26 changes: 26 additions & 0 deletions tests/test_build_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from build_docs import format_seconds


@pytest.mark.parametrize(
"seconds, expected",
[
(0.4, "0s"),
(0.5, "0s"),
(0.6, "1s"),
(1.5, "2s"),
(30, "30s"),
(60, "1m 0s"),
(185, "3m 5s"),
(454, "7m 34s"),
(7456, "2h 4m 16s"),
(30.1, "30s"),
(60.2, "1m 0s"),
(185.3, "3m 5s"),
(454.4, "7m 34s"),
(7456.5, "2h 4m 16s"),
],
)
def test_format_seconds(seconds: float, expected: str) -> None:
assert format_seconds(seconds) == expected
25 changes: 25 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[tox]
requires =
tox>=4.2
env_list =
lint
py{313, 312, 311, 310}

[testenv]
package = wheel
wheel_build_env = .pkg
skip_install = true
deps =
-r requirements.txt
pytest
commands =
{envpython} -m pytest {posargs}

[testenv:lint]
skip_install = true
deps =
pre-commit
pass_env =
PRE_COMMIT_COLOR
commands =
pre-commit run --all-files --show-diff-on-failure