Skip to content

Commit 756eb07

Browse files
authored
Add Readthedocs json web page (Ameba-AIoT#285)
* Add RTD json support part1 * Add RTD json support part2 * Update .readthedocs.yaml * Update conf.py * Update .readthedocs.yaml * Update custom_script.py
1 parent 4662360 commit 756eb07

File tree

10 files changed

+341
-1
lines changed

10 files changed

+341
-1
lines changed

.readthedocs.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#.readthedocs.yaml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
# Set the OS, Python version and other tools you might need
9+
build:
10+
os: ubuntu-22.04
11+
tools:
12+
python: "3.11"
13+
# You can also specify other tool versions:
14+
# nodejs: "19"
15+
# rust: "1.64"
16+
# golang: "1.19"
17+
commands:
18+
- echo "Installing requirements..."
19+
- pip install -r Ameba_misc/RTD_links/requirements.txt
20+
- echo "Checking Sphinx version..."
21+
- sphinx-build --version # Check if sphinx-build is available
22+
- echo "Running custom Python script before build..."
23+
- python Ameba_misc/RTD_links/source/custom_script.py
24+
- echo "Custom script finished"
25+
- echo "Building Sphinx documentation..."
26+
- sphinx-build -b html Ameba_misc/RTD_links/source/ $READTHEDOCS_OUTPUT/html
27+
28+
# Optional but recommended, declare the Python requirements required
29+
# to build your documentation
30+
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
31+
python:
32+
install:
33+
- requirements: requirements.txt
34+
35+
# Build documentation in the directory with Sphinx
36+
sphinx:
37+
configuration: Ameba_misc/RTD_links/source/conf.py
38+
39+
# Optionally build your docs in additional formats such as PDF and ePub
40+
formats:
41+
- pdf
42+
# - epub

Ameba_misc/RTD_links/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
SPHINXOPTS = -W
11+
12+
# Put it first so that "make" without argument is like "make help".
13+
help:
14+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
15+
16+
.PHONY: help Makefile
17+
18+
# Catch-all target: route all unknown targets to Sphinx using the new
19+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
20+
%: Makefile
21+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

Ameba_misc/RTD_links/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ameba Pro2 Arduino SDK
2+
Ameba Pro2 Arduino SDK Readthedocs link

Ameba_misc/RTD_links/requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sphinx
2+
sphinx-markdown-tables==0.0.17
3+
sphinx-rtd-theme==2.0.0rc2
4+
recommonmark
5+
sphinx-tabs
Loading
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Ameba Pro2 Arduino SDK json link
2+
================================
3+
4+
.. _Download File:
5+
6+
You can download the file here:
7+
:download:`SDK json link early <../_static/package_realtek_amebapro2_early_index_rtd.json>`

Ameba_misc/RTD_links/source/conf.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# For the full list of built-in configuration values, see the documentation:
4+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
5+
6+
import sys
7+
import os
8+
import subprocess
9+
10+
# -- Project information -----------------------------------------------------
11+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
12+
13+
project = 'Ameba Arduino Json link RTD'
14+
copyright = '2024 Realtek Semiconductor Corp. All rights reserved'
15+
author = 'REALTEK SG'
16+
release = 'V1.0.0'
17+
18+
# -- General configuration ---------------------------------------------------
19+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
20+
21+
extensions = [
22+
'recommonmark',
23+
'sphinx_markdown_tables',
24+
'sphinx.ext.intersphinx',
25+
'sphinx_tabs.tabs'
26+
]
27+
28+
templates_path = ['_templates']
29+
exclude_patterns = []
30+
31+
# -- Options for HTML output -------------------------------------------------
32+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
33+
34+
html_context = {
35+
"display_github": True,
36+
"github_user": "Ameba-AIoT",
37+
"github_repo": "ameba-arduino-pro2",
38+
"github_version": "main",
39+
"conf_py_path": "/Ameba_misc/RTD_links/source/",
40+
}
41+
42+
html_logo = '_static/Realtek_logo.png'
43+
html_theme = 'sphinx_rtd_theme'
44+
html_static_path = ['_static']
45+
html_css_files = [
46+
'custom.css',
47+
]
48+
html_output = '_build/html'
49+
50+
numfig = True
51+
52+
# Get the path to the current directory
53+
current_dir = os.path.dirname(__file__)
54+
# Get the path to the custom script
55+
custom_script_path = os.path.join(current_dir, 'custom_script.py')
56+
# Run the custom script
57+
def run_custom_script():
58+
subprocess.run(['python', custom_script_path])
59+
# Add the custom script to the build process
60+
def setup(app):
61+
run_custom_script()
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
import os
2+
import shutil
3+
4+
board_list = []
5+
common_list = []
6+
temp_only_list = [1000, 1000]
7+
8+
def create_folder(folder_name):
9+
try:
10+
os.mkdir(folder_name)
11+
print(f"Folder '{folder_name}' created successfully.")
12+
except FileExistsError:
13+
print(f"Folder '{folder_name}' already exists.")
14+
except OSError as error:
15+
print(f"Creation of the directory '{folder_name}' failed: {error}")
16+
17+
def get_folder_paths(folder_path, mode):
18+
folder_paths = []
19+
if mode == 0:
20+
for item in os.listdir(folder_path):
21+
item_path = os.path.join(folder_path, item)
22+
if os.path.isdir(item_path):
23+
folder_paths.append(item_path)
24+
elif mode == 1:
25+
for item in os.listdir(folder_path):
26+
if os.path.isdir(os.path.join(folder_path, item)) and not item.startswith("_"):
27+
folder_paths.append(item)
28+
return folder_paths
29+
30+
def copy_files(o_file, c_file, mode):
31+
### copytree
32+
if mode == 1:
33+
source_path = os.path.abspath(o_file)
34+
target_path = os.path.abspath(c_file)
35+
shutil.copytree(source_path, target_path)
36+
### copyfile
37+
else:
38+
source_path = os.path.abspath(o_file)
39+
target_path = os.path.abspath(c_file)
40+
shutil.copyfile(source_path, target_path)
41+
42+
def copy_folder(src_folder, target_folder):
43+
"""
44+
Copy the contents of a folder into an existing target folder.
45+
46+
Args:
47+
src_folder (str): Path to the source folder.
48+
target_folder (str): Path to the target folder.
49+
50+
Returns:
51+
None
52+
"""
53+
# Check if source folder exists
54+
if not os.path.exists(src_folder):
55+
raise FileNotFoundError(f"Source folder '{src_folder}' not found.")
56+
57+
# Check if target folder exists, create it if not
58+
if not os.path.exists(target_folder):
59+
os.makedirs(target_folder)
60+
61+
# Iterate over all items in the source folder
62+
for item in os.listdir(src_folder):
63+
src_item = os.path.join(src_folder, item)
64+
target_item = os.path.join(target_folder, item)
65+
66+
# If it's a directory, copy it recursively
67+
if os.path.isdir(src_item):
68+
if os.path.exists(target_item):
69+
# If the target subdirectory already exists, merge contents
70+
shutil.copytree(src_item, target_item, dirs_exist_ok=True)
71+
else:
72+
shutil.copytree(src_item, target_item)
73+
# If it's a file, copy it directly
74+
else:
75+
shutil.copy2(src_item, target_item)
76+
77+
def replace_text_in_file(file_path, text_a, text_b):
78+
"""
79+
Replace all occurrences of text A with text B in the specified file.
80+
81+
Parameters:
82+
file_path (str): The path to the file.
83+
text_a (str): The text to be replaced.
84+
text_b (str): The text to replace with.
85+
86+
Returns:
87+
str: A message indicating the success of the operation.
88+
"""
89+
try:
90+
# Read the content of the file
91+
with open(file_path, 'r', encoding='utf-8') as file:
92+
content = file.read()
93+
94+
# Replace the text
95+
new_content = content.replace(text_a, text_b)
96+
97+
# Write the modified content back to the file
98+
with open(file_path, 'w', encoding='utf-8') as file:
99+
file.write(new_content)
100+
101+
return f"Text '{text_a}' has been replaced with '{text_b}' in the file '{file_path}'"
102+
103+
except Exception as e:
104+
return f"An error occurred: {e}"
105+
106+
if __name__ == "__main__":
107+
# Change the current working directory
108+
new_directory = './Ameba_misc/RTD_links/source'
109+
os.chdir(new_directory)
110+
# Print the new current working directory
111+
print(os.getcwd())
112+
113+
# copy json files
114+
copy_files('../../../Arduino_package/package_realtek_amebapro2_early_index.json', '_static/package_realtek_amebapro2_early_index_rtd.json', 0);
115+
### copy_files('../../../Arduino_package/package_realtek_amebapro2_early_index.json', '_static/package_realtek_amebapro2_index_rtd.json', 0);
116+
117+
# copy release files
118+
copy_folder('../../../Arduino_package/release', '_static/release');
119+
120+
replace_text_in_file('_static/package_realtek_amebapro2_early_index_rtd.json', 'github.com/Ameba-AIoT/ameba-arduino-pro2/raw/dev/Arduino_package', 'ameba-doc-arduino-sdk-json.readthedocs-hosted.com/en/latest/_static');
121+
122+
# Remove the folder '/path/to/folder' and all its contents
123+
###shutil.rmtree('_static/release')
124+
125+
126+
127+
128+
129+
130+
131+
132+
133+
134+
135+
136+
137+
138+
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
149+
150+
151+
152+
153+
154+
155+
156+
157+
158+
159+
160+
161+
162+
163+
164+
165+
166+
167+
168+
169+
170+
171+
172+
173+
174+
175+
176+
177+

Ameba_misc/RTD_links/source/index.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Ameba Arduino Readtehdocs json files
2+
====================================
3+
4+
.. tabs::
5+
6+
.. tab:: Ameba Pro2
7+
8+
.. toctree::
9+
:maxdepth: 1
10+
11+
AMB82 mini <amebapro2/index>
12+
13+
FAQ and Forum
14+
=============
15+
16+
* `Ameba IoT FAQ <https://forum.amebaiot.com/c/faq/48>`_
17+
18+
* `Ameba IoT Forum <https://forum.amebaiot.com/>`_
19+
20+
Indices and tables
21+
==================
22+
23+
* :ref:`genindex`
24+
* :ref:`modindex`
25+
* :ref:`search`

Arduino_package/package_realtek_amebapro2_early_index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"packages": [
33
{
44
"name": "realtek",
5-
"maintainer": "Realtek",
5+
"maintainer": "Realtek SG SD3",
66
"websiteURL": "https://www.amebaiot.com/",
77
"email": "realteksgsd3@gmail.com",
88
"help": {

0 commit comments

Comments
 (0)