Skip to content

Commit d672539

Browse files
authored
Fix CSS breakage for instructions and embeds ahead of 3.0 (#2520)
* Temp-fix brittle dev release name handling * Syncs sound, music, and video now * Comment out ref generation for embeds * Clean up embed code * Add anti-preload hints * Temp fix copy buttons of both kinds * Clean up some support code * Clean up conf.py + move things to a utils item * Comments * Fix resource handle copyables for smaller display ports * Get resource page cleaned up with usage instructions * Fix CSS * Fix generation and add explanation of videos * Some proofreading and experimental warnings * Remove big commented-out block
1 parent b07f43f commit d672539

File tree

7 files changed

+314
-65
lines changed

7 files changed

+314
-65
lines changed
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
This logo of the snake doubles as a quick way to test Arcade's resource handles.
22

3-
#. Mouse over the copy button (|Example Copy Button|) below
4-
#. It should change color to indicate you've hovered
5-
#. Click to copy
3+
.. raw:: html
64

7-
Paste in your favorite text editor!
5+
<ol>
6+
<li>Look down toward the Arcade logo below until you see the file name<li>
7+
<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;">
9+
<img src="/_static/icons/tabler/copy.svg"></div>) </li>
10+
<li>Click or tap it.</li>
11+
</ol>
812

13+
Click the button or tap it if you're on mobile. Then try pasting in your favorite text editor. It
14+
should look like this::
15+
16+
':resources:/logo.png'
17+
18+
This string is what Arcade calls a **:ref:`resource handle <resource_handles>`**. They let you load
19+
images, sound, and other data without worrying about where exactly data is on a computer. To learn
20+
more, including how to define your own handle prefix, see :ref:`resource_handles`.
21+
22+
To get started with game code right away, please see the following:
23+
24+
* :ref:`example-code`
25+
* :ref:`main-page-tutorials`

doc/_includes/resources_Video.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. _resources_video:
2+
3+
Video
4+
-----
5+
6+
Arcade offers experimental support for video playback through :py:mod:`pyglet` and other libraries.
7+
8+
.. warning:: These features are works-in-progress!
9+
10+
Please the following to learn more:
11+
12+
* :ref:`future_api`
13+
* The undocumented `experimental folder <https://github.com/pythonarcade/arcade/tree/development/arcade/experimental>`_
14+
15+
To make testing easier, Arcade includes the small video file embedded below. However, runnign the
16+
examples below may require installing both :ref:`guide-supportedmedia-ffmpeg` and additional libraries:
17+
18+
* The `cv2-based video examples <https://github.com/pythonarcade/arcade/blob/development/arcade/future/video/>`_
19+
* The `cv2-based shadertoy example <https://github.com/pythonarcade/arcade/blob/development/arcade/experimental/shadertoy_video_cv2.py>`_
20+
21+
The links above use the unstable development branch of Arcade to gain access to the latest :py:mod:`pyglet`
22+
and Arcade features. If you have questions or want to help develop these examples further, we'd love to hear
23+
from you. The Arcade `Discord server <Arcade Discord>`_ and `GitHub repository <Arcade GitHub>`_ always welcome
24+
new community members.

doc/_static/css/custom.css

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,18 @@ table.resource-table td > .resource-thumb.file-icon {
262262

263263

264264
.resource-handle {
265-
display: inline-block;
265+
/* Flex props keep this all on one line when the viewport with's small */
266+
display: inline-flex;
267+
flex-direction: row;
268+
flex-shrink: 0;
269+
270+
/* Make the button round so it's nice-looking */
266271
border-radius: 0.4em;
267272
border: 1px solid rgb(0, 0, 0, 0);
273+
268274
width: fit-content !important;
269275
}
276+
270277
.resource-handle:has(button.arcade-ezcopy:hover) {
271278
border-color: #54c079;
272279
color: #54c079;
@@ -314,20 +321,28 @@ table.resource-table td > .resource-thumb.file-icon {
314321
.resource-table * > .literal:has(+ button.arcade-ezcopy) {
315322
border-radius: 0.4em 0 0 0.4em !important;
316323
}
317-
.resource-table .literal + button.arcade-ezcopy {
324+
.resource-table * > .literal + button.arcade-ezcopy {
318325
border-radius: 0 0.4em 0.4em 0 !important;
319326
}
320327

321328

322-
323-
.arcade-ezcopy > img {
329+
.arcade-ezcopy > *:is(img, svg) {
324330
margin: 0;
325331
width: 100%;
332+
max-width: 100%;
326333
height: 100%;
334+
max-height: 100%;
327335
}
328336
.arcade-ezcopy:hover {
329337
background-color: #54c079;
330338
}
339+
/* Give it some breathing room inside the inline HTML we're using for the moment
340+
# pending: post-3.0 clean-up
341+
*/
342+
li .arcade-ezcopy.doc-ui-example-dummy {
343+
margin-left: 0.2em;
344+
margin-right: 0.2em;
345+
}
331346

332347
table.colorTable {
333348
border-width: 1px;

doc/_static/icons/tabler/copy.svg

Lines changed: 1 addition & 0 deletions
Loading

doc/conf.py

Lines changed: 69 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
#!/usr/bin/env python
22
"""Sphinx configuration file"""
33
from __future__ import annotations
4+
45
from functools import cache
56
import logging
67
from pathlib import Path
7-
from textwrap import dedent
88
from typing import Any, NamedTuple
9-
import docutils.nodes
10-
import os
119
import re
1210
import runpy
13-
import sphinx.ext.autodoc
14-
import sphinx.transforms
1511
import sys
1612

1713
from docutils import nodes
18-
from docutils.nodes import literal
1914
from sphinx.util.docutils import SphinxRole
2015

16+
HERE = Path(__file__).resolve()
17+
REPO_LOCAL_ROOT = HERE.parent.parent
18+
ARCADE_MODULE = REPO_LOCAL_ROOT / "arcade"
19+
UTIL_DIR = REPO_LOCAL_ROOT / "util"
20+
21+
log = logging.getLogger('conf.py')
22+
logging.basicConfig(level=logging.INFO)
23+
24+
sys.path.insert(0, str(REPO_LOCAL_ROOT))
25+
sys.path.insert(0, str(ARCADE_MODULE))
26+
log.info(f"Inserted elements in system path: First two are now:")
27+
for i in range(2):
28+
log.info(f" {i}: {sys.path[i]!r}")
29+
30+
from util.doc_helpers.real_filesystem import copy_media
31+
2132
# As of pyglet==2.1.dev7, this is no longer set in pyglet/__init__.py
2233
# because Jupyter / IPython always load Sphinx into sys.modules. See
2334
# the following for more info:
@@ -27,44 +38,47 @@
2738

2839
# --- Pre-processing Tasks
2940

30-
log = logging.getLogger('conf.py')
31-
logging.basicConfig(level=logging.INFO)
32-
33-
HERE = Path(__file__).resolve()
34-
REPO_LOCAL_ROOT = HERE.parent.parent
35-
36-
ARCADE_MODULE = REPO_LOCAL_ROOT / "arcade"
37-
UTIL_DIR = REPO_LOCAL_ROOT / "util"
38-
41+
# Report our diagnostic info
3942
log.info(f"Absolute path for our conf.py : {str(HERE)!r}")
4043
log.info(f"Absolute path for the repo root : {str(REPO_LOCAL_ROOT)!r}")
4144
log.info(f"Absolute path for the arcade module : {str(REPO_LOCAL_ROOT)!r}")
4245
log.info(f"Absolute path for the util dir : {str(UTIL_DIR)!r}")
4346

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

46-
sys.path.insert(0, str(REPO_LOCAL_ROOT))
47-
sys.path.insert(0, str(ARCADE_MODULE))
48-
log.info(f"Inserted elements in system path: First two are now:")
49-
for i in range(2):
50-
log.info(f" {i}: {sys.path[i]!r}")
51-
5249
# Don't change to
5350
# from arcade.version import VERSION
5451
# or read the docs build will fail.
5552
from version import VERSION # pyright: ignore [reportMissingImports]
56-
log.info(f"Got version {VERSION!r}")
53+
log.info(f" Got version {VERSION!r}")
5754

58-
REPO_URL_BASE="https://github.com/pythonarcade/arcade"
59-
if 'dev' in VERSION:
60-
GIT_REF = 'development'
61-
log.info(f"Got .dev release: using {GIT_REF!r}")
62-
else:
55+
56+
# Check whether the version ends in an all-digit string
57+
VERSION_PARTS = []
58+
for part in VERSION.split('.'):
59+
if part.isdigit():
60+
VERSION_PARTS.append(int(part))
61+
else:
62+
VERSION_PARTS.append(part)
63+
64+
print()
65+
if VERSION_PARTS[-1].isdigit():
6366
GIT_REF = VERSION
64-
log.info(f"Got real release: using {GIT_REF!r}")
67+
log.info(" !!!!! APPEARS TO BE A REAL RELEASE !!!!!")
68+
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}")
75+
print()
76+
6577

6678
# We'll pass this to our generation scripts to initialize their globals
79+
REPO_URL_BASE="https://github.com/pythonarcade/arcade"
6780
FMT_URL_REF_BASE=f"{REPO_URL_BASE}/blob/{GIT_REF}"
81+
6882
RESOURCE_GLOBALS = dict(
6983
GIT_REF=GIT_REF,
7084
BASE_URL_REPO=REPO_URL_BASE,
@@ -104,6 +118,22 @@ def run_util(filename, run_name="__main__", init_globals=None):
104118
# Run the generate quick API index script
105119
run_util('../util/update_quick_index.py')
106120

121+
122+
src_res_dir = ARCADE_MODULE / 'resources/assets'
123+
out_res_dir = REPO_LOCAL_ROOT / 'build/html/_static/assets'
124+
125+
# pending: post-3.0 cleanup to find the right source events to make this work?
126+
# if exc or app.builder.format != "html":
127+
# return
128+
# static_dir = (app.outdir / '_static').resolve()
129+
copy_what = { # pending: post-3.0 cleanup to tie this into resource generation correctly
130+
'sounds': ('*.wav', '*.ogg', '*.mp3'),
131+
'music': ('*.wav', '*.ogg', '*.mp3'),
132+
'video': ('*.mp4', '*.webm', )
133+
}
134+
copy_media(src_res_dir, out_res_dir, copy_what)
135+
136+
107137
autodoc_inherit_docstrings = False
108138
autodoc_default_options = {
109139
'members': True,
@@ -136,6 +166,12 @@ def run_util(filename, run_name="__main__", init_globals=None):
136166
'doc.extensions.prettyspecialmethods', # Forker plugin for prettifying special methods
137167
]
138168

169+
# pending: post-3.0 cleanup:
170+
# 1. Setting this breaks the CSS for both the plugin's buttons and our "custom" ones
171+
# 2. Since our custom ones are only on the gui page for now, it's okay
172+
# Note: tabler doesn't require attribution + it's the original theme for this icon set
173+
# copybutton_image_svg = (REPO_LOCAL_ROOT / "doc/_static/icons/tabler/copy.svg").read_text()
174+
139175
# Add any paths that contain templates here, relative to this directory.
140176
templates_path = ['_templates']
141177

@@ -272,7 +308,6 @@ def run_util(filename, run_name="__main__", init_globals=None):
272308
rst_prolog = "\n".join(PROLOG_PARTS)
273309

274310

275-
276311
def strip_init_return_typehint(app, what, name, obj, options, signature, return_annotation):
277312
# Prevent a the `-> None` annotation from appearing after classes.
278313
# This annotation comes from the `__init__`, but it renders on the class,
@@ -281,6 +316,7 @@ def strip_init_return_typehint(app, what, name, obj, options, signature, return_
281316
if what == "class" and return_annotation is None:
282317
return (signature, None)
283318

319+
284320
def inspect_docstring_for_member(
285321
_app,
286322
what: str,
@@ -407,7 +443,6 @@ def on_autodoc_process_bases(app, name, obj, options, bases):
407443
bases[:] = [base for base in bases if base is not object]
408444

409445

410-
411446
class A(NamedTuple):
412447
dirname: str
413448
comment: str = ""
@@ -439,7 +474,7 @@ def run(self) -> tuple[list[nodes.Node], list[nodes.system_message]]:
439474
'/api_docs/resources.html#', page_id]),
440475
)
441476

442-
print("HALP?", locals())
477+
log.info(" Attempted ResourceRole", locals())
443478
return [node], []
444479

445480

@@ -452,6 +487,7 @@ def setup(app):
452487
print(f" {comment}")
453488

454489
# Separate stylesheets loosely by category.
490+
# pending: sphinx >= 8.1.4 to remove the sphinx_static_file_temp_fix.py
455491
app.add_css_file("css/colors.css")
456492
app.add_css_file("css/layout.css")
457493
app.add_css_file("css/custom.css")
@@ -467,6 +503,8 @@ def setup(app):
467503
app.connect('autodoc-process-bases', on_autodoc_process_bases)
468504
# app.add_transform(Transform)
469505
app.add_role('resource', ResourceRole())
506+
# Don't do anything that can fail on this event or it'll kill your build hard
507+
# app.connect('build-finished', throws_exception)
470508

471509
# ------------------------------------------------------
472510
# Old hacks that breaks the api docs. !!! DO NOT USE !!!

0 commit comments

Comments
 (0)