Skip to content
Open
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
8 changes: 4 additions & 4 deletions djangoproject/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)

try:
with DATA_DIR.joinpath("conf", "secrets.json").open() as handle:
with (DATA_DIR / "conf" / "secrets.json").open() as handle:
SECRETS = json.load(handle)
except OSError:
SECRETS = {
Expand Down Expand Up @@ -54,7 +54,7 @@
DEFAULT_FROM_EMAIL = "[email protected]"
FUNDRAISING_DEFAULT_FROM_EMAIL = "[email protected]"

FIXTURE_DIRS = [str(PROJECT_PACKAGE.joinpath("fixtures"))]
FIXTURE_DIRS = [PROJECT_PACKAGE / "fixtures"]

INSTALLED_APPS = [
"accounts",
Expand Down Expand Up @@ -184,7 +184,7 @@

SITE_ID = 1

STATICFILES_DIRS = [str(PROJECT_PACKAGE.joinpath("static"))]
STATICFILES_DIRS = [PROJECT_PACKAGE / "static"]

STATIC_URL = "/s/"

Expand All @@ -196,7 +196,7 @@
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [str(PROJECT_PACKAGE.joinpath("templates"))],
"DIRS": [PROJECT_PACKAGE / "templates"],
"APP_DIRS": True,
"OPTIONS": {
"builtins": [
Expand Down
6 changes: 3 additions & 3 deletions djangoproject/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@

EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

MEDIA_ROOT = str(DATA_DIR.joinpath("media_root"))
MEDIA_ROOT = DATA_DIR / "media_root"

SESSION_COOKIE_SECURE = False

STATIC_ROOT = str(DATA_DIR.joinpath("static_root"))
STATIC_ROOT = DATA_DIR / "static_root"

# Docs settings
DOCS_BUILD_ROOT = DATA_DIR.joinpath("djangodocs")
DOCS_BUILD_ROOT = DATA_DIR / "djangodocs"

# django-hosts settings

Expand Down
6 changes: 3 additions & 3 deletions djangoproject/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}
LOGGING["loggers"]["django.request"]["handlers"].append("syslog")

MEDIA_ROOT = str(DATA_DIR.joinpath("media"))
MEDIA_ROOT = DATA_DIR / "media"

MEDIA_URL = f"https://media.{DOMAIN_NAME}/"

Expand All @@ -61,12 +61,12 @@
},
}

STATIC_ROOT = str(DATA_DIR.joinpath("static"))
STATIC_ROOT = DATA_DIR / "static"

STATIC_URL = f"https://static.{DOMAIN_NAME}/"

# Docs settings
DOCS_BUILD_ROOT = DATA_DIR.joinpath("data", "docbuilds")
DOCS_BUILD_ROOT = DATA_DIR / "data" / "docbuilds"

# django-hosts settings

Expand Down
35 changes: 17 additions & 18 deletions docs/management/commands/update_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,8 @@ def build_doc_release(self, release, force=False, interactive=False):
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():
Expand All @@ -159,20 +157,21 @@ def build_doc_release(self, release, force=False, interactive=False):
)
return

source_dir = checkout_dir.joinpath("docs")
source_dir = checkout_dir / "docs"

if release.lang != "en":
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
Expand All @@ -189,7 +188,7 @@ def build_doc_release(self, release, force=False, interactive=False):
#
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)
Expand All @@ -207,7 +206,7 @@ def build_doc_release(self, release, force=False, interactive=False):
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)
Expand All @@ -232,9 +231,9 @@ def build_doc_release(self, release, force=False, interactive=False):
# 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:
Expand All @@ -257,8 +256,8 @@ def zipfile_inclusion_filter(file_path):
# 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",
Expand All @@ -273,7 +272,7 @@ def zipfile_inclusion_filter(file_path):
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)

Expand All @@ -287,7 +286,7 @@ def update_git(self, url, destdir, changed_dir="."):
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:
Expand Down
4 changes: 1 addition & 3 deletions docs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ def sync_to_db(self, decoded_documents):
self.documents.all().delete()

# Read excluded paths from robots.docs.txt.
robots_path = settings.BASE_DIR.joinpath(
"djangoproject", "static", "robots.docs.txt"
)
robots_path = settings.BASE_DIR / "djangoproject" / "static" / "robots.docs.txt"
with open(str(robots_path)) as fh:
excluded_paths = [
line.strip().split("/")[-1]
Expand Down
6 changes: 2 additions & 4 deletions docs/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,8 @@ def test_excluded_documents(self):
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
Expand Down
4 changes: 2 additions & 2 deletions docs/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def test_get_all_doc_versions_empty(self):
def test_get_all_doc_versions(self):
tmp_docs_build_root = Path(tempfile.mkdtemp())
self.addCleanup(shutil.rmtree, tmp_docs_build_root)
os.makedirs(tmp_docs_build_root.joinpath("en", "1.8", "_built", "json"))
os.makedirs(tmp_docs_build_root.joinpath("en", "1.11", "_built", "json"))
os.makedirs(tmp_docs_build_root / "en" / "1.8" / "_built" / "json")
os.makedirs(tmp_docs_build_root / "en" / "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"])

Expand Down
7 changes: 4 additions & 3 deletions docs/utils.py
Original file line number Diff line number Diff line change
@@ -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"):
Expand All @@ -22,15 +23,15 @@ 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
except NotADirectoryError:
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

Expand Down
4 changes: 2 additions & 2 deletions docs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def load_json_file(path):

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,
Expand All @@ -91,7 +91,7 @@ def load_json_file(path):
"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),
}
Expand Down
2 changes: 1 addition & 1 deletion fundraising/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def setUp(self):
)

def stripe_data(self, filename):
file_path = settings.BASE_DIR.joinpath(f"fundraising/test_data/{filename}.json")
file_path = settings.BASE_DIR / f"fundraising/test_data/{filename}.json"
with file_path.open() as f:
data = json.load(f)
return stripe.convert_to_stripe_object(data, stripe.api_key, None)
Expand Down