diff --git a/.gitignore b/.gitignore index da6ec6fc..3ed5f76d 100644 --- a/.gitignore +++ b/.gitignore @@ -233,3 +233,6 @@ cython_debug/ /docs/_static/logos/ /docs/_build/ /docs/changelog.md +/docs_version3/_build/ +/docs_version3/_static/logos/ +/docs_version3/changelog.md diff --git a/.readthedocs.yml b/.readthedocs.yml index 08ccc9d7..90f394df 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -9,25 +9,10 @@ build: os: "ubuntu-24.04" tools: python: "3.13" - jobs: - post_checkout: - # Copy the appropriate conf.py based on project name - - | - if [ "$DOC_BUILD_VERSION" = "v2" ]; then - echo "DOC_BUILD_VERSION is: $DOC_BUILD_VERSION" - echo "Building brainpy-version2 documentation" - mkdir -p docs_build - cp -r docs_version2/* docs_build/ - else - echo "DOC_BUILD_VERSION is: $DOC_BUILD_VERSION" - echo "Building standard brainpy documentation" - mkdir -p docs_build - cp -r docs/* docs_build/ - fi # Build documentation using the copied conf.py sphinx: - configuration: docs_build/conf.py + configuration: docs/conf.py # Optionally set the version of Python and requirements required to build your docs python: diff --git a/docs/conf.py b/docs/conf.py index 2282061d..70a03338 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,16 +15,42 @@ import shutil import sys +# 要保留的文件/文件夹列表 +keep_files = {'highlight_test_lexer.py', 'conf.py', 'make.bat', 'Makefile'} + +# 遍历当前目录 +for item in os.listdir('.'): + if item not in keep_files: + path = os.path.join('.', item) + try: + if os.path.isfile(path): + os.remove(path) + elif os.path.isdir(path): + shutil.rmtree(path) + except Exception as e: + print(f"Error deleting {item}: {e}") + +build_version = os.environ.get('CURRENT_VERSION', 'v3') +if build_version == 'v2': + shutil.copytree( + os.path.join(os.path.dirname(__file__), '../docs_version2'), + os.path.join(os.path.dirname(__file__), ), + dirs_exist_ok=True + ) +else: + shutil.copytree( + os.path.join(os.path.dirname(__file__), '../docs_version3'), + os.path.join(os.path.dirname(__file__), ), + dirs_exist_ok=True + ) + sys.path.insert(0, os.path.abspath('./')) sys.path.insert(0, os.path.abspath('../')) -sys.path.insert(0, r'D:\codes\projects\brainstate') import brainpy + shutil.copytree('../images/', './_static/logos/', dirs_exist_ok=True) shutil.copyfile('../changelog.md', './changelog.md') -shutil.rmtree('./generated', ignore_errors=True) -shutil.rmtree('./_build', ignore_errors=True) - # -- Project information ----------------------------------------------------- @@ -88,12 +114,20 @@ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] # href with no underline and white bold text color -announcement = """ - - This site covers the new BrainPy 3.0 API. - [Click here for the classical BrainPy 2.0 API] - -""" + +if build_version == 'v2': + announcement = """ + + This site covers the old BrainPy 2.0 API. [Explore the new BrainPy 3.0 API ✨] + + """ +else: + announcement = """ + + This site covers the new BrainPy 3.0 API. + [Click here for the classical BrainPy 2.0 API] + + """ html_theme_options = { 'repository_url': 'https://github.com/brainpy/BrainPy', diff --git a/docs_version2/Makefile b/docs_version2/Makefile deleted file mode 100644 index 2de4207a..00000000 --- a/docs_version2/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -# Minimal makefile for Sphinx documentation -# - -# You can set these variables from the command line, and also -# from the environment for the first two. -SPHINXOPTS ?= -SPHINXBUILD ?= sphinx-build -SPHINXPROJ = brainpy -SOURCEDIR = . -BUILDDIR = _build - -# Put it first so that "make" without argument is like "make help". -help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - -.PHONY: help Makefile - -# Catch-all target: route all unknown targets to Sphinx using the new -# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). -%: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs_version2/conf.py b/docs_version2/conf.py deleted file mode 100644 index c0b6339a..00000000 --- a/docs_version2/conf.py +++ /dev/null @@ -1,150 +0,0 @@ -# Configuration file for the Sphinx documentation builder. -# -# This file only contains a selection of the most common options. For a full -# a_list see the documentation: -# https://www.sphinx-doc.org/en/master/usage/configuration.html - -# -- Path setup -------------------------------------------------------------- - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -# - -import os -import shutil -import sys - -sys.path.insert(0, os.path.abspath('./')) -sys.path.insert(0, os.path.abspath('../')) - -import brainpy - -os.makedirs('apis/auto/', exist_ok=True) - -# import auto_generater -# auto_generater.generate_analysis_docs() -# auto_generater.generate_connect_docs() -# auto_generater.generate_encoding_docs() -# auto_generater.generate_initialize_docs() -# auto_generater.generate_inputs_docs() -# auto_generater.generate_dnn_docs() -# auto_generater.generate_dyn_docs() -# auto_generater.generate_losses_docs() -# auto_generater.generate_measure_docs() -# auto_generater.generate_optim_docs() -# auto_generater.generate_running_docs() -# auto_generater.generate_brainpy_docs() -# auto_generater.generate_integrators_doc() -# auto_generater.generate_math_docs() -# auto_generater.generate_mixin_docs() -# sys.exit() - -shutil.copytree('../images/', './_static/logos/', dirs_exist_ok=True) - -# -- Project information ----------------------------------------------------- - -project = 'BrainPy' -copyright = '2020-, BrainPy' -author = 'BrainPy Team' - -# The full version, including alpha/beta/rc tags -release = brainpy.__version__ - -# -- General configuration --------------------------------------------------- - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.autosummary', - 'sphinx.ext.intersphinx', - 'sphinx.ext.mathjax', - 'sphinx.ext.napoleon', - 'sphinx.ext.viewcode', - 'sphinx_autodoc_typehints', - 'myst_nb', - 'matplotlib.sphinxext.plot_directive', - 'sphinx_thebe', - 'sphinx_design' - # 'sphinx-mathjax-offline', -] -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] -source_suffix = ['.rst', '.ipynb', '.md'] - -# source_suffix = '.rst' -autosummary_generate = True - -# The master toctree document. -master_doc = 'index' - -intersphinx_mapping = { - "python": ("https://docs.python.org/3.8", None), - "sphinx": ("https://www.sphinx-doc.org/en/master", None), -} -nitpick_ignore = [ - ("py:class", "docutils.nodes.document"), - ("py:class", "docutils.parsers.rst.directives.body.Sidebar"), -] - -suppress_warnings = ["myst.domains", "ref.ref"] -numfig = True -myst_enable_extensions = ["dollarmath", "amsmath", "deflist", "colon_fence"] -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -# This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] - -# href with no underline and white bold text color -announcement = """ - - This site covers the old BrainPy 2.0 API. [Explore the new BrainPy 3.0 API ✨] - -""" - -html_theme_options = { - 'repository_url': 'https://github.com/brainpy/BrainPy', - 'use_repository_button': True, # add a 'link to repository' button - 'use_issues_button': False, # add an 'Open an Issue' button - 'path_to_docs': 'docs', # used to compute the path to launch notebooks in colab - 'launch_buttons': { - 'colab_url': 'https://colab.research.google.com/', - }, - 'prev_next_buttons_location': None, - 'show_navbar_depth': 1, - 'announcement': announcement, - 'logo_only': True, - 'show_toc_level': 2, -} - -html_theme = "sphinx_book_theme" -html_logo = "_static/logos/logo.png" -html_title = "BrainPy documentation" -html_copy_source = True -html_sourcelink_suffix = "" -html_favicon = "_static/logos/logo-square.png" -html_last_updated_fmt = "" -html_css_files = ['css/theme.css'] - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] -jupyter_execute_notebooks = "off" -thebe_config = { - "repository_url": "https://github.com/binder-examples/jupyter-stacks-datascience", - "repository_branch": "master", -} - -# -- Options for myst ---------------------------------------------- -# Notebook cell execution timeout; defaults to 30. -execution_timeout = 200 - -autodoc_default_options = { - 'exclude-members': '....,default_rng', -} diff --git a/docs_version2/make.bat b/docs_version2/make.bat deleted file mode 100644 index 922152e9..00000000 --- a/docs_version2/make.bat +++ /dev/null @@ -1,35 +0,0 @@ -@ECHO OFF - -pushd %~dp0 - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set SOURCEDIR=. -set BUILDDIR=_build - -if "%1" == "" goto help - -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 -) - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% - -:end -popd diff --git a/docs/_static/css/theme.css b/docs_version3/_static/css/theme.css similarity index 100% rename from docs/_static/css/theme.css rename to docs_version3/_static/css/theme.css diff --git a/docs/_static/snn-simulation1.png b/docs_version3/_static/snn-simulation1.png similarity index 100% rename from docs/_static/snn-simulation1.png rename to docs_version3/_static/snn-simulation1.png diff --git a/docs/_templates/classtemplate.rst b/docs_version3/_templates/classtemplate.rst similarity index 100% rename from docs/_templates/classtemplate.rst rename to docs_version3/_templates/classtemplate.rst diff --git a/docs/apis.rst b/docs_version3/apis.rst similarity index 100% rename from docs/apis.rst rename to docs_version3/apis.rst diff --git a/docs/checkpointing-en.ipynb b/docs_version3/checkpointing-en.ipynb similarity index 100% rename from docs/checkpointing-en.ipynb rename to docs_version3/checkpointing-en.ipynb diff --git a/docs/checkpointing-zh.ipynb b/docs_version3/checkpointing-zh.ipynb similarity index 100% rename from docs/checkpointing-zh.ipynb rename to docs_version3/checkpointing-zh.ipynb diff --git a/docs/index.rst b/docs_version3/index.rst similarity index 100% rename from docs/index.rst rename to docs_version3/index.rst diff --git a/docs/snn_simulation-en.ipynb b/docs_version3/snn_simulation-en.ipynb similarity index 100% rename from docs/snn_simulation-en.ipynb rename to docs_version3/snn_simulation-en.ipynb diff --git a/docs/snn_simulation-zh.ipynb b/docs_version3/snn_simulation-zh.ipynb similarity index 100% rename from docs/snn_simulation-zh.ipynb rename to docs_version3/snn_simulation-zh.ipynb diff --git a/docs/snn_training-en.ipynb b/docs_version3/snn_training-en.ipynb similarity index 100% rename from docs/snn_training-en.ipynb rename to docs_version3/snn_training-en.ipynb diff --git a/docs/snn_training-zh.ipynb b/docs_version3/snn_training-zh.ipynb similarity index 100% rename from docs/snn_training-zh.ipynb rename to docs_version3/snn_training-zh.ipynb diff --git a/docs/spiking_neural_networks-en.ipynb b/docs_version3/spiking_neural_networks-en.ipynb similarity index 100% rename from docs/spiking_neural_networks-en.ipynb rename to docs_version3/spiking_neural_networks-en.ipynb diff --git a/docs/spiking_neural_networks-zh.ipynb b/docs_version3/spiking_neural_networks-zh.ipynb similarity index 100% rename from docs/spiking_neural_networks-zh.ipynb rename to docs_version3/spiking_neural_networks-zh.ipynb