Skip to content

Commit 9663b2a

Browse files
committed
refactor: Remove auto_examples_config.ini and update download script to use default configuration
1 parent 5c471df commit 9663b2a

File tree

3 files changed

+20
-114
lines changed

3 files changed

+20
-114
lines changed

.github/workflows/generate-examples.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77
- "examples/**"
88
- "docs/conf.py"
99
- "scripts/download_auto_examples.py"
10-
- "scripts/auto_examples_config.ini"
1110
- "requirements*.txt"
1211
- ".github/workflows/generate-examples.yml"
1312
pull_request:
@@ -16,7 +15,6 @@ on:
1615
- "examples/**"
1716
- "docs/conf.py"
1817
- "scripts/download_auto_examples.py"
19-
- "scripts/auto_examples_config.ini"
2018
- "requirements*.txt"
2119
- ".github/workflows/generate-examples.yml"
2220
release:
@@ -43,7 +41,6 @@ jobs:
4341
- 'examples/**'
4442
- 'docs/conf.py'
4543
- 'scripts/download_auto_examples.py'
46-
- 'scripts/auto_examples_config.ini'
4744
- 'requirements*.txt'
4845
- '.github/workflows/generate-examples.yml'
4946
@@ -73,7 +70,7 @@ jobs:
7370
if: needs.detect-changes.outputs.examples-changed == 'true' || needs.detect-changes.outputs.force-build == 'true'
7471
strategy:
7572
matrix:
76-
python-version: ["3.11"] # Use a single version for example generation
73+
python-version: ["3.13.2"]
7774

7875
steps:
7976
- uses: actions/checkout@v4
@@ -311,7 +308,6 @@ jobs:
311308
echo " - examples/**"
312309
echo " - docs/conf.py"
313310
echo " - scripts/download_auto_examples.py"
314-
echo " - scripts/auto_examples_config.ini"
315311
echo " - requirements*.txt"
316312
echo " - .github/workflows/generate-examples.yml"
317313
echo ""

scripts/auto_examples_config.ini

Lines changed: 0 additions & 29 deletions
This file was deleted.

scripts/download_auto_examples.py

Lines changed: 19 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,10 @@
11
#!/usr/bin/env python3
2-
"""Download auto_examples folder for document except Exception as e:
3-
if requests and hasattr(e, 'r except Exception as e:
4-
if requests and hasattr(e, 'response') and e.response is not None:
5-
if e.response.status_code == 404:
6-
log_message("No GitHub releases found or no auto_examples assets available")
7-
else:
8-
log_message(f"Could not check GitHub releases: HTTP {e.response.status_code}")
9-
elif isinstance(e, urllib.error.HTTPError): # urllib error
10-
if e.code == 404:
11-
log_message("No GitHub releases found or no auto_examples assets available")
12-
else:
13-
log_message(f"Could not check GitHub releases: HTTP {e.code} - {e.reason}") # type: ignore[attr-defined]
14-
else:
15-
log_message(f"Could not check GitHub releases: {e}") e.response is not None:
16-
if e.response.status_code == 404:
17-
log_message("No GitHub artifacts found or repository not accessible")
18-
elif e.response.status_code == 403:
19-
log_message("GitHub artifacts require authentication (GITHUB_TOKEN)")
20-
else:
21-
log_message(f"Could not check GitHub artifacts: HTTP {e.response.status_code}")
22-
elif isinstance(e, urllib.error.HTTPError): # urllib error
23-
if e.code == 404:
24-
log_message("No GitHub artifacts found or repository not accessible")
25-
elif e.code == 403:
26-
log_message("GitHub artifacts require authentication (GITHUB_TOKEN)")
27-
else:
28-
log_message(f"Could not check GitHub artifacts: HTTP {e.code} - {e.reason}") # type: ignore[attr-defined]
29-
else:
30-
log_message(f"Could not check GitHub artifacts: {e}")is script downloads the auto_examples folder from a remote source (such as GitHub releases or
31-
artifacts) before documentation builds. It's designed to work both locally and on ReadTheDocs.
2+
"""Download auto_examples folder from a remote source (such as GitHub releases or artifacts) before
3+
documentation builds.
4+
5+
It's designed to work both locally and on ReadTheDocs.
326
"""
337

34-
import configparser
358
import json
369
import os
3710
import shutil
@@ -87,9 +60,17 @@ def check_github_artifacts_for_examples(repo_owner: str, repo_name: str, token:
8760
artifacts_data = json.loads(urllib_response.read().decode())
8861

8962
# Look for recent auto_examples artifacts
90-
for artifact in artifacts_data.get("artifacts", []):
91-
if "auto_examples" in artifact["name"].lower() and not artifact["expired"]:
92-
log_message(f"Found auto_examples artifact: {artifact['name']}")
63+
# Sort by creation date to get the most recent first
64+
artifacts = sorted(
65+
artifacts_data.get("artifacts", []),
66+
key=lambda x: x.get("created_at", ""),
67+
reverse=True,
68+
)
69+
70+
for artifact in artifacts:
71+
name_lower = artifact["name"].lower()
72+
if ("auto_examples" in name_lower or "auto-examples" in name_lower) and not artifact["expired"]:
73+
log_message(f"Found auto_examples artifact: {artifact['name']} (created: {artifact.get('created_at', 'unknown')})")
9374
return artifact["archive_download_url"]
9475

9576
except Exception as e:
@@ -282,13 +263,9 @@ def generate_placeholder_examples(target_dir: Path) -> None:
282263
log_message("Placeholder auto_examples created")
283264

284265

285-
def load_config(script_dir: Path) -> dict[str, bool | int | str]:
286-
"""Load configuration from config file."""
287-
config_file = script_dir / "auto_examples_config.ini"
288-
config = configparser.ConfigParser()
289-
290-
# Set defaults with their expected types
291-
defaults = {
266+
def get_default_config() -> dict[str, bool | int | str]:
267+
"""Get default configuration for auto_examples download."""
268+
return {
292269
"github_owner": "ipc-lab",
293270
"github_repo": "kaira",
294271
"use_github_releases": True,
@@ -299,44 +276,6 @@ def load_config(script_dir: Path) -> dict[str, bool | int | str]:
299276
"skip_if_exists": True,
300277
}
301278

302-
if config_file.exists():
303-
config.read(config_file)
304-
305-
# Merge with defaults
306-
result: dict[str, bool | int | str] = {}
307-
for key, default_value in defaults.items():
308-
if "." in key:
309-
section, option = key.split(".", 1)
310-
else:
311-
section = "sources" if key.startswith(("github_", "use_")) else "settings"
312-
option = key
313-
314-
try:
315-
if section in config and option in config[section]:
316-
raw_value = config[section][option]
317-
318-
# Convert based on the type of the default value
319-
if isinstance(default_value, bool):
320-
result[key] = raw_value.lower() in ("true", "1", "yes", "on")
321-
elif isinstance(default_value, int):
322-
result[key] = int(raw_value)
323-
else:
324-
result[key] = str(raw_value)
325-
else:
326-
# Ensure we assign the correct type based on default_value type
327-
if isinstance(default_value, (bool, int, str)):
328-
result[key] = default_value
329-
else:
330-
result[key] = str(default_value)
331-
except Exception:
332-
# Ensure we assign the correct type based on default_value type
333-
if isinstance(default_value, (bool, int, str)):
334-
result[key] = default_value
335-
else:
336-
result[key] = str(default_value)
337-
338-
return result
339-
340279

341280
def main():
342281
"""Main function to download auto_examples."""
@@ -350,7 +289,7 @@ def main():
350289
log_message(f"Docs directory: {docs_dir}")
351290

352291
# Load configuration
353-
config = load_config(script_dir)
292+
config = get_default_config()
354293

355294
# Check if auto_examples already exists and is not empty
356295
auto_examples_dir = docs_dir / "auto_examples"

0 commit comments

Comments
 (0)