Skip to content

Commit

Permalink
Merge branch 'development' into maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
pvcraven committed Jan 25, 2025
2 parents 1a4bebd + cda4761 commit dfa12ce
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 29 deletions.
4 changes: 2 additions & 2 deletions doc/_includes/resources_Top-Level_Resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ This logo of the snake doubles as a quick way to test Arcade's resource handles.
.. raw:: html

<ol>
<li>Look down toward the Arcade logo below until you see the file name<li>
<li>Look down toward the Arcade logo below until you see the file name</li>
<li>Look to the right edge of the file name (<code class="docutils literal notranslate"><span class="pre">'logo.png'</span></code>)</li>
<li>There should be a copy button <(<div class="arcade-ezcopy doc-ui-example-dummy" style="display: inline-block;">
<li>There should be a copy button (<div class="arcade-ezcopy doc-ui-example-dummy" style="display: inline-block;">
<img src="/_static/icons/tabler/copy.svg"></div>) </li>
<li>Click or tap it.</li>
</ol>
Expand Down
69 changes: 55 additions & 14 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Sphinx configuration file"""
from __future__ import annotations

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


# Grab readthedocs env variables for logging + use
# https://docs.readthedocs.com/platform/stable/reference/environment-variables.html
# Their GH comments suggest they want to move away from "magic" injection as
# part of the readthedocs theme, so this seems like the best option for us.
log.info(" Env variables...")
col_width = max(map(len, os.environ.keys()))
READTHEDOCS = dict()
ENV = dict()
for k, v in os.environ.items():
if k.startswith('READTHEDOCS_'):
READTHEDOCS[k.removeprefix('READTHEDOCS_')] = v
ENV[k] = v

from util.doc_helpers.real_filesystem import copy_media


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

print()
for k, v in ENV.items():
log.info(f"Env variable {k:{col_width}} : {v!r}")

# _temp_version = (REPO_LOCAL_ROOT / "arcade" / "VERSION").read_text().replace("-",'')

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


# Check whether the version ends in an all-digit string
VERSION_PARTS = []
ARCADE_VERSION_PARTS = []
for part in VERSION.split('.'):
if part.isdigit():
VERSION_PARTS.append(int(part))
ARCADE_VERSION_PARTS.append(part)
else:
VERSION_PARTS.append(part)
ARCADE_VERSION_PARTS.append(part)

print()
if VERSION_PARTS[-1].isdigit():
GIT_REF = VERSION
log.info(" !!!!! APPEARS TO BE A REAL RELEASE !!!!!")
GIT_REF = 'development'
if READTHEDOCS:
if READTHEDOCS.get('VERSION') in ('latest', 'stable'):
log.info(" !!!!! APPEARS TO BE A REAL RELEASE !!!!!")
else:
log.info(" +++++ Building a PR or development +++++")
else:
GIT_REF = 'development'
log.info(" - - - Building as a dev release - - -")

print()
print(f" {GIT_REF=!r}")
print(f" {VERSION=!r}")
log.info(" - - - Building outside readthedocs +++++")
print()


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

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

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


OUT_STATIC = REPO_LOCAL_ROOT / 'build/html/_static/'

src_res_dir = ARCADE_MODULE / 'resources/assets'
out_res_dir = REPO_LOCAL_ROOT / 'build/html/_static/assets'

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

# We are no longer asking. We are copying.
copy_media(
REPO_LOCAL_ROOT / "doc/_static/icons",
OUT_STATIC / "icons" ,
{
'tabler': ("*.svg",)
}
)
copy_media(
REPO_LOCAL_ROOT / "doc/_static/",
OUT_STATIC ,
{
'filetiles': ("*.png",)
}
)
#copy_media(
# REP / ""
#)


autodoc_inherit_docstrings = False
autodoc_default_options = {
Expand Down
31 changes: 20 additions & 11 deletions util/create_resources_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def announce_templating(var_name):

# The following are provided via runpy.run_path's init_globals keyword
# in conf.py. Uncomment for easy debugger run without IDE config.
_ = RTD_EVIL # noqa # explode ASAP or the links will all be broken
log.info(f" RTD EVIL: {RTD_EVIL!r}") # noqa
try:

_ = GIT_REF # noqa
except Exception as _:
GIT_REF = "development"
Expand All @@ -61,6 +64,10 @@ def announce_templating(var_name):
announce_templating("FMT_URL_REF_EMBED")


def src_kludge(strpath): # pending: post-3.0 cleanup: # evil evil evil evil
"""We inject what RTD says the canonical domain is up top + the version"""
return f"{RTD_EVIL}{strpath}"

MODULE_DIR = Path(__file__).parent.resolve()
ARCADE_ROOT = MODULE_DIR.parent
RESOURCE_DIR = ARCADE_ROOT / "arcade" / "resources"
Expand Down Expand Up @@ -477,7 +484,7 @@ def indent( # pending: post-3.0 refactor # why would indent come after the tex
return new.getvalue()

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


Expand All @@ -489,13 +496,15 @@ def html_copyable(
if string_quote_char:
value = f"{string_quote_char}{value}{string_quote_char}"
escaped = html.escape(value)
# src = src_kludge(COPY_BUTTON_PATH)
src = FMT_URL_REF_EMBED.format(COPY_BUTTON_PATH)
raw = (
f"<span class=\"resource-handle\">\n"
f" <code class=\"docutils literal notranslate\">\n"
f" <span class=\"pre\">{escaped}</span>\n"
f" </code>\n"
f" <button class=\"arcade-ezcopy\" data-clipboard-text=\"{resource_handle}\">\n"
f" <img src=\"/{COPY_BUTTON_PATH}\"/>\n"
f" <img src=\"{COPY_BUTTON_PATH}\"/>\n"
# + indent(" " * 2, COPY_BUTTON_RAW) + # pending: post-3.0 cleanup
f" </button>\n"
f"</span>\n"
Expand Down Expand Up @@ -621,17 +630,16 @@ def do_filetile(out, suffix: str | None = None, state: str = None):
p = FILETILE_DIR / f"type-{suffix.strip('.')}.png"
log.info(f" FILETILE: {p}")
if p.exists():
print(" KNOWN!")
print(f" KNOWN! {p.name!r}")
name = p.name
else:
name = f"type-unknown.png"
print(" ... unknown :(")
else:
name = "state-error.png"

out.write(indent(f" ",
f".. raw:: html\n\n"
f" <img class=\"resource-thumb\" src=\"/_static/filetiles/{name}\"/>\n\n"))
f" <img class=\"resource-thumb\" src=\"{src_kludge('/_static/filetiles/' + name)}\"/>\n\n"))


def process_resource_files(
Expand Down Expand Up @@ -712,9 +720,9 @@ def start():
config = MEDIA_EMBED[suffix]
kind = config.get('media_kind')
mime_suffix = config.get('mime_suffix')
# file_path = FMT_URL_REF_EMBED.format(resource_path)
rel = path.relative_to(RESOURCE_DIR)
file_path = f"/_static/{str(rel)}"
file_path = FMT_URL_REF_EMBED.format(resource_path)
#rel = path.relative_to(RESOURCE_DIR)
#file_path = src_kludge(f"/_static/{str(rel)}")
out.write(f" {start()} - .. raw:: html\n\n")
out.write(indent(
" ", resource_copyable))
Expand All @@ -723,7 +731,8 @@ def start():
out.write(indent(" ",
# Using preload="none" is gentler on GitHub and readthedocs
f"<{kind} class=\"resource-thumb\" controls preload=\"none\">\n"
f" <source src='{file_path}' type='{kind}/{mime_suffix}'>\n"
f" <source src=\"{file_path}\" type=\"{kind}/{mime_suffix}\">\n"
f" <source src=\"{src_kludge(file_path)}\" type=\"{kind}/{mime_suffix}\">\n"
f"</{kind}>\n\n"))

# Fonts
Expand All @@ -743,7 +752,7 @@ def start():

# File tiles we don't have previews for
else:# suffix == ".json":
file_path = FMT_URL_REF_PAGE.format(resource_path)
# file_path = FMT_URL_REF_PAGE.format(resource_path)
out.write(f" {start()} - .. raw:: html\n\n")
out.write(indent(" ",
resource_copyable))
Expand Down Expand Up @@ -802,7 +811,7 @@ def resources():
f" <ol>\n"
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"
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;\">"
f"<img src=\"/_static/icons/tabler/copy.svg\"></div>)</li>\n"
f"<img src=\"{src_kludge('/_static/icons/tabler/copy.svg')}\"></div>)</li>\n"
f" </ol>\n\n"
+
"Click the button above a preview to copy the **resource handle** string for loading the asset.\n"
Expand Down
5 changes: 3 additions & 2 deletions util/doc_helpers/real_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

FILE = Path(__file__)
REPO_ROOT = Path(__file__).parent.parent.resolve()
log = logging.getLogger(str(FILE.relative_to(REPO_ROOT)))
log = logging.getLogger(FILE.name)


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

shutil.copyfile(src_file, dest_file)

else:
log.info(f" Skipping media file {src_file} to {dest_file}")

def copy_media(
src_root: Path | str,
Expand Down

0 comments on commit dfa12ce

Please sign in to comment.