diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-10-24 08:46:14 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-10-24 09:23:18 +0200 |
| commit | 56f084389a3eb6b34df86af347ce60acdeb6106b (patch) | |
| tree | 3e3fc02086b7b246752a6dc4804551dd05b4dfa3 | |
| parent | 1f3a6e09d3b605fb70cd0dd2165373814feb2eda (diff) | |
Actions + Docs: Use Sphinx docs for Python
| -rw-r--r-- | .github/workflows/deploy.yml | 50 | ||||
| -rw-r--r-- | docs/src/SUMMARY.md | 1 | ||||
| -rw-r--r-- | docs/src/api/python/README.md | 10 | ||||
| -rw-r--r-- | docs/src/api/python/functions.md | 101 | ||||
| -rw-r--r-- | wrappers/python/docs/source/conf.py | 2 |
5 files changed, 48 insertions, 116 deletions
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5735b1b..103472c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,6 +1,6 @@ # Adapted from https://github.com/rust-lang/mdBook/wiki/Automated-Deployment:-GitHub-Actions#github-pages-deploy -name: Deploy +name: Build docs on: push: branches: @@ -8,7 +8,7 @@ on: jobs: deploy: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 with: @@ -19,23 +19,65 @@ jobs: curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.18/mdbook-v0.4.18-x86_64-unknown-linux-gnu.tar.gz -o mdbook.tar.gz # Verify hash echo "d276b0e594d5980de6a7917ce74c348f28d3cb8b353ca4eaae344ae8a4c40bea mdbook.tar.gz" | sha256sum --check + # Extract mkdir mdbook tar -xzf mdbook.tar.gz --directory mdbook echo `pwd`/mdbook >> $GITHUB_PATH + - name: Install sphinx + run: | + # Install python dependencies + sudo apt -y install python3 python3-pip python3-sphinx + + # Install rtd theme + pip install sphinx_rtd_theme + - name: Install go + run: | + sudo apt -y install golang-go + - name: Build & Install python-eduvpn-common + run: | + # Make go library + make + + # Go to Python wrapper + cd wrappers/python + + # Make wheel + make pack + + # Install wheel + pip3 install dist/*.whl - name: Deploy GitHub Pages run: | - # Go to docs directory - cd docs + # Build Sphinx + cd wrappers/python/docs + make html + + # Go to docs directory & build mdbook + cd ../../../docs mdbook build + + # gh pages branch settings git worktree add gh-pages gh-pages git config user.name "Deploy from CI" git config user.email "" cd gh-pages + # Delete the ref to avoid keeping history. git update-ref -d refs/heads/gh-pages rm -rf * + + # move mdbook files mv ../book/* . + + # move sphinx files + mkdir api/python/rtd + mv ../../wrappers/python/docs/build/html/* api/python/rtd + + # Disable jekyll as otherwise it won't find our sphinx paths + # that start with underscore + touch .nojekyll + git add . git commit -m "Deploy $GITHUB_SHA to gh-pages" git push --force diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 9274cee..6ec2259 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -22,5 +22,4 @@ - [Go](./api/go/README.md) - [Example](./api/go/example.md) - [Python](./api/python/README.md) - - [Functions](./api/python/functions.md) - [Example](./api/python/example.md) diff --git a/docs/src/api/python/README.md b/docs/src/api/python/README.md index e15511f..6bc66b6 100644 --- a/docs/src/api/python/README.md +++ b/docs/src/api/python/README.md @@ -1,10 +1,2 @@ # Python -As the Go library is build as a *shared* library, it can be loaded by other languages. We have created wrapper code for Python to use this library. We define the functions and then give a similar example to the Go example. - -The functions that we will discuss are all part of the `EduVPN` class defined in `eduvpn_common.main`. You can import it like so: - -```python -import eduvpn_common.main as eduvpn - -# Then use eduvpn.EduVPN -``` +As the Go library is build as a *shared* library, it can be loaded by other languages. We have created wrapper code for Python to use this library. The api documentation can be found [here](./rtd/index.html). In the next chapter we will give a similar example to the Go example. diff --git a/docs/src/api/python/functions.md b/docs/src/api/python/functions.md deleted file mode 100644 index 2b909a8..0000000 --- a/docs/src/api/python/functions.md +++ /dev/null @@ -1,101 +0,0 @@ -# Functions -## Creating the class -See [Overview](../overview/registering.html) - -This creates the class and basically forwards these arguments when `register` is called. -```python -def __init__(self, name: str, directory: str) -``` -- `name`: The name of the client -- `directory`: The directory where the configs and logging should be stored - -## Registering -See [Overview](../overview/registering.html) -```python -def register(self, debug: bool = False) -> None -``` -- `debug`: Whether or not we want to enable debugging, default: `False` - -Returns nothing. Raises an exception in case of an error. - -## Discovery -See [Overview](../overview/discovery.html) -```python -def get_disco_servers(self) -> str -``` -```python -def get_disco_organizations(self) -> str -``` - -Returns a `string` of JSON data with the servers/organizations. Raises an exception in case of an error. - -## OpenVPN/Wireguard config -See [Overview](../overview/getconfig.html) -```python -def get_config_institute_access(self, url: str, preferTCP: bool = False) -> Tuple[str, str] -``` -```python -def get_config_secure_internet(self, url: str, preferTCP: bool = False) -> Tuple[str, str] -``` -- `url`: The url of the Secure Internet or Institute Access server to get a connect config for -- `preferTCP`: Whether or not we want to prefer TCP, default: `False` - -Returns: -- A `string` of the OpenVPN/Wireguard config -- An `string`, `openvpn` or `wireguard` indicating if it is an OpenVPN or Wireguard config - -Raises an exception in case of an error. - -### Cancelling OAuth -```python -def cancel_oauth(self) -> None -``` - -Returns nothing. Raises an exception in case of an error. - -### Setting a profile ID -```python -def set_profile(self, profile_id: str) -> None -``` -- `profile_id`: The profile ID to connect to - -Returns nothing. Raises an exception in case of an errorr. - -## Connecting/Disconnecting -See [Overview](../overview/connecting.html) -```python -def set_connected(self) -> None -``` -```python -def set_disconnected(self) -> None -``` - -Returns an nothing. Raises an exception in case of an error. - -## Deregister -See [Overview](../overview/deregistering.html) -```python -def deregister() -> None -``` - -Returns nothing. Raises an exception in case of an error. - -# Note on Callbacks -Some functions (e.g. [the API for getting an OpenVPN/Wireguard config](http://localhost:3000/api/overview/getconfig.html)) need a (or multiple) callbacks set. In Python, the callback function is set using decorators. -For this, the `eduvpn.EduVPN` class has the following syntax: - -```python -# Where _eduvpn is the eduvpn.EduVPN class instance -# This gets called when the New_State_Example state is entered -# old_state is then the old state -@_eduvpn.event.on("New_State_Example", eduvpn.StateType.ENTER) -def example_enter(old_state: str, data: str) -``` -```python -# Where _eduvpn is the eduvpn.EduVPN class instance -# This gets called when the Old_State_Example state is left -# new_state is then the new state -@_eduvpn.event.on("Old_State_Example", eduvpn.StateType.LEAVE) -def example_leave(new_state: str, data: str) -``` -To show how this can be done in practice, we will give an example in the next section. diff --git a/wrappers/python/docs/source/conf.py b/wrappers/python/docs/source/conf.py index 89da513..d7b8c57 100644 --- a/wrappers/python/docs/source/conf.py +++ b/wrappers/python/docs/source/conf.py @@ -29,4 +29,4 @@ exclude_patterns = [] # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output html_theme = 'sphinx_rtd_theme' -html_static_path = ['_static'] +html_static_path = [] |
