Skip to content

Commit dfa12ce

Browse files
committed
Merge branch 'development' into maintenance
2 parents 1a4bebd + cda4761 commit dfa12ce

File tree

4 files changed

+80
-29
lines changed

4 files changed

+80
-29
lines changed

doc/_includes/resources_Top-Level_Resources.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ This logo of the snake doubles as a quick way to test Arcade's resource handles.
33
.. raw:: html
44

55
<ol>
6-
<li>Look down toward the Arcade logo below until you see the file name<li>
6+
<li>Look down toward the Arcade logo below until you see the file name</li>
77
<li>Look to the right edge of the file name (<code class="docutils literal notranslate"><span class="pre">'logo.png'</span></code>)</li>
8-
<li>There should be a copy button <(<div class="arcade-ezcopy doc-ui-example-dummy" style="display: inline-block;">
8+
<li>There should be a copy button (<div class="arcade-ezcopy doc-ui-example-dummy" style="display: inline-block;">
99
<img src="/_static/icons/tabler/copy.svg"></div>) </li>
1010
<li>Click or tap it.</li>
1111
</ol>

doc/conf.py

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""Sphinx configuration file"""
33
from __future__ import annotations
44

5+
import os
56
from functools import cache
67
import logging
78
from pathlib import Path
@@ -27,8 +28,23 @@
2728
for i in range(2):
2829
log.info(f" {i}: {sys.path[i]!r}")
2930

31+
32+
# Grab readthedocs env variables for logging + use
33+
# https://docs.readthedocs.com/platform/stable/reference/environment-variables.html
34+
# Their GH comments suggest they want to move away from "magic" injection as
35+
# part of the readthedocs theme, so this seems like the best option for us.
36+
log.info(" Env variables...")
37+
col_width = max(map(len, os.environ.keys()))
38+
READTHEDOCS = dict()
39+
ENV = dict()
40+
for k, v in os.environ.items():
41+
if k.startswith('READTHEDOCS_'):
42+
READTHEDOCS[k.removeprefix('READTHEDOCS_')] = v
43+
ENV[k] = v
44+
3045
from util.doc_helpers.real_filesystem import copy_media
3146

47+
3248
# As of pyglet==2.1.dev7, this is no longer set in pyglet/__init__.py
3349
# because Jupyter / IPython always load Sphinx into sys.modules. See
3450
# the following for more info:
@@ -44,6 +60,10 @@
4460
log.info(f"Absolute path for the arcade module : {str(REPO_LOCAL_ROOT)!r}")
4561
log.info(f"Absolute path for the util dir : {str(UTIL_DIR)!r}")
4662

63+
print()
64+
for k, v in ENV.items():
65+
log.info(f"Env variable {k:{col_width}} : {v!r}")
66+
4767
# _temp_version = (REPO_LOCAL_ROOT / "arcade" / "VERSION").read_text().replace("-",'')
4868

4969
# Don't change to
@@ -52,26 +72,23 @@
5272
from version import VERSION # pyright: ignore [reportMissingImports]
5373
log.info(f" Got version {VERSION!r}")
5474

55-
5675
# Check whether the version ends in an all-digit string
57-
VERSION_PARTS = []
76+
ARCADE_VERSION_PARTS = []
5877
for part in VERSION.split('.'):
5978
if part.isdigit():
60-
VERSION_PARTS.append(int(part))
79+
ARCADE_VERSION_PARTS.append(part)
6180
else:
62-
VERSION_PARTS.append(part)
81+
ARCADE_VERSION_PARTS.append(part)
6382

6483
print()
65-
if VERSION_PARTS[-1].isdigit():
66-
GIT_REF = VERSION
67-
log.info(" !!!!! APPEARS TO BE A REAL RELEASE !!!!!")
84+
GIT_REF = 'development'
85+
if READTHEDOCS:
86+
if READTHEDOCS.get('VERSION') in ('latest', 'stable'):
87+
log.info(" !!!!! APPEARS TO BE A REAL RELEASE !!!!!")
88+
else:
89+
log.info(" +++++ Building a PR or development +++++")
6890
else:
69-
GIT_REF = 'development'
70-
log.info(" - - - Building as a dev release - - -")
71-
72-
print()
73-
print(f" {GIT_REF=!r}")
74-
print(f" {VERSION=!r}")
91+
log.info(" - - - Building outside readthedocs +++++")
7592
print()
7693

7794

@@ -80,11 +97,14 @@
8097
FMT_URL_REF_BASE=f"{REPO_URL_BASE}/blob/{GIT_REF}"
8198

8299
RESOURCE_GLOBALS = dict(
83-
GIT_REF=GIT_REF,
100+
GIT_REF=GIT_REF, # pending: post-3.0 clean-up, not sure if things use it now?
101+
# This may be more useful according to some doc? (It's unclear)
102+
# https://docs.readthedocs.com/platform/stable/reference/environment-variables.html#envvar-READTHEDOCS_GIT_COMMIT_HASH
84103
BASE_URL_REPO=REPO_URL_BASE,
85104
# This double-bracket escapes brackets in f-strings
86105
FMT_URL_REF_PAGE=f"{FMT_URL_REF_BASE}/{{}}",
87106
FMT_URL_REF_EMBED=f"{FMT_URL_REF_BASE}/{{}}?raw=true",
107+
RTD_EVIL=READTHEDOCS['CANONICAL_URL'] if READTHEDOCS else "" # pending: post-3.0 cleanup
88108
)
89109

90110
def run_util(filename, run_name="__main__", init_globals=None):
@@ -119,6 +139,8 @@ def run_util(filename, run_name="__main__", init_globals=None):
119139
run_util('../util/update_quick_index.py')
120140

121141

142+
OUT_STATIC = REPO_LOCAL_ROOT / 'build/html/_static/'
143+
122144
src_res_dir = ARCADE_MODULE / 'resources/assets'
123145
out_res_dir = REPO_LOCAL_ROOT / 'build/html/_static/assets'
124146

@@ -133,6 +155,25 @@ def run_util(filename, run_name="__main__", init_globals=None):
133155
}
134156
copy_media(src_res_dir, out_res_dir, copy_what)
135157

158+
# We are no longer asking. We are copying.
159+
copy_media(
160+
REPO_LOCAL_ROOT / "doc/_static/icons",
161+
OUT_STATIC / "icons" ,
162+
{
163+
'tabler': ("*.svg",)
164+
}
165+
)
166+
copy_media(
167+
REPO_LOCAL_ROOT / "doc/_static/",
168+
OUT_STATIC ,
169+
{
170+
'filetiles': ("*.png",)
171+
}
172+
)
173+
#copy_media(
174+
# REP / ""
175+
#)
176+
136177

137178
autodoc_inherit_docstrings = False
138179
autodoc_default_options = {

util/create_resources_listing.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ def announce_templating(var_name):
4343

4444
# The following are provided via runpy.run_path's init_globals keyword
4545
# in conf.py. Uncomment for easy debugger run without IDE config.
46+
_ = RTD_EVIL # noqa # explode ASAP or the links will all be broken
47+
log.info(f" RTD EVIL: {RTD_EVIL!r}") # noqa
4648
try:
49+
4750
_ = GIT_REF # noqa
4851
except Exception as _:
4952
GIT_REF = "development"
@@ -61,6 +64,10 @@ def announce_templating(var_name):
6164
announce_templating("FMT_URL_REF_EMBED")
6265

6366

67+
def src_kludge(strpath): # pending: post-3.0 cleanup: # evil evil evil evil
68+
"""We inject what RTD says the canonical domain is up top + the version"""
69+
return f"{RTD_EVIL}{strpath}"
70+
6471
MODULE_DIR = Path(__file__).parent.resolve()
6572
ARCADE_ROOT = MODULE_DIR.parent
6673
RESOURCE_DIR = ARCADE_ROOT / "arcade" / "resources"
@@ -477,7 +484,7 @@ def indent( # pending: post-3.0 refactor # why would indent come after the tex
477484
return new.getvalue()
478485

479486
# pending: post-3.0 cleanup, I don't have time to make this CSS nice right now.
480-
COPY_BUTTON_PATH = "_static/icons/tabler/copy.svg"
487+
COPY_BUTTON_PATH = "https://raw.githubusercontent.com/pythonarcade/arcade/refs/heads/development/doc/_static/icons/tabler/copy.svg"
481488
#COPY_BUTTON_RAW = (DOC_ROOT / "_static/icons/tabler/copy.svg").read_text().strip() + "\n"
482489

483490

@@ -489,13 +496,15 @@ def html_copyable(
489496
if string_quote_char:
490497
value = f"{string_quote_char}{value}{string_quote_char}"
491498
escaped = html.escape(value)
499+
# src = src_kludge(COPY_BUTTON_PATH)
500+
src = FMT_URL_REF_EMBED.format(COPY_BUTTON_PATH)
492501
raw = (
493502
f"<span class=\"resource-handle\">\n"
494503
f" <code class=\"docutils literal notranslate\">\n"
495504
f" <span class=\"pre\">{escaped}</span>\n"
496505
f" </code>\n"
497506
f" <button class=\"arcade-ezcopy\" data-clipboard-text=\"{resource_handle}\">\n"
498-
f" <img src=\"/{COPY_BUTTON_PATH}\"/>\n"
507+
f" <img src=\"{COPY_BUTTON_PATH}\"/>\n"
499508
# + indent(" " * 2, COPY_BUTTON_RAW) + # pending: post-3.0 cleanup
500509
f" </button>\n"
501510
f"</span>\n"
@@ -621,17 +630,16 @@ def do_filetile(out, suffix: str | None = None, state: str = None):
621630
p = FILETILE_DIR / f"type-{suffix.strip('.')}.png"
622631
log.info(f" FILETILE: {p}")
623632
if p.exists():
624-
print(" KNOWN!")
633+
print(f" KNOWN! {p.name!r}")
625634
name = p.name
626635
else:
627636
name = f"type-unknown.png"
628637
print(" ... unknown :(")
629638
else:
630639
name = "state-error.png"
631-
632640
out.write(indent(f" ",
633641
f".. raw:: html\n\n"
634-
f" <img class=\"resource-thumb\" src=\"/_static/filetiles/{name}\"/>\n\n"))
642+
f" <img class=\"resource-thumb\" src=\"{src_kludge('/_static/filetiles/' + name)}\"/>\n\n"))
635643

636644

637645
def process_resource_files(
@@ -712,9 +720,9 @@ def start():
712720
config = MEDIA_EMBED[suffix]
713721
kind = config.get('media_kind')
714722
mime_suffix = config.get('mime_suffix')
715-
# file_path = FMT_URL_REF_EMBED.format(resource_path)
716-
rel = path.relative_to(RESOURCE_DIR)
717-
file_path = f"/_static/{str(rel)}"
723+
file_path = FMT_URL_REF_EMBED.format(resource_path)
724+
#rel = path.relative_to(RESOURCE_DIR)
725+
#file_path = src_kludge(f"/_static/{str(rel)}")
718726
out.write(f" {start()} - .. raw:: html\n\n")
719727
out.write(indent(
720728
" ", resource_copyable))
@@ -723,7 +731,8 @@ def start():
723731
out.write(indent(" ",
724732
# Using preload="none" is gentler on GitHub and readthedocs
725733
f"<{kind} class=\"resource-thumb\" controls preload=\"none\">\n"
726-
f" <source src='{file_path}' type='{kind}/{mime_suffix}'>\n"
734+
f" <source src=\"{file_path}\" type=\"{kind}/{mime_suffix}\">\n"
735+
f" <source src=\"{src_kludge(file_path)}\" type=\"{kind}/{mime_suffix}\">\n"
727736
f"</{kind}>\n\n"))
728737

729738
# Fonts
@@ -743,7 +752,7 @@ def start():
743752

744753
# File tiles we don't have previews for
745754
else:# suffix == ".json":
746-
file_path = FMT_URL_REF_PAGE.format(resource_path)
755+
# file_path = FMT_URL_REF_PAGE.format(resource_path)
747756
out.write(f" {start()} - .. raw:: html\n\n")
748757
out.write(indent(" ",
749758
resource_copyable))
@@ -802,7 +811,7 @@ def resources():
802811
f" <ol>\n"
803812
f" <li>A <strong>file name</strong> as a single-quoted string (<code class=\"docutils literal notranslate\"><span class=\"pre\">{logo}</span></code>)</li>\n"
804813
f" <li>A <strong>copy button</strong> to the right of the string (<div class=\"arcade-ezcopy doc-ui-example-dummy\" style=\"display: inline-block;\">"
805-
f"<img src=\"/_static/icons/tabler/copy.svg\"></div>)</li>\n"
814+
f"<img src=\"{src_kludge('/_static/icons/tabler/copy.svg')}\"></div>)</li>\n"
806815
f" </ol>\n\n"
807816
+
808817
"Click the button above a preview to copy the **resource handle** string for loading the asset.\n"

util/doc_helpers/real_filesystem.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
FILE = Path(__file__)
1515
REPO_ROOT = Path(__file__).parent.parent.resolve()
16-
log = logging.getLogger(str(FILE.relative_to(REPO_ROOT)))
16+
log = logging.getLogger(FILE.name)
1717

1818

1919
def dest_older(src: Path | str, dest: Path | str) -> bool:
@@ -89,7 +89,8 @@ def sync_dir(src_dir: Path, dest_dir: Path, *globs: str, done: set | None = None
8989
log.info(f' Copying media file {src_file} to {dest_file}')
9090

9191
shutil.copyfile(src_file, dest_file)
92-
92+
else:
93+
log.info(f" Skipping media file {src_file} to {dest_file}")
9394

9495
def copy_media(
9596
src_root: Path | str,

0 commit comments

Comments
 (0)