Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Python doc polish #1757

Merged
merged 33 commits into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
303b1fa
Exercise doctests as a test not as a linter
feuGeneA Apr 3, 2019
2351648
Add a contract artifact doctest, and exercise it
feuGeneA Apr 3, 2019
db5756c
Clean up linter issues
feuGeneA Apr 3, 2019
49acd74
Change asset data decoding output type
feuGeneA Apr 3, 2019
0abc492
Add type annotations to JSON schemas docs
feuGeneA Apr 3, 2019
ca2df03
Add doc publish metadata file for middlewares pkg
feuGeneA Apr 3, 2019
95c83ac
Improve documentation
feuGeneA Apr 3, 2019
da2a64a
correct package name in doc URL
feuGeneA Apr 3, 2019
1ac390b
Move sra_client module into zero_ex namespace
feuGeneA Apr 3, 2019
9dab19b
Add functions to encode asset data to bytes
feuGeneA Apr 4, 2019
75d2ac5
Remove redundant test
feuGeneA Apr 6, 2019
2c4752f
Fix: SRA client was deserializing orders weirdly
feuGeneA Apr 6, 2019
dd7e433
Fix problem with Web3/JSON order conversion utils
feuGeneA Apr 6, 2019
ca6cb95
doctest: maker, trade ZRX for WETH, not vice versa
feuGeneA Apr 6, 2019
a23f5cf
Construct order in native Python, not JSON
feuGeneA Apr 6, 2019
0cad0f5
doctest: simplify asset units
feuGeneA Apr 6, 2019
b1ed091
Add doctests for filling and cancelling
feuGeneA Apr 6, 2019
6fc4521
Minor doctetst copy edits; whitespace
feuGeneA Apr 6, 2019
1c3fb40
Rename function, and add optional parameter
feuGeneA Apr 6, 2019
e36d61d
Tweak docstrings on JSON conversion functions.
feuGeneA Apr 6, 2019
3ab4948
Demo asset data decoding to view asset pairs
feuGeneA Apr 6, 2019
aa5f34c
Demo selecting an order from the order book
feuGeneA Apr 6, 2019
18a2e55
Rename variable
feuGeneA Apr 6, 2019
9928382
Abstract ganache from examples
feuGeneA Apr 6, 2019
8dc9c99
Add missing SRA client doc publication metadata
feuGeneA Apr 6, 2019
74ab455
Ran prettier on new SRA client doc pub metadata
feuGeneA Apr 6, 2019
01c9bae
Remove local env customizations in doc metadata
feuGeneA Apr 6, 2019
75e2442
Merge branch 'development' into feature/python-doc-polish
feuGeneA Apr 6, 2019
7498d54
Eliminate temporary variable
feuGeneA Apr 8, 2019
b2cde22
Rename variable
feuGeneA Apr 8, 2019
ace3971
Show `pip install` in every package's doc
feuGeneA Apr 8, 2019
4282ed7
Doc NetorkID & pagination params as int, not float
feuGeneA Apr 8, 2019
53daaaf
Clean up unmatched parenthesis in docs
feuGeneA Apr 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions python-packages/contract_addresses/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from distutils.command.clean import clean
import distutils.command.build_py
from setuptools import find_packages, setup
from setuptools.command.test import test as TestCommand


class LintCommand(distutils.command.build_py.build_py):
Expand All @@ -30,8 +31,6 @@ def run(self):
"mypy src setup.py".split(),
# security issue checker:
"bandit -r src ./setup.py".split(),
# run doctests:
"pytest --doctest-modules".split(),
# general linter:
"pylint src setup.py".split(),
# pylint takes relatively long to run, so it runs last, to enable
Expand Down Expand Up @@ -103,6 +102,16 @@ def run(self):
subprocess.check_call("discharge deploy".split()) # nosec


class TestCommandExtension(TestCommand):
"""Run pytest tests."""

def run_tests(self):
"""Invoke pytest."""
import pytest

exit(pytest.main(["--doctest-modules"]))


with open("README.md", "r") as file_handle:
README_MD = file_handle.read()

Expand All @@ -122,6 +131,7 @@ def run(self):
cmdclass={
"clean": CleanCommandExtension,
"lint": LintCommand,
"test": TestCommandExtension,
"test_publish": TestPublishCommand,
"publish": PublishCommand,
"publish_docs": PublishDocsCommand,
Expand Down
11 changes: 8 additions & 3 deletions python-packages/contract_addresses/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ Python zero_ex.contract_addresses
:maxdepth: 2
:caption: Contents:

.. autoclass:: zero_ex.contract_addresses.NetworkId
.. automodule:: zero_ex.contract_addresses
:no-members:

See source for enum members.
.. autoclass:: zero_ex.contract_addresses.NetworkId
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: zero_ex.contract_addresses.ContractAddresses
:members:
:show-inheritance:

.. autodata:: zero_ex.contract_addresses.NETWORK_TO_ADDRESSES
:annotation:
:annotation: : Dict[NetworkId, ContractAddresses]

Indices and tables
==================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,48 @@
from typing import Dict, NamedTuple


class ContractAddresses(NamedTuple): # noqa
class ContractAddresses(NamedTuple):
"""An abstract record listing all the contracts that have addresses."""

erc20_proxy: str
"""Address of the ERC20Proxy contract."""

erc721_proxy: str
"""Address of the ERC20Proxy contract."""

zrx_token: str
"""Address of the ZRX token contract."""

ether_token: str
"""Address of the WETH token contract."""

exchange: str
"""Address of the Exchange contract."""

asset_proxy_owner: str
"""Address of the AssetProxyOwner contract."""

forwarder: str
"""Address of the Forwarder contract."""

order_validator: str
"""Address of the OrderValidator contract."""

coordinator_registry: str
"""Address of the CoordinatorRegistry contract."""

coordinator: str
"""Address of the Coordinator contract."""


class NetworkId(Enum):
"""Network names correlated to their network identification numbers.

>>> NetworkId.MAINNET
<NetworkId.MAINNET: 1>

>>> NetworkId.MAINNET.value
1
"""

MAINNET = 1
Expand Down Expand Up @@ -98,7 +120,7 @@ class NetworkId(Enum):
"""A mapping from instances of NetworkId to instances of ContractAddresses.

Addresses under NetworkId.Ganache are from our Ganache snapshot generated from
migrations.
npm package @0x/migrations.

>>> NETWORK_TO_ADDRESSES[NetworkId.MAINNET].exchange
0x4f833a24e1f95d70f028921e27040ca56e09ab0b
Expand Down
12 changes: 12 additions & 0 deletions python-packages/contract_artifacts/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from distutils.command.clean import clean
import distutils.command.build_py
from setuptools import find_packages, setup
from setuptools.command.test import test as TestCommand


class LintCommand(distutils.command.build_py.build_py):
Expand Down Expand Up @@ -110,6 +111,16 @@ def run(self):
subprocess.check_call("discharge deploy".split()) # nosec


class TestCommandExtension(TestCommand):
"""Run pytest tests."""

def run_tests(self):
"""Invoke pytest."""
import pytest

exit(pytest.main(["--doctest-modules"]))


with open("README.md", "r") as file_handle:
README_MD = file_handle.read()

Expand All @@ -129,6 +140,7 @@ def run(self):
cmdclass={
"clean": CleanCommandExtension,
"lint": LintCommand,
"test": TestCommandExtension,
"test_publish": TestPublishCommand,
"publish": PublishCommand,
"publish_docs": PublishDocsCommand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,21 @@ def contract_name_to_abi(cls, contract_name: str) -> Dict:


def abi_by_name(contract_name: str) -> Dict:
"""Return the ABI for the named contract."""
"""Return the ABI for the named contract.

Contract names must correspond to files in the package's `artifacts`:code:
directory, without the `.json`:code: suffix.

>>> from pprint import pprint
>>> pprint(abi_by_name("IValidator"))
[{'constant': True,
'inputs': [{'name': 'hash', 'type': 'bytes32'},
{'name': 'signerAddress', 'type': 'address'},
{'name': 'signature', 'type': 'bytes'}],
'name': 'isValidSignature',
'outputs': [{'name': 'isValid', 'type': 'bool'}],
'payable': False,
'stateMutability': 'view',
'type': 'function'}]
"""
return _ArtifactCache.contract_name_to_abi(contract_name)
6 changes: 4 additions & 2 deletions python-packages/contract_wrappers/.pylintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[MESSAGES CONTROL]
disable=C0330,line-too-long,fixme,too-few-public-methods,too-many-ancestors,too-many-arguments
disable=C0330,line-too-long,fixme,too-few-public-methods,too-many-ancestors
# C0330 is "bad hanging indent". we use indents per `black`.
min-similarity-lines=10

[SIMILARITIES]
min-similarity-lines=6
13 changes: 6 additions & 7 deletions python-packages/contract_wrappers/src/index.rst
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
Python zero_ex.contract_wrappers
================================================
================================

.. toctree::
:maxdepth: 2
:caption: Contents:

.. automodule:: zero_ex.contract_wrappers
:members:
:inherited-members:


zero_ex.contract_wrappers.Exchange
----------------------------------
==================================

.. autoclass:: zero_ex.contract_wrappers.Exchange
:members:
:inherited-members:
:special-members:


zero_ex.contract_wrappers.ERC20Token
-------------------------------------
====================================

.. autoclass:: zero_ex.contract_wrappers.ERC20Token
:members:
:inherited-members:
:special-members:


zero_ex.contract_wrappers.TxParams
----------------------------------
==================================

.. autoclass:: zero_ex.contract_wrappers.TxParams
:members:
Expand Down
Loading