Skip to content

Commit f8922a5

Browse files
committed
extract documentation URL from frozen directory README.rst
1 parent e08502f commit f8922a5

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

docs/shared_bindings_matrix.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
"""Files and dirs at the root of a frozen directory that should be ignored.
7171
This is the same list as in the preprocess_frozen_modules script."""
7272

73+
repository_urls = {}
74+
"""Cache of repository URLs for frozen modules."""
75+
7376
def get_circuitpython_root_dir():
7477
""" The path to the root './circuitpython' directory
7578
"""
@@ -168,15 +171,38 @@ def get_settings_from_makefile(port_dir, board_name):
168171
return settings
169172

170173
def get_repository_url(directory):
171-
contents = subprocess.run(
172-
["git", "remote", "get-url", "origin"],
173-
encoding="utf-8",
174-
errors="replace",
175-
stdout=subprocess.PIPE,
176-
stderr=subprocess.PIPE,
177-
cwd=directory
178-
)
179-
return contents.stdout.strip()
174+
if directory in repository_urls:
175+
return repository_urls[directory]
176+
readme = None
177+
for readme_path in (
178+
os.path.join(directory, "README.rst"),
179+
os.path.join(os.path.dirname(directory), "README.rst")
180+
):
181+
if os.path.exists(readme_path):
182+
readme = readme_path
183+
break
184+
path = None
185+
if readme:
186+
with open(readme, "r") as fp:
187+
for line in fp.readlines():
188+
if m := re.match("\s+:target:\s+(http\S+(docs.circuitpython|readthedocs)\S+)\s*", line):
189+
path = m.group(1)
190+
break
191+
if m := re.search("<(http[^>]+)>", line):
192+
path = m.group(1)
193+
break
194+
if path is None:
195+
contents = subprocess.run(
196+
["git", "remote", "get-url", "origin"],
197+
encoding="utf-8",
198+
errors="replace",
199+
stdout=subprocess.PIPE,
200+
stderr=subprocess.PIPE,
201+
cwd=directory
202+
)
203+
path = contents.stdout.strip()
204+
repository_urls[directory] = path
205+
return path
180206

181207
def frozen_modules_from_dirs(frozen_mpy_dirs):
182208
"""

docs/static/filter.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
.support-matrix-table .reference.external {
1212
box-sizing: border-box;
1313
font-weight: 700;
14-
color: #404050;
14+
color: #404040;
1515
font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace;
1616
padding: 2px 5px;
1717
background: white;

0 commit comments

Comments
 (0)