Skip to content

Commit

Permalink
Initial featureset
Browse files Browse the repository at this point in the history
  • Loading branch information
zakstucke committed Oct 9, 2023
1 parent 6a5eb0b commit 60b83db
Show file tree
Hide file tree
Showing 28 changed files with 1,641 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
hooks:
- id: pdm-export
# command arguments, e.g.:
args: ["-o", "requirements.txt", "--without-hashes"]
args: ["-o", "requirements.txt", "--without-hashes", "--prod"]
files: ^pdm.lock$
- repo: local
hooks:
Expand Down
39 changes: 39 additions & 0 deletions docs/gen_ref_pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Generate the code reference pages and navigation. https://mkdocstrings.github.io/recipes/?h=recip#automatic-code-reference-pages."""

from pathlib import Path

import mkdocs_gen_files

pkg_name = "watz"

nav = mkdocs_gen_files.Nav() # type: ignore

for path in sorted(Path(pkg_name).rglob("*.py")):
# Make sure filename doesn't start with an underscore:
if path.name.startswith("_"):
continue

module_path = path.relative_to(".").with_suffix("")
doc_path = path.relative_to(pkg_name).with_suffix(".md")
full_doc_path = Path("reference", doc_path)

parts = tuple(module_path.parts)

if parts[-1] == "__init__":
parts = parts[:-1]
doc_path = doc_path.with_name("index.md")
full_doc_path = full_doc_path.with_name("index.md")
elif parts[-1] == "__main__":
continue

if parts:
nav[parts] = doc_path.as_posix()

with mkdocs_gen_files.open(full_doc_path, "w") as fd:
ident = ".".join(parts)
fd.write(f"::: {ident}")

mkdocs_gen_files.set_edit_path(full_doc_path, path)

with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file:
nav_file.writelines(nav.build_literate_nav())
1 change: 0 additions & 1 deletion docs/reference.md

This file was deleted.

21 changes: 17 additions & 4 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ theme:
- navigation.instant.progress
- navigation.tracking
- navigation.tabs
- navigation.indexes
- search.suggest
- search.highlight

Expand All @@ -32,7 +31,21 @@ plugins:
repository: watz-inc/watz-py
branch: main
- search
- mkdocstrings

# https://mkdocstrings.github.io/recipes/?h=recip#automatic-code-reference-pages
- gen-files:
scripts:
- docs/gen_ref_pages.py
- literate-nav:
nav_file: SUMMARY.md
- section-index

- mkdocstrings:
handlers:
python:
options:
merge_init_into_class: true
inherited_members: true

markdown_extensions:
- pymdownx.snippets
Expand All @@ -44,8 +57,8 @@ extra:
nav:
- Home:
- index.md
- API:
- reference.md
# defer to gen-files + literate-nav https://mkdocstrings.github.io/recipes/?h=recip#automatic-code-reference-pages
- Code Reference: reference/ # Note the trailing slash is important
- Contributing:
- CONTRIBUTING.md
- CODE_OF_CONDUCT.md
Expand Down
96 changes: 96 additions & 0 deletions notebooks/scratch_space.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"971.264\n"
]
}
],
"source": [
"import json\n",
"import pprint\n",
"\n",
"with open(\"/home/zakst/Downloads/req_example.json\", \"r\") as file:\n",
" data = json.load(file)\n",
" # print size in kb of file:\n",
" file_size = len(json.dumps(data))\n",
" print(file_size/1000)\n",
"\n",
"\n",
"\n",
"# pprint.pprint(data[\"Requests\"])"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/zakst/code/watz-py/watz/client.py:36: UserWarning: Failed to connect to Watz API. Attempt 1 of 5.\n",
" return end_ping.call(self._session, ReqPing())\n",
"/home/zakst/code/watz-py/watz/client.py:36: UserWarning: Failed to connect to Watz API. Attempt 2 of 5.\n",
" return end_ping.call(self._session, ReqPing())\n",
"/home/zakst/code/watz-py/watz/client.py:36: UserWarning: Failed to connect to Watz API. Attempt 3 of 5.\n",
" return end_ping.call(self._session, ReqPing())\n",
"/home/zakst/code/watz-py/watz/client.py:36: UserWarning: Failed to connect to Watz API. Attempt 4 of 5.\n",
" return end_ping.call(self._session, ReqPing())\n",
"/home/zakst/code/watz-py/watz/client.py:36: UserWarning: Failed to connect to Watz API. Attempt 5 of 5.\n",
" return end_ping.call(self._session, ReqPing())\n"
]
},
{
"ename": "ConnectError",
"evalue": "Failed to connect to Watz API after 5 attempts.",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mConnectError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/home/zakst/code/watz-py/notebooks/scratch_space.ipynb Cell 1\u001b[0m line \u001b[0;36m4\n\u001b[1;32m <a href='vscode-notebook-cell:/home/zakst/code/watz-py/notebooks/scratch_space.ipynb#W0sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mwatz\u001b[39;00m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/zakst/code/watz-py/notebooks/scratch_space.ipynb#W0sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m client \u001b[39m=\u001b[39m watz\u001b[39m.\u001b[39mClient(base\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mhttp://localhost:3000\u001b[39m\u001b[39m\"\u001b[39m, secret\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mafb48q5s.GJmVKAk9sSrsSD2qoIdIwxjYjjuY8uMK\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m----> <a href='vscode-notebook-cell:/home/zakst/code/watz-py/notebooks/scratch_space.ipynb#W0sZmlsZQ%3D%3D?line=3'>4</a>\u001b[0m client\u001b[39m.\u001b[39;49mping()\n",
"File \u001b[0;32m~/code/watz-py/watz/client.py:36\u001b[0m, in \u001b[0;36mClient.ping\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 30\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mping\u001b[39m(\u001b[39mself\u001b[39m) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m RespPing:\n\u001b[1;32m 31\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"Ping the API.\u001b[39;00m\n\u001b[1;32m 32\u001b[0m \n\u001b[1;32m 33\u001b[0m \u001b[39m Returns:\u001b[39;00m\n\u001b[1;32m 34\u001b[0m \u001b[39m RespPing: The response from the API.\u001b[39;00m\n\u001b[1;32m 35\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m---> 36\u001b[0m \u001b[39mreturn\u001b[39;00m end_ping\u001b[39m.\u001b[39;49mcall(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_session, ReqPing())\n",
"File \u001b[0;32m~/code/watz-py/watz/endpoints/_endpoint.py:35\u001b[0m, in \u001b[0;36mEndpoint.call\u001b[0;34m(self, session, req)\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mcall\u001b[39m(\u001b[39mself\u001b[39m, session: httpx\u001b[39m.\u001b[39mClient, req: Req_T) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Resp_T:\n\u001b[0;32m---> 35\u001b[0m resp \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_req(session, req)\n\u001b[1;32m 36\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_parse(resp)\n",
"File \u001b[0;32m~/code/watz-py/watz/endpoints/_endpoint.py:53\u001b[0m, in \u001b[0;36mEndpoint._req\u001b[0;34m(self, session, req)\u001b[0m\n\u001b[1;32m 48\u001b[0m warnings\u001b[39m.\u001b[39mwarn(\n\u001b[1;32m 49\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mFailed to connect to Watz API. Attempt \u001b[39m\u001b[39m{}\u001b[39;00m\u001b[39m of 5.\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m.\u001b[39mformat(x \u001b[39m+\u001b[39m \u001b[39m1\u001b[39m), stacklevel\u001b[39m=\u001b[39m\u001b[39m3\u001b[39m\n\u001b[1;32m 50\u001b[0m )\n\u001b[1;32m 51\u001b[0m time\u001b[39m.\u001b[39msleep(\u001b[39m0.5\u001b[39m)\n\u001b[0;32m---> 53\u001b[0m \u001b[39mraise\u001b[39;00m httpx\u001b[39m.\u001b[39mConnectError(\u001b[39m\"\u001b[39m\u001b[39mFailed to connect to Watz API after 5 attempts.\u001b[39m\u001b[39m\"\u001b[39m)\n",
"\u001b[0;31mConnectError\u001b[0m: Failed to connect to Watz API after 5 attempts."
]
}
],
"source": [
"# import watz\n",
"\n",
"client = watz.Client(base=\"http://localhost:3000\", secret=\"afb48q5s.GJmVKAk9sSrsSD2qoIdIwxjYjjuY8uMK\")\n",
"client.ping()\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 60b83db

Please sign in to comment.