Skip to content
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

ENH: set sphinx.configuration #488

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,5 @@ description = "Perform all linting, formatting, and spelling checks"
[tool.uv]
constraint-dependencies = [
"pygments!=2.19.*", # https://github.com/felix-hilden/sphinx-codeautolink/issues/152
"sphinx-codeautolink!=0.16.0",
]
25 changes: 23 additions & 2 deletions src/compwa_policy/check_dev_files/readthedocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from compwa_policy.errors import PrecommitError
from compwa_policy.utilities import CONFIG_PATH, get_nested_dict
from compwa_policy.utilities.match import git_ls_files
from compwa_policy.utilities.match import filter_files, git_ls_files
from compwa_policy.utilities.pyproject import get_constraints_file
from compwa_policy.utilities.yaml import create_prettier_round_trip_yaml

Expand All @@ -32,6 +32,7 @@
if isinstance(source, Path) and not source.exists():
return
rtd = ReadTheDocs(source)
_set_sphinx_configuration(rtd)
_update_os(rtd)
_update_python_version(rtd, python_version)
if package_manager == "pixi+uv":
Expand All @@ -51,6 +52,27 @@
rtd.finalize()


def _set_sphinx_configuration(config: ReadTheDocs) -> None:
if "sphinx" not in config.document:
config.document["sphinx"] = {}

Check warning on line 57 in src/compwa_policy/check_dev_files/readthedocs.py

View check run for this annotation

Codecov / codecov/patch

src/compwa_policy/check_dev_files/readthedocs.py#L57

Added line #L57 was not covered by tests
sphinx = config.document["sphinx"]
if "configuration" not in sphinx:
conf_path = __get_sphinx_config_path()
sphinx["configuration"] = str(conf_path)
msg = f"Set sphinx.configuration to {conf_path}"
config.changelog.append(msg)

Check warning on line 63 in src/compwa_policy/check_dev_files/readthedocs.py

View check run for this annotation

Codecov / codecov/patch

src/compwa_policy/check_dev_files/readthedocs.py#L60-L63

Added lines #L60 - L63 were not covered by tests


def __get_sphinx_config_path() -> Path | None:
conf_path = Path("docs/conf.py")

Check warning on line 67 in src/compwa_policy/check_dev_files/readthedocs.py

View check run for this annotation

Codecov / codecov/patch

src/compwa_policy/check_dev_files/readthedocs.py#L67

Added line #L67 was not covered by tests
if conf_path.exists():
return conf_path
candidate_paths = list(filter_files(["**/conf.py"]))

Check warning on line 70 in src/compwa_policy/check_dev_files/readthedocs.py

View check run for this annotation

Codecov / codecov/patch

src/compwa_policy/check_dev_files/readthedocs.py#L69-L70

Added lines #L69 - L70 were not covered by tests
if not candidate_paths:
return None
return Path(candidate_paths[0])

Check warning on line 73 in src/compwa_policy/check_dev_files/readthedocs.py

View check run for this annotation

Codecov / codecov/patch

src/compwa_policy/check_dev_files/readthedocs.py#L72-L73

Added lines #L72 - L73 were not covered by tests


def _update_os(config: ReadTheDocs) -> None:
build = cast("CommentedMap", config.document.get("build"))
if build is None:
Expand Down Expand Up @@ -150,7 +172,6 @@
"build.apt_packages",
"build.jobs",
"formats",
"sphinx",
]
removed_keys = [
key for key in redundant_keys if __remove_nested_key(config.document, key)
Expand Down
2 changes: 2 additions & 0 deletions tests/check_dev_files/readthedocs/extend/.readthedocs-bad.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ build:
- mkdir bin
- ln -s $PWD/julia-1.9.2/bin/julia bin/julia
- ./bin/julia docs/InstallIJulia.jl
sphinx:
configuration: docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ build:
- mkdir bin
- ln -s $PWD/julia-1.9.2/bin/julia bin/julia
- ./bin/julia docs/InstallIJulia.jl
sphinx:
configuration: docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ build:
jobs:
post_install:
- pip install -e .[doc]
sphinx:
configuration: docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ build:
os: ubuntu-20.04
tools:
python: "3.7"
sphinx:
configuration: docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ build:
post_install:
- python -m pip install 'uv>=0.2.0'
- python -m uv pip install -e .[doc]
sphinx:
configuration: docs/conf.py