summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorÜlgen Sarıkavak <ulgensrkvk@gmail.com>2025-11-03 01:17:24 +0300
committerSaptak Sengupta <saptak013@gmail.com>2025-11-24 16:36:48 +0530
commitaf8be6402ff5a76c7193a21d4b3557e470012936 (patch)
tree7fe7bdde11bfe4d8dab0826bde45c2a1481b4d3b /docs
parentddf333258f45215f1afe54aa6dd0d0884e37e69f (diff)
Make use of Pathlib's "/"
It provides a cleaner and easier to read experience, comparing to .joinpath()
Diffstat (limited to 'docs')
-rw-r--r--docs/management/commands/update_docs.py35
-rw-r--r--docs/models.py8
-rw-r--r--docs/tests/test_models.py6
-rw-r--r--docs/tests/test_templates.py16
-rw-r--r--docs/utils.py7
-rw-r--r--docs/views.py4
6 files changed, 38 insertions, 38 deletions
diff --git a/docs/management/commands/update_docs.py b/docs/management/commands/update_docs.py
index 29e25131..acc0069b 100644
--- a/docs/management/commands/update_docs.py
+++ b/docs/management/commands/update_docs.py
@@ -135,10 +135,8 @@ class Command(BaseCommand):
self.stdout.write(f"Starting update for {release} at {datetime.now()}...")
# checkout_dir is shared for all languages.
- checkout_dir = settings.DOCS_BUILD_ROOT.joinpath("sources", release.version)
- parent_build_dir = settings.DOCS_BUILD_ROOT.joinpath(
- release.lang, release.version
- )
+ checkout_dir = settings.DOCS_BUILD_ROOT / "sources" / release.version
+ parent_build_dir = settings.DOCS_BUILD_ROOT / release.lang / release.version
if not checkout_dir.exists():
checkout_dir.mkdir(parents=True)
if not parent_build_dir.exists():
@@ -161,20 +159,21 @@ class Command(BaseCommand):
)
return
- source_dir = checkout_dir.joinpath("docs")
+ source_dir = checkout_dir / "docs"
if release.lang != settings.DEFAULT_LANGUAGE_CODE:
scm_url = release.scm_url.replace(
"django.git", "django-docs-translations.git"
)
- trans_dir = checkout_dir.joinpath("django-docs-translation")
+ trans_dir = checkout_dir / "django-docs-translation"
if not trans_dir.exists():
trans_dir.mkdir()
self.update_git(scm_url, trans_dir)
- if not source_dir.joinpath("locale").exists():
- source_dir.joinpath("locale").symlink_to(
- trans_dir.joinpath("translations")
- )
+
+ locale_dir = source_dir / "locale"
+ if not locale_dir.exists():
+ locale_dir.symlink_to(trans_dir / "translations")
+
extra_kwargs = {"stdout": subprocess.DEVNULL} if self.verbosity == 0 else {}
subprocess.check_call(
"cd %s && make translations" % trans_dir, shell=True, **extra_kwargs
@@ -191,7 +190,7 @@ class Command(BaseCommand):
#
for builder in builders:
# Wipe and re-create the build directory. See #18930.
- build_dir = parent_build_dir.joinpath("_build", builder)
+ build_dir = parent_build_dir / "_build" / builder
if build_dir.exists():
shutil.rmtree(str(build_dir))
build_dir.mkdir(parents=True)
@@ -209,7 +208,7 @@ class Command(BaseCommand):
srcdir=source_dir,
confdir=source_dir,
outdir=build_dir,
- doctreedir=build_dir.joinpath(".doctrees"),
+ doctreedir=build_dir / ".doctrees",
buildername=builder,
# Translated docs builds generate a lot of warnings, so send
# stderr to stdout to be logged (rather than generating an email)
@@ -234,9 +233,9 @@ class Command(BaseCommand):
# Create a zip file of the HTML build for offline reading.
# This gets moved into MEDIA_ROOT for downloading.
#
- html_build_dir = parent_build_dir.joinpath("_build", "djangohtml")
+ html_build_dir = parent_build_dir / "_build" / "djangohtml"
zipfile_name = f"django-docs-{release.version}-{release.lang}.zip"
- zipfile_path = Path(settings.MEDIA_ROOT).joinpath("docs", zipfile_name)
+ zipfile_path = settings.MEDIA_ROOT / "docs" / zipfile_name
if not zipfile_path.parent.exists():
zipfile_path.parent.mkdir(parents=True)
if self.verbosity >= 2:
@@ -259,8 +258,8 @@ class Command(BaseCommand):
# Copy the build results to the directory used for serving
# the documentation in the least disruptive way possible.
#
- build_dir = parent_build_dir.joinpath("_build")
- built_dir = parent_build_dir.joinpath("_built")
+ build_dir = parent_build_dir / "_build"
+ built_dir = parent_build_dir / "_built"
subprocess.check_call(
[
"rsync",
@@ -275,7 +274,7 @@ class Command(BaseCommand):
if release.is_default:
self._setup_stable_symlink(release, built_dir)
- json_built_dir = parent_build_dir.joinpath("_built", "json")
+ json_built_dir = parent_build_dir / "_built" / "json"
documents = gen_decoded_documents(json_built_dir)
release.sync_to_db(documents)
@@ -289,7 +288,7 @@ class Command(BaseCommand):
repo, branch = url.rsplit("@", 1)
else:
repo, branch = url, "main"
- if destdir.joinpath(".git").exists():
+ if (destdir / ".git").exists():
remote = "origin"
branch_with_remote = f"{remote}/{branch}"
try:
diff --git a/docs/models.py b/docs/models.py
index d690c76b..b5ad2870 100644
--- a/docs/models.py
+++ b/docs/models.py
@@ -188,10 +188,8 @@ class DocumentRelease(models.Model):
self.documents.all().delete()
# Read excluded paths from robots.docs.txt.
- robots_path = settings.BASE_DIR.joinpath(
- "djangoproject", "static", "robots.docs.txt"
- )
- with open(str(robots_path)) as fh:
+ robots_path = settings.BASE_DIR / "djangoproject" / "static" / "robots.docs.txt"
+ with robots_path.open() as fh:
excluded_paths = [
line.strip().split("/")[-1]
for line in fh
@@ -472,6 +470,6 @@ class Document(models.Model):
@cached_property
def body(self):
"""The document's body"""
- with open(str(self.full_path)) as fp:
+ with self.full_path.open() as fp:
doc = json.load(fp)
return doc["body"]
diff --git a/docs/tests/test_models.py b/docs/tests/test_models.py
index 4724cabe..a5e22065 100644
--- a/docs/tests/test_models.py
+++ b/docs/tests/test_models.py
@@ -570,10 +570,8 @@ class UpdateDocTests(TestCase):
from robots indexing.
"""
# Read the first Disallow line of robots.txt.
- robots_path = settings.BASE_DIR.joinpath(
- "djangoproject", "static", "robots.docs.txt"
- )
- with open(str(robots_path)) as fh:
+ robots_path = settings.BASE_DIR / "djangoproject" / "static" / "robots.docs.txt"
+ with robots_path.open() as fh:
for line in fh:
if line.startswith("Disallow:"):
break
diff --git a/docs/tests/test_templates.py b/docs/tests/test_templates.py
index eb5e33f7..f1f3af4a 100644
--- a/docs/tests/test_templates.py
+++ b/docs/tests/test_templates.py
@@ -31,14 +31,18 @@ class TemplateTagTests(TestCase):
tmp_docs_build_root = Path(tempfile.mkdtemp())
self.addCleanup(shutil.rmtree, tmp_docs_build_root)
os.makedirs(
- tmp_docs_build_root.joinpath(
- settings.DEFAULT_LANGUAGE_CODE, "1.8", "_built", "json"
- )
+ tmp_docs_build_root
+ / settings.DEFAULT_LANGUAGE_CODE
+ / "1.8"
+ / "_built"
+ / "json"
)
os.makedirs(
- tmp_docs_build_root.joinpath(
- settings.DEFAULT_LANGUAGE_CODE, "1.11", "_built", "json"
- )
+ tmp_docs_build_root
+ / settings.DEFAULT_LANGUAGE_CODE
+ / "1.11"
+ / "_built"
+ / "json"
)
with self.settings(DOCS_BUILD_ROOT=tmp_docs_build_root):
self.assertEqual(get_all_doc_versions({}), ["1.8", "1.11", "dev"])
diff --git a/docs/utils.py b/docs/utils.py
index 500104df..bbbf5790 100644
--- a/docs/utils.py
+++ b/docs/utils.py
@@ -1,12 +1,13 @@
import re
import unicodedata
+from pathlib import Path
from django.conf import settings
from django.http import Http404
def get_doc_root(lang, version, builder="json"):
- return settings.DOCS_BUILD_ROOT.joinpath(lang, version, "_built", builder)
+ return settings.DOCS_BUILD_ROOT / lang / version / "_built" / builder
def get_doc_root_or_404(lang, version, builder="json"):
@@ -22,7 +23,7 @@ def get_doc_path(docroot, subpath):
bits = subpath.strip("/").split("/") + ["index.fjson"]
except AttributeError:
bits = []
- doc = docroot.joinpath(*bits)
+ doc = docroot / Path(*bits)
try:
if doc.exists():
return doc
@@ -30,7 +31,7 @@ def get_doc_path(docroot, subpath):
pass # we get here if doc + subpath (without /index.fjson) is a file
bits = bits[:-2] + ["%s.fjson" % bits[-2]]
- doc = docroot.joinpath(*bits)
+ doc = docroot / Path(*bits)
if doc.exists():
return doc
diff --git a/docs/views.py b/docs/views.py
index a525b3c1..e7fdc2f9 100644
--- a/docs/views.py
+++ b/docs/views.py
@@ -81,7 +81,7 @@ def document(request, lang, version, url):
context = {
"doc": load_json_file(doc_path),
- "env": load_json_file(docroot.joinpath("globalcontext.json")),
+ "env": load_json_file(docroot / "globalcontext.json"),
"lang": lang,
"version": version,
"canonical_version": canonical_version,
@@ -91,7 +91,7 @@ def document(request, lang, version, url):
"rtd_version": rtd_version,
"docurl": url,
"update_date": datetime.datetime.fromtimestamp(
- (docroot.joinpath("last_build")).stat().st_mtime
+ (docroot / "last_build").stat().st_mtime
),
"redirect_from": request.GET.get("from", None),
}