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

Python doc polish #1757

merged 33 commits into from
Apr 30, 2019

Conversation

feuGeneA
Copy link
Contributor

@feuGeneA feuGeneA commented Apr 4, 2019

Description

After the recent bounty to fully document all of our Python offerings with code examples, I polished things up, mostly copy editing (incl. code examples) for conciseness and improved flow.

The rendered docs are accessible at the links below. I suggest not reviewing the "Improve documentation" commit (which, btw, encompasses the bulk of the changes in this PR), and instead just review the rendered docs.

Do note that virtually all of this documentation is rendered from "docstings" in the source code. (In Python, a docstring is simply a string literal that's ignored at runtime but that documents a module, method, etc, depending on its context.) The rendering is done by Sphinx, which to my understanding is powerfully customizable, so in theory we could make the rendering look however we wanted. However, I don't know much about this tool, as I have barely scratched the surface of its usage.

Also note that all of the code examples are "doctests." (In Python, doctests are code snippets that can be exercised in an automated way.) When we run our unit tests (in CI and locally), we also test our doctests. So, when CI is clean, you know those examples are working.

Types of changes

  • New feature (non-breaking change which adds functionality)

Future work

Outside the scope of this PR...

Ensuring ease of conversion between Python object and JSON

Edit: I knocked this out on Future Focused Friday.

In scrubbing this code with such scrutiny, it has come to my attention that there's one remaining thing that's still not as easy as it should be: moving order objects between Web3.py-compatibility and Relayer-compatibility.

To submit an order to our contracts via web3.py the order object must have Python-native data types (asset data as bytes, numbers as ints, etc), but when working with a Relayer the order must be in JSON (asset data as hex strings, numbers as strings, etc). We have provided convenience methods for converting between the two types, but we should write some more tests/examples/documentation around that.

Specifically, I think we should modify the SRA Client examples to declare the order as a web3.py-compatible object (currently it starts out as JSON), then convert it to JSON and submit it to the relayer (launch kit), then have a separate taker account get the order and fill it (which will require converting it back from JSON to a web3.py-compatible object). Doing this may well reveal worthwhile changes to our Python API.

Integrating docs with 0x.org

The URLs for these docs are ugly. You see those staging URLs above, but they're not really any different from the "real" doc locations. (Just take out the -staging part, and you have it.) We should consider altering the rendering to fit our design motifs (see discussion of Sphinx above), and we should host them at friendlier URLs. If desirable, we may be able to get Sphinx to render everything into one giant doc, rather than one per package.

Checklist

  • Ensure pip install instructions are consistent across the docs (some were missing it).
  • Correct SRA client documentation describing Network ID and pagination parameters as floats.
  • Clean up unmatched parenthesis in doc of return value of *_with_http_info() methods in SRA client.

feuGeneA added 10 commits April 4, 2019 10:28
Previously, it was a TypedDict, but that was causing problems.  Sphinx
seems to be broken, such that none of the fields of the class were being
rendered into the doc.

Thinking on it further, I decided that a NamedTuple makes more sense
here anyways, since tuples are immutable and this output value isn't
something someone should ever build or modify.  And, NamedTuple is
getting its fields properly rendered by Sphinx.
Note that none of the changes to .py files impact functionality in any
way, because the changes are restricted to "docstrings", which to the
Python interpreter are simply no-op statements.

However, one caveat to that is that much of these docstring changes DO
affect the functionality of automated test runs, because all of the code
examples (blocks beginning with `>>> `) are "doctests", which are
exercised via the test framework.

The index.rst files are the top-level templates for generating the
documentation, and the "automodule"/"autoclass"/etc statements pull in
the docstrings from the source code.
@PirosB3
Copy link
Contributor

PirosB3 commented Apr 5, 2019

Eugene! this documentation is really amazing! thanks for putting this together. I took a look at all the rendered documentation and I want to share my comments. Most of these comments are broad across all the documentation:

  1. Many times you mention names of products or networks within the Ethereum ecosystem (for example: Infura, Ganache). While 99% of Ethereum developers will know what you are speaking about, the 1% would probably appreciate linking these terms to the appropriate documentation.

  2. All libraries have a namespace of zero_ex. What's interesting is that, if I install one of these libraries (python -m pip install 0x-sra-client) I don't get thezero_ex namespace

>>> from zero_ex.sra_client import ApiClient, Configuration, DefaultApi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'zero_ex'
>>> from sra_client import ApiClient, Configuration, DefaultApi

Are we sure the zero_ex namespace is always installed?

  1. When you mention cancels having to deal with the blockchain directly (without going through the SRA) maybe it would be nice to mention the TEC and how this can benefit cancels in the future? just a thought.

  2. In a good part of the documentation, arguments to functions that are considered integers (ex. network_id) are mentioned as floats in the function signatures. An example is get_order_config(). Why is this?

  3. Aside from the SRA and order-wrapper, I don't see many of these packages having a traditional "pip install" page. Putting myself in the shoes of a end-user: how do I actually install these libraries?

Copy link
Contributor

@PirosB3 PirosB3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from my notes, this doc is really great!

@feuGeneA
Copy link
Contributor Author

feuGeneA commented Apr 5, 2019

@PirosB3 thanks for the great feedback!

  1. All libraries have a namespace of zero_ex. What's interesting is that, if I install one of these libraries (python -m pip install 0x-sra-client) I don't get thezero_ex namespace
>>> from zero_ex.sra_client import ApiClient, Configuration, DefaultApi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'zero_ex'
>>> from sra_client import ApiClient, Configuration, DefaultApi

Are we sure the zero_ex namespace is always installed?

0x-sra-client is a special case here, as it formerly was not in the zero_ex namespace, and in this PR I've corrected that. Further, the packages that were recently introduced by the bounty work (0x-contract-wrappers, and 0x-middlwares) have not yet been published, so at this point you can only install them from the repo (eg python-packages/contract_wrappers$ pip install -e .). If you experience this problem with any of the already-published packages (that aren't sra_client) please let me know.

  1. In a good part of the documentation, arguments to functions that are considered integers (ex. network_id) are mentioned as floats in the function signatures. An example is get_order_config(). Why is this?

Yeah, I noticed that myself and wasn't sure whether it was worth addressing. This bulk of the SRA client was generated from the SRA spec (see generate.sh in this component), and that's how it came out. Looking closer, tt's because there are lots of places in the spec where we use "type":"number" where we really should be using "type":"integer". So, technically it's a bug in the spec, which I've just raised (#1762), but I'll correct it here.

  1. Aside from the SRA and order-wrapper, I don't see many of these packages having a traditional "pip install" page. Putting myself in the shoes of a end-user: how do I actually install these libraries?

Good call, I'll add pip install instructions where they're missing. I hadn't put them in my own docs, but the bounty guys did, so that's why they're inconsistent.

feuGeneA added 9 commits April 5, 2019 23:14
The generated code was transforming the order structure, from the camel
case field name format in the spec, into the snake case field name
format expected by Python convention.  With this problem in place, the
only way to take an order from a relayer and send it to a contract (for
fill, cancel, etc) was to manually transform the field names, one by
one, into a new structure.
Then convert it to JSON before sending it to the relayer.
@coveralls
Copy link

coveralls commented Apr 6, 2019

Coverage Status

Coverage decreased (-0.008%) to 85.376% when pulling 53daaaf on feature/python-doc-polish into 2ff5c39 on development.

@feuGeneA
Copy link
Contributor Author

feuGeneA commented Apr 6, 2019

I spent my Future Focused Friday knocking off that "Future Work" item in my PR description about ease of JSON conversion. The SRA demo now goes from native Python, converted to JSON for submission to relayer, and then back from relayer JSON to native Python, demonstrating both a fill and a cancel.

feuGeneA added 8 commits April 6, 2019 00:07
Doing that exposed excessive use of the verbose
NETWORK_TO_ADDRESSES[NetworkId.Ganache] construct, so simplified that,
which ripped into eliminating other temporary variables that had been
used to hold specific contract addresses.

Also cleaned up some misplaced import statements.
@feuGeneA feuGeneA requested a review from PirosB3 April 6, 2019 16:49
@PirosB3
Copy link
Contributor

PirosB3 commented Apr 8, 2019

Hi @feuGeneA thanks for the great update! Have you re-rendered documentation since you made those changes we discussed? can I go ahead with another review?

@feuGeneA
Copy link
Contributor Author

feuGeneA commented Apr 8, 2019

@PirosB3 yes, I did update the rendered docs at the links in my initial comment with the latest changes. Please do go ahead with another review :) Thanks!

Copy link
Contributor

@PirosB3 PirosB3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes!

@feuGeneA feuGeneA merged commit 0564ac1 into development Apr 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants