Skip to content

Commit ef0bd75

Browse files
feat: add documentation site (#115)
[ci skip]
1 parent be69467 commit ef0bd75

File tree

13 files changed

+397
-91
lines changed

13 files changed

+397
-91
lines changed

.github/workflows/docs.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Documentation
2+
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types: [released]
7+
8+
jobs:
9+
docs:
10+
name: Build Documentation
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0
16+
- uses: actions/setup-python@v2
17+
with:
18+
python-version: 3.8
19+
- run: pip install poetry
20+
- name: Set up cache
21+
uses: actions/cache@v2
22+
with:
23+
path: .venv
24+
key: ${{ runner.os }}-venv-py3.8-${{ hashFiles('**/poetry.lock') }}
25+
- name: Install package
26+
run: poetry install
27+
- name: Publish documentation
28+
run: poetry run mkdocs gh-deploy

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ contxt --help
1818

1919
## Documentation
2020

21-
- [CLI](docs/cli.md)
22-
- [Worker](docs/worker.md)
21+
Please refer to <https://ndustrialio.github.io/contxt-sdk-python>.
2322

2423
## Contributing
2524

contxt/cli/commands/auth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ def logout(client: Clients) -> None:
2626
@click.argument("audience")
2727
@click.pass_obj
2828
def token(client: Clients, audience: str) -> None:
29-
"""Fetch token for an API."""
29+
"""Fetch an access token for an API."""
3030
token = client.auth.get_token_provider(audience).access_token
3131
print(token)

contxt/cli/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def get_command(self, ctx, name):
2424
return ns[name]
2525

2626

27-
@click.group(cls=Cli, context_settings=dict(help_option_names=["-h", "--help"]))
27+
@click.group(cls=Cli, name="contxt", context_settings=dict(help_option_names=["-h", "--help"]))
2828
@click.option(
2929
"--env",
3030
type=click.Choice(["production", "staging"]),

docs/cli.md

-67
This file was deleted.

docs/cli/commands.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
::: mkdocs-click
2+
:module: contxt.__main__
3+
:command: cli
4+
:prog_name: contxt

docs/cli/index.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Quickstart
2+
3+
## Login
4+
5+
To access any Contxt API, first login with your Contxt credentials:
6+
7+
```sh
8+
contxt auth login
9+
```
10+
11+
This will open a browser window, ask you to login (if not already), and confirm a code. If this succeeds, you should see something like `Your device is now connected.`
12+
13+
## Usage
14+
15+
The CLI's general usage pattern is:
16+
17+
```sh
18+
contxt [entity] [action]
19+
```
20+
21+
For example, to _get_ all _orgs_:
22+
23+
```sh
24+
contxt orgs get
25+
```
26+
27+
See all supported commands [here](./commands.md).

docs/examples/worker.py

-17
This file was deleted.

docs/index.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Overview
2+
3+
This software development kit (SDK) gives you quick access to the set of Contxt API's from <https://ndustrial.io>, both programatically and on the command line.
4+
5+
## Install
6+
7+
Before proceeding, you must have [Python](https://www.python.org/) 3.7+ installed.
8+
9+
### Library
10+
11+
To install and use this SDK as a library, just use [pip](https://pip.pypa.io/en/stable/quickstart/):
12+
13+
```sh
14+
python3 -m pip install --upgrade contxt-sdk
15+
```
16+
17+
### CLI
18+
19+
If you only need the CLI, the above method will work fine. However, we recommend using [pipx](https://pipxproject.github.io/pipx/installation/#install-pipx)[^1]:
20+
21+
```sh
22+
# Setup pipx (once only)
23+
python3 -m pip install --user pipx
24+
python3 -m pipx ensurepath
25+
26+
# Install
27+
pipx install contxt-sdk
28+
29+
# Upgrade
30+
pipx upgrade contxt-sdk
31+
```
32+
33+
Run the following to ensure the installation was successful:
34+
35+
```sh
36+
$ contxt --version
37+
contxt, version 2.1.4
38+
```
39+
40+
[^1]: Why pipx? See [here](https://pipxproject.github.io/pipx/#how-is-it-different-from-pip)

docs/worker.md renamed to docs/sdk/worker.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,24 @@ Within Contxt, a machine client is identified by a unique client id and secret p
1010

1111
Our SDK provides a `BaseWorker` class to help abstract the authentication process between a machine client and a Contxt API. Upon instantation, the class will look for your machine credientials in the environment variables `CLIENT_ID` and `CLIENT_SECRET`, and then store this pair as the attribute `auth`. Next, your worker's business logic is defined in the `do_work()` method. If we need to make requests to a Contxt API here, we simply inject our credentials when instantiating the service class (i.e. `FacilitiesService(self.auth)`). Now, that class handles generating, sending, and refreshing your JWT to authenticate requests to that API.
1212

13-
For a more concrete example, see [worker.py](examples/worker.py).
13+
For a more concrete example:
14+
15+
```python
16+
from contxt.services.facilities import FacilitiesService
17+
from contxt.workers import BaseWorker
18+
19+
20+
class ExampleWorker(BaseWorker):
21+
def __init__(self):
22+
super().__init__()
23+
self.facilities_service = FacilitiesService(self.auth)
24+
25+
def do_work(self):
26+
facilities = self.facilities_service.get_facilities()
27+
print(facilities)
28+
29+
30+
if __name__ == "__main__":
31+
worker = ExampleWorker()
32+
worker.do_work()
33+
```

mkdocs.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
site_name: Contxt SDK
2+
theme: readthedocs
3+
repo_url: https://github.com/ndustrialio/contxt-sdk-python/
4+
markdown_extensions:
5+
- footnotes
6+
- mkdocs-click
7+
- toc:
8+
permalink: True

0 commit comments

Comments
 (0)