-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Sphinx documentation builder and added doc comments (#107)
* Added empty but configured Sphinx project * Added bulk of documentation * Added RTD config file * Renamed doc to docs * Squashed commits with RTD build attempts - Unsucceful in the end Attempting to add apt install command to conf.py Moved attempt at install to setup.py instead Added Y flag to setup.py Added apt install did not work - Trying while skipping setup.py altogether Tried setting a default flag in setup.py for RTD Forgot to re-enable setup.py in RTD yml Changing from pip to setuptools build Reverted setup.py to master state, added comments in .readthedocs.yml
- Loading branch information
1 parent
4739f82
commit 8fdfb09
Showing
12 changed files
with
410 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,23 @@ | ||
# Build directories | ||
build/ | ||
dist/ | ||
MANIFEST | ||
hid.c | ||
hidraw.c | ||
.eggs/ | ||
hidapi.egg-info/ | ||
|
||
# Temp files | ||
hid.*.pyd | ||
|
||
# Testing | ||
.tox/ | ||
|
||
# IDE files | ||
.idea/ | ||
|
||
# Virtual environments | ||
venv/ | ||
|
||
# Doc output | ||
docs/_build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# .readthedocs.yml | ||
# Read the Docs configuration file | ||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details | ||
|
||
# Required | ||
version: 2 | ||
|
||
# Build documentation in the docs/ directory with Sphinx | ||
sphinx: | ||
configuration: docs/conf.py | ||
|
||
# Also checkout any submodules | ||
submodules: | ||
include: all | ||
|
||
# Optionally build your docs in additional formats such as PDF | ||
formats: | ||
|
||
# Optionally set the version of Python and requirements required to build your docs | ||
python: | ||
version: 3.8 | ||
install: | ||
- requirements: docs/requirements.txt | ||
- method: setuptools | ||
path: . | ||
|
||
# | ||
# Build on ReadTheDocs is not working because libusb and libudev are missing. | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# 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 | ||
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) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
API | ||
=== | ||
|
||
List devices | ||
------------ | ||
|
||
.. autofunction:: hid.enumerate | ||
|
||
|
||
Device class | ||
------------ | ||
|
||
.. autoclass:: hid.device | ||
:members: | ||
:undoc-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Configuration file for the Sphinx documentation builder. | ||
# | ||
# This file only contains a selection of the most common options. For a full | ||
# 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 sys | ||
sys.path.insert(0, os.path.abspath('../')) # Add root directory to path | ||
|
||
|
||
# -- Project information ----------------------------------------------------- | ||
|
||
project = 'HIDAPI' | ||
copyright = '2021, Trezor' | ||
author = 'Trezor' | ||
|
||
|
||
# -- 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', | ||
'recommonmark', | ||
] | ||
|
||
# Add any paths that contain templates here, relative to this directory. | ||
templates_path = ['_templates'] | ||
|
||
source_suffix = { | ||
'.rst': 'restructuredtext', | ||
'.md': 'markdown', | ||
} | ||
|
||
# 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'] | ||
|
||
|
||
# -- Options for HTML output ------------------------------------------------- | ||
|
||
# The theme to use for HTML and HTML Help pages. See the documentation for | ||
# a list of builtin themes. | ||
# | ||
html_theme = 'sphinx_rtd_theme' | ||
|
||
# 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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Examples | ||
|
||
## Finding devices | ||
|
||
List all info of all devices with: | ||
|
||
```python | ||
import hid | ||
|
||
for device_dict in hid.enumerate(): | ||
keys = list(device_dict.keys()) | ||
keys.sort() | ||
for key in keys: | ||
print("%s : %s" % (key, device_dict[key])) | ||
print() | ||
|
||
``` | ||
|
||
## Connecting, reading and writing | ||
|
||
```python | ||
try: | ||
print("Opening the device") | ||
|
||
h = hid.device() | ||
h.open(0x534C, 0x0001) # TREZOR VendorID/ProductID | ||
|
||
print("Manufacturer: %s" % h.get_manufacturer_string()) | ||
print("Product: %s" % h.get_product_string()) | ||
print("Serial No: %s" % h.get_serial_number_string()) | ||
|
||
# enable non-blocking mode | ||
h.set_nonblocking(1) | ||
|
||
# write some data to the device | ||
print("Write the data") | ||
h.write([0, 63, 35, 35] + [0] * 61) | ||
|
||
# wait | ||
time.sleep(0.05) | ||
|
||
# read back the answer | ||
print("Read the data") | ||
while True: | ||
d = h.read(64) | ||
if d: | ||
print(d) | ||
else: | ||
break | ||
|
||
print("Closing the device") | ||
h.close() | ||
|
||
except IOError as ex: | ||
print(ex) | ||
print("You probably don't have the hard-coded device.") | ||
print("Update the h.open() line in this script with the one") | ||
print("from the enumeration list output above and try again.") | ||
|
||
print("Done") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.. HIDAPI documentation master file, created by | ||
sphinx-quickstart on Tue Feb 9 09:56:35 2021. | ||
You can adapt this file completely to your liking, but it should at least | ||
contain the root `toctree` directive. | ||
Welcome to HIDAPI's documentation! | ||
================================== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
:caption: Contents: | ||
|
||
Home <self> | ||
examples.md | ||
api.rst | ||
|
||
|
||
Indices and tables | ||
================== | ||
|
||
* :ref:`genindex` | ||
* :ref:`modindex` | ||
* :ref:`search` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
sphinx | ||
sphinx-rtd-theme |
Oops, something went wrong.