Skip to content

Add Ruff configuration file #262

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 1 commit into from
Apr 11, 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.6
rev: v0.11.5
hooks:
- id: ruff-format

Expand Down
7 changes: 7 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
target-version = "py313" # Pin Ruff to Python 3.13
line-length = 88
output-format = "full"

[format]
preview = true
docstring-code-format = true
143 changes: 64 additions & 79 deletions build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,12 @@ def build(self):
sphinxopts = list(self.language.sphinxopts)
if self.language.tag != "en":
locale_dirs = self.build_root / self.version.name / "locale"
sphinxopts.extend(
(
f"-D locale_dirs={locale_dirs}",
f"-D language={self.language.iso639_tag}",
"-D gettext_compact=0",
"-D translation_progress_classes=1",
)
)
sphinxopts.extend((
f"-D locale_dirs={locale_dirs}",
f"-D language={self.language.iso639_tag}",
"-D gettext_compact=0",
"-D translation_progress_classes=1",
))
if self.language.tag == "ja":
# Since luatex doesn't support \ufffd, replace \ufffd with '?'.
# https://gist.github.com/zr-tex8r/e0931df922f38fbb67634f05dfdaf66b
Expand Down Expand Up @@ -667,20 +665,18 @@ def build(self):
self.version,
self.checkout / "Doc" / "tools" / "templates" / "indexsidebar.html",
)
run_with_logging(
[
"make",
"-C",
self.checkout / "Doc",
"PYTHON=" + str(python),
"SPHINXBUILD=" + str(sphinxbuild),
"BLURB=" + str(blurb),
"VENVDIR=" + str(self.venv),
"SPHINXOPTS=" + " ".join(sphinxopts),
"SPHINXERRORHANDLING=",
maketarget,
]
)
run_with_logging([
"make",
"-C",
self.checkout / "Doc",
"PYTHON=" + str(python),
"SPHINXBUILD=" + str(sphinxbuild),
"BLURB=" + str(blurb),
"VENVDIR=" + str(self.venv),
"SPHINXOPTS=" + " ".join(sphinxopts),
"SPHINXERRORHANDLING=",
maketarget,
])
run(["mkdir", "-p", self.log_directory])
run(["chgrp", "-R", self.group, self.log_directory])
if self.includes_html:
Expand Down Expand Up @@ -743,69 +739,57 @@ def copy_build_to_webroot(self, http: urllib3.PoolManager) -> None:
# Copy built HTML files to webroot (default /srv/docs.python.org)
changed = changed_files(self.checkout / "Doc" / "build" / "html", target)
logging.info("Copying HTML files to %s", target)
run(
[
"chown",
"-R",
":" + self.group,
self.checkout / "Doc" / "build" / "html/",
]
)
run([
"chown",
"-R",
":" + self.group,
self.checkout / "Doc" / "build" / "html/",
])
run(["chmod", "-R", "o+r", self.checkout / "Doc" / "build" / "html"])
run(
[
"find",
self.checkout / "Doc" / "build" / "html",
"-type",
"d",
"-exec",
"chmod",
"o+x",
"{}",
";",
]
)
run(
[
"rsync",
"-a",
"--delete-delay",
"--filter",
"P archives/",
str(self.checkout / "Doc" / "build" / "html") + "/",
target,
]
)
run([
"find",
self.checkout / "Doc" / "build" / "html",
"-type",
"d",
"-exec",
"chmod",
"o+x",
"{}",
";",
])
run([
"rsync",
"-a",
"--delete-delay",
"--filter",
"P archives/",
str(self.checkout / "Doc" / "build" / "html") + "/",
target,
])

if not self.quick:
# Copy archive files to /archives/
logging.debug("Copying dist files.")
run(
[
"chown",
"-R",
":" + self.group,
self.checkout / "Doc" / "dist",
]
)
run(
[
"chmod",
"-R",
"o+r",
self.checkout / "Doc" / "dist",
]
)
run([
"chown",
"-R",
":" + self.group,
self.checkout / "Doc" / "dist",
])
run([
"chmod",
"-R",
"o+r",
self.checkout / "Doc" / "dist",
])
run(["mkdir", "-m", "o+rx", "-p", target / "archives"])
run(["chown", ":" + self.group, target / "archives"])
run(
[
"cp",
"-a",
*(self.checkout / "Doc" / "dist").glob("*"),
target / "archives",
]
)
run([
"cp",
"-a",
*(self.checkout / "Doc" / "dist").glob("*"),
target / "archives",
])
changed.append("archives/")
for file in (target / "archives").iterdir():
changed.append("archives/" + file.name)
Expand Down Expand Up @@ -984,7 +968,8 @@ def parse_args():
default=Path("/var/log/docsbuild/"),
)
parser.add_argument(
"--languages", "--language",
"--languages",
"--language",
nargs="*",
help="Language translation, as a PEP 545 language tag like"
" 'fr' or 'pt-br'. "
Expand Down
10 changes: 4 additions & 6 deletions check_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,10 @@ async def which_sphinx_is_used_in_production():
table = [
[
version.name,
*await asyncio.gather(
*[
get_version_in_prod(language.tag, version.name)
for language in LANGUAGES
]
),
*await asyncio.gather(*[
get_version_in_prod(language.tag, version.name)
for language in LANGUAGES
]),
]
for version in VERSIONS
]
Expand Down