File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Sphinx build
2+
3+ on :
4+ # Push/Pull for main branch.
5+ push :
6+ branches : [main]
7+ pull_request :
8+ branches : [main]
9+
10+ # Run workflow manually from actions tab.
11+ workflow_dispatch :
12+
13+ jobs :
14+ build :
15+ # Specify an OS for the runner
16+ runs-on : ubuntu-latest
17+
18+ # Define steps
19+ steps :
20+
21+ # Firstly, checkout repo
22+ - name : Checkout repository
23+ uses : actions/checkout@v4
24+ # Set up Python env
25+ - name : Setup Python
26+ uses : actions/setup-python@v5
27+ with :
28+ python-version : 3.11
29+ # Install dependencies
30+ - name : Install Python dependencies
31+ run : |
32+ python3 -m pip install --upgrade pip
33+ pip3 install poetry
34+ poetry install
35+
36+ - name : Build documentation
37+ run : |
38+ mkdir gh-pages
39+ touch gh-pages/.nojekyll
40+ pushd docs/source/
41+ poetry run sphinx-build -b html . _build
42+ popd
43+ cp -r docs/source/_build/* gh-pages/
44+
45+ - name : Upload artifacts
46+ uses : actions/upload-artifact@v4
47+ with :
48+ name : html-docs
49+ path : gh-pages
50+ # Deploys to the gh-pages branch if the commit was made to main, the
51+ # gh-pages then takes over serving the html
52+ - name : Deploy documentation
53+ if : ${{ github.event_name == 'push' }}
54+ uses : JamesIves/github-pages-deploy-action@4.1.4
55+ with :
56+ branch : gh-pages
57+ folder : gh-pages
Original file line number Diff line number Diff line change 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 = .
9+ BUILDDIR = _build
10+
11+ # Put it first so that "make" without argument is like "make help".
12+ help :
13+ @$(SPHINXBUILD ) -M help " $( SOURCEDIR) " " $( BUILDDIR) " $(SPHINXOPTS ) $(O )
14+
15+ .PHONY : help Makefile
16+
17+ # Catch-all target: route all unknown targets to Sphinx using the new
18+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+ % : Makefile
20+ @$(SPHINXBUILD ) -M $@ " $( SOURCEDIR) " " $( BUILDDIR) " $(SPHINXOPTS ) $(O )
Original file line number Diff line number Diff line change 1+ .. ceda-datapoint documentation master file, created by
2+ sphinx-quickstart on Tue Oct 15 15:34:57 2024.
3+ You can adapt this file completely to your liking, but it should at least
4+ contain the root `toctree` directive.
5+
6+ CCI STAC Tools
7+ ==============
8+
9+
10+ Indices and tables
11+ ==================
12+
13+ * :ref: `genindex `
14+ * :ref: `modindex `
15+ * :ref: `search `
Original file line number Diff line number Diff line change 1+ @ ECHO OFF
2+
3+ pushd %~dp0
4+
5+ REM Command file for Sphinx documentation
6+
7+ if " %SPHINXBUILD% " == " " (
8+ set SPHINXBUILD = sphinx-build
9+ )
10+ set SOURCEDIR = source
11+ set BUILDDIR = _build
12+
13+ %SPHINXBUILD% > NUL 2 > NUL
14+ if errorlevel 9009 (
15+ echo .
16+ echo .The 'sphinx-build' command was not found. Make sure you have Sphinx
17+ echo .installed, then set the SPHINXBUILD environment variable to point
18+ echo .to the full path of the 'sphinx-build' executable. Alternatively you
19+ echo .may add the Sphinx directory to PATH.
20+ echo .
21+ echo .If you don't have Sphinx installed, grab it from
22+ echo .https://www.sphinx-doc.org/
23+ exit /b 1
24+ )
25+
26+ if " %1 " == " " goto help
27+
28+ %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+ goto end
30+
31+ :help
32+ %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+ :end
35+ popd
Original file line number Diff line number Diff line change 1+ echo 1. Converting
2+ jupyter nbconvert --to rst ../demo/basic_usage.ipynb
3+
4+ echo 2. Relocating
5+ mv ../demo/basic_usage.rst usage.rst
6+
7+ echo 3. Reformatting
8+ python rst_format.py usage.rst
9+
10+ echo 4. Installing
11+ mv usage.rst source/usage.rst
Original file line number Diff line number Diff line change 1+ """
2+ Turn:
3+
4+ .. code:: ipython3
5+
6+ do some python
7+
8+ .. code:: literal
9+
10+ result
11+
12+ Into:
13+
14+ .. parsed-literal::
15+
16+ >>> do some python
17+ result
18+ """
19+
20+ import sys
21+
22+
23+ def reformat_file (filename : str , ofile : str = None ):
24+ """
25+ Reformat a generated file to use as documentation with testing
26+ """
27+
28+ with open (filename ) as f :
29+ lines = [r .replace ('\n ' ,'' ) for r in f .readlines ()]
30+
31+ rst = []
32+ in_code_block = False
33+ python = False
34+ literal = False
35+ for x , l in enumerate (lines ):
36+
37+ if not bool (l ):
38+ if not in_code_block :
39+ rst .append (l )
40+ continue
41+ elif '.. code::' in l or '.. parsed-literal::' in l :
42+ if not in_code_block or literal :
43+ if literal :
44+ rst .append ('' )
45+ l = '.. code::'
46+ in_code_block = True
47+ python = True
48+ literal = False
49+ rst .append (l )
50+ rst .append ('' )
51+ else :
52+ literal = True
53+ python = False
54+ elif not l .startswith (' ' ):
55+ if in_code_block :
56+ in_code_block = False
57+ rst .append ('' )
58+ rst .append (l )
59+ else :
60+ if python :
61+ rst .append (f' >>> { l [4 :]} ' )
62+ else :
63+ rst .append (l [1 :])
64+
65+ if ofile is None :
66+ ofile = filename
67+
68+ with open (ofile , 'w' ) as f :
69+ f .write ('\n ' .join (rst ))
70+
71+ print (f'Written to output file: { ofile } ' )
72+
73+ if __name__ == '__main__' :
74+ reformat_file (sys .argv [- 1 ])
You can’t perform that action at this time.
0 commit comments