Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit c8cdf56

Browse files
all: add sphinx documentation generation, some documentation fixes
GitOrigin-RevId: 4a415414ce59b9baba01d71baf021779a7ef2b74
1 parent 273087e commit c8cdf56

File tree

14 files changed

+114
-30
lines changed

14 files changed

+114
-30
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
*.pyc
22
.idea
33
.coverage
4+
docs/build
5+
docs/rst

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ test:
1515
.PHONY: coverage
1616
coverage:
1717
python -m pytest --timeout=10 --cov=agora --cov-report term-missing tests .
18+
19+
.PHONY: docs
20+
docs:
21+
sphinx-apidoc agora/ -o docs/rst
22+
sphinx-build -b html docs/ docs/build

agora/client/client.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from agora.client.environment import Environment
1212
from agora.client.utils import public_key_to_address, quarks_to_kin_str
1313
from agora.error import AccountExistsError, AccountNotFoundError, InvoiceError, InvoiceErrorReason, \
14-
UnsupportedVersionError, TransactionMalformedError, SenderDoesNotExistError, \
15-
DestinationDoesNotExistError, InsufficientBalanceError, InsufficientFeeError, BadNonceError, OperationInvoiceError, \
16-
TransactionRejectedError, TransactionError, Error
14+
UnsupportedVersionError, TransactionMalformedError, SenderDoesNotExistError, InsufficientBalanceError, \
15+
DestinationDoesNotExistError, InsufficientFeeError, BadNonceError, \
16+
OperationInvoiceError, TransactionRejectedError, TransactionError, Error
1717
from agora.model.earn import Earn
1818
from agora.model.invoice import InvoiceList
1919
from agora.model.memo import AgoraMemo
@@ -92,7 +92,7 @@ def get_transaction(self, tx_hash: bytes) -> TransactionData:
9292
"""Retrieves a transaction.
9393
9494
:param tx_hash: The hash of the transaction to retrieve
95-
:return: a :class:`TransactionData <agora.transaction.TransactionData>` object.
95+
:return: a :class:`TransactionData <agora.model.transaction.TransactionData>` object.
9696
"""
9797
raise NotImplementedError("BaseClient is an abstract class. Subclasses must implement get_transaction")
9898

@@ -109,7 +109,7 @@ def get_balance(self, public_key: bytes) -> int:
109109
def submit_payment(self, payment: Payment) -> bytes:
110110
"""Submits a payment to the Kin blockchain.
111111
112-
:param payment: The :class:`Payment <agora.payment.Payment>` to submit.
112+
:param payment: The :class:`Payment <agora.model.payment.Payment>` to submit.
113113
114114
:raise: :exc:`UnsupportedVersionError <agora.error.UnsupportedVersionError>`
115115
:raise: :exc:`TransactionMalformedError <agora.error.TransactionMalformedError>`
@@ -140,7 +140,7 @@ def submit_earn_batch(
140140
141141
:raise: :exc:`UnsupportedVersionError <agora.error.UnsupportedVersionError>`
142142
143-
:return a :class:`BatchEarnResult <agora.results.BatchEarnResult>`
143+
:return: a :class:`BatchEarnResult <agora.model.result.BatchEarnResult>`
144144
"""
145145
raise NotImplementedError("BaseClient is an abstract class. Subclasses must implement submit_earn_batch")
146146

@@ -290,7 +290,7 @@ def submit_earn_batch(
290290
def _submit_payment_tx(self, payment: Payment) -> bytes:
291291
""" Submits a payment transaction.
292292
293-
:param payment: The :class:`Payment <agora.payment.Payment>` to submit.
293+
:param payment: The :class:`Payment <agora.model.payment.Payment>` to submit.
294294
:return: The transaction hash.
295295
"""
296296
tx_source = payment.source if payment.source else payment.sender
@@ -334,7 +334,7 @@ def _submit_earn_batch_tx(
334334
:param memo: (optional) The memo to include in the transaction. If set, none of the invoices included in earns
335335
will be applied.
336336
337-
:return a :class:`BatchEarnResult <agora.results.BatchEarnResult>`
337+
:return: a list of :class:`BatchEarnResult <agora.model.result.EarnResult>` objects
338338
"""
339339
if len(earns) > 100:
340340
raise ValueError("cannot send more than 100 earns")
@@ -429,11 +429,13 @@ def _submit_stellar_transaction(
429429
) -> bytes:
430430
"""Submit a stellar transaction to Agora.
431431
:param tx_bytes: The transaction envelope xdr, in bytes
432-
:param invoice_list: (optional) An :class:`InvoiceList <agora.invoice.InvoiceList>` to associate with the
432+
:param invoice_list: (optional) An :class:`InvoiceList <agora.model.invoice.InvoiceList>` to associate with the
433433
transaction
434+
:raise: :exc:`TransactionRejectedError <agora.error.TransactionRejectedError>`: if the transaction was rejected
435+
by the configured app's webhook
434436
:raise: :exc:`InvoiceError <agora.error.InvoiceError>`: if the transaction failed for a invoice-related reason.
435-
:raise: :exc:`StellarTransactionError <agora.error.StellarTransactionError>`: if the transaction failed
436-
upon submission to the blockchain.
437+
:raise: :exc:`TransactionError <agora.error.TransactionError>`: if the transaction failed upon submission to the
438+
blockchain.
437439
:return: The transaction hash
438440
"""
439441

agora/client/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def kin_to_quarks(kin: float) -> int:
1010
"""Converts a kin amount to quarks, with rounding. Uses the ROUND_HALF_UP method.
1111
1212
:param kin: An amount, in Kin.
13-
:return A integer quark amount.
13+
:return: A integer quark amount.
1414
"""
1515
return int((decimal.Decimal(kin) * _KIN_TO_QUARKS).quantize(decimal.Decimal('0.00001'),
1616
rounding=decimal.ROUND_HALF_UP).to_integral_value())
@@ -20,7 +20,7 @@ def quarks_to_kin(quarks: int) -> float:
2020
"""Converts an amount of quarks to kin.
2121
2222
:param quarks: An amount, in quarks.
23-
:return A float Kin amount.
23+
:return: A float Kin amount.
2424
"""
2525
return float((decimal.Decimal(quarks) / _KIN_TO_QUARKS))
2626

agora/model/earn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Earn(object):
88
99
:param destination: The public key, in raw bytes, of the account the earn will be sent to.
1010
:param quarks: The amount being sent.
11-
:param invoice: (optional) An :class:`Invoice <agora.invoice.Invoice>` object to associate with this earn.
11+
:param invoice: (optional) An :class:`Invoice <agora.model.invoice.Invoice>` object to associate with this earn.
1212
"""
1313

1414
def __init__(self, destination: bytes, quarks: int, invoice: Optional[Invoice] = None):

agora/model/invoice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ def to_proto(self) -> model_pb2.InvoiceList:
9292
def get_sha_224_hash(self) -> bytes:
9393
"""Returns the SHA-224 of the marshaled protobuf form of this invoice.
9494
95-
:return the SHA-224 hash.
95+
:return: the SHA-224 hash.
9696
"""
9797
return hashlib.sha224(self.to_proto().SerializeToString()).digest()

agora/model/memo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def new(cls, version: int, tx_type: TransactionType, app_index: int, foreign_key
3131
"""Returns an Agora memo containing the provided properties.
3232
3333
:param version: The memo encoding version
34-
:param tx_type: The :class:`TransactionType <agora.transaction_type.TransactionType>` of the transaction
34+
:param tx_type: The :class:`TransactionType <agora.model.transaction_type.TransactionType>` of the transaction
3535
:param app_index: The index of the app the transaction relates to
3636
:param foreign_key: An identifier in an auxiliary service that contains additional data about what the
3737
transaction was for
@@ -119,7 +119,7 @@ def is_valid(self) -> bool:
119119
Stricter validation can be done via :meth:`AgoraMemo.is_valid_strict`. However,
120120
:meth:`AgoraMemo.is_valid_strict` is not as forward compatible.
121121
122-
:return A bool indicating whether the memo is valid
122+
:return: A bool indicating whether the memo is valid
123123
"""
124124
if self.val[0] & 0x3 != MAGIC_BYTE:
125125
return False
@@ -150,9 +150,9 @@ def version(self) -> int:
150150
return (self.val[0] & 0x1c) >> 2
151151

152152
def tx_type(self) -> TransactionType:
153-
"""Returns the :class:`TransactionType <agora.transaction_type.TransactionType>` of this memo.
153+
"""Returns the :class:`TransactionType <agora.model.transaction_type.TransactionType>` of this memo.
154154
155-
:return: :class:`TransactionType <agora.transaction_type.TransactionType>`
155+
:return: :class:`TransactionType <agora.model.transaction_type.TransactionType>`
156156
"""
157157
try:
158158
return TransactionType(self.tx_type_raw())

agora/model/payment.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ class Payment(object):
1515
1616
:param sender: The secret seed, in raw bytes, of the account from which funds will be sent.
1717
:param destination: The public key, in raw bytes, of the account to which funds will be sent.
18-
:param payment_type: The :class:`TransactionType <agora.transaction_type.TransactionType>` of this payment.
18+
:param payment_type: The :class:`TransactionType <agora.model.transaction_type.TransactionType>` of this payment.
1919
:param quarks: The amount being sent.
2020
:param source: (optional) The secret seed, in raw bytes, of the account that will act as the source of the
2121
transaction. If unset, the sender will be used as the transaction source.
2222
2323
On Stellar, this is where the transaction fee and sequence number is taken/chosen from.
2424
2525
On Solana, this is where the fee is taken from.
26-
:param invoice: (optional) An :class:`Invoice <agora.invoice.Invoice>` to associate with this payment. Only one of
27-
invoice or memo should be set.
26+
:param invoice: (optional) An :class:`Invoice <agora.model.invoice.Invoice>` to associate with this payment. Only
27+
one of invoice or memo should be set.
2828
:param memo: (optional) The text memo to include with the transaction. Only one of invoice or memo should be set.
2929
"""
3030

@@ -65,8 +65,8 @@ class ReadOnlyPayment(object):
6565
:param dest: The public key, in raw bytes, of the destination account.
6666
:param payment_type: The type of this payment.
6767
:param quarks: The amount of the payment.
68-
:param invoice: (optional) The :class:`Invoice <agora.invoice.Invoice>` associated with this payment. Only one of
69-
invoice or memo will be set.
68+
:param invoice: (optional) The :class:`Invoice <agora.model.invoice.Invoice>` associated with this payment. Only one
69+
of invoice or memo will be set.
7070
:param memo: (optional) The text memo associated with this transaction. Only one of invoice or memo will be set.
7171
"""
7272

agora/model/transaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class TransactionData(object):
1313
transaction.
1414
1515
:param tx_hash: The hash of the transaction.
16-
:param payments: (optional) A list of :class:`ReadOnlyPayment <agora.payment.ReadOnlyPayment>` objects.
17-
:param error: (optional)) A :class:`TransactionError <agora.error.TransactionError>` object that contians extra
16+
:param payments: (optional) A list of :class:`ReadOnlyPayment <agora.model.payment.ReadOnlyPayment>` objects.
17+
:param error: (optional)) A :class:`TransactionError <agora.error.TransactionError>` object that contains extra
1818
details about why a transaction failed. If present, it indicates that the transaction failed.
1919
"""
2020

agora/webhook/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def is_valid_signature(self, req_body: str, signature: str) -> bool:
2929
3030
:param req_body: The request body that the provided signature is supposedly for.
3131
:param signature: The base64-encoded signature to verify for the corresponding `req_body`.
32-
:return A bool indicating whether or not the signature is valid.
32+
:return: A bool indicating whether or not the signature is valid.
3333
"""
3434
decoded_sig = base64.b64decode(signature)
3535
calculated_sig = hmac.new(self.secret, req_body.encode(), hashlib.sha256).digest()

agora/webhook/sign_transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def from_json(cls, data: dict):
5151
def get_tx_hash(self) -> bytes:
5252
"""Returns the transaction hash of the transaction being signed.
5353
54-
:return The transaction hash, in bytes.
54+
:return: The transaction hash, in bytes.
5555
"""
5656
return self.envelope.hash_meta()
5757

docs/conf.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
# import os
14+
# import sys
15+
# sys.path.insert(0, os.path.abspath('.'))
16+
17+
import os
18+
import sys
19+
sys.path.insert(0, os.path.abspath('../'))
20+
21+
22+
# -- Project information -----------------------------------------------------
23+
24+
project = 'Kin Python SDK'
25+
copyright = '2020, Kik Engineering'
26+
author = 'Kik Engineering'
27+
28+
# The full version, including alpha/beta/rc tags
29+
release = '0.1.0'
30+
31+
# -- General configuration ---
32+
33+
# Add any Sphinx extension module names here, as strings. They can be
34+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
35+
# ones.
36+
extensions = [
37+
'sphinx.ext.autodoc',
38+
'sphinx.ext.viewcode',
39+
'sphinx_autodoc_typehints'
40+
]
41+
42+
# List of patterns, relative to source directory, that match files and
43+
# directories to ignore when looking for source files.
44+
# This pattern also affects html_static_path and html_extra_path.
45+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
46+
47+
48+
# -- Options for HTML output -
49+
50+
# The theme to use for HTML and HTML Help pages. See the documentation for
51+
# a list of builtin themes.
52+
#
53+
html_theme = 'alabaster'

docs/index.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. Kin Python SDK documentation master file, created by
2+
sphinx-quickstart on Sun Jul 26 23:37:08 2020.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to Kin Python SDK's documentation!
7+
==========================================
8+
9+
.. toctree::
10+
:maxdepth: 3
11+
:caption: Contents:
12+
13+
14+
15+
Indices and tables
16+
==================
17+
18+
* :ref:`genindex`
19+
* :ref:`modindex`
20+
* :ref:`search`

requirements.dev.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
Flask==1.1.2
2+
grpcio-testing==1.30.0
13
pytest==5.4.3
24
pytest-cov==2.10.0
35
pytest-mock==3.2.0
46
pytest-timeout==1.4.1
5-
grpcio-testing==1.30.0
6-
Flask==1.1.2
7+
sphinx==3.1.2
8+
sphinx-autodoc-typehints==1.11.0

0 commit comments

Comments
 (0)