Move zero_ex.json_schemas to its own package

This commit is contained in:
F. Eugene Aumson 2018-12-12 17:47:25 -08:00
parent f9a6c45a03
commit b6c8126589
No known key found for this signature in database
GPG Key ID: 23E6737B1374A24A
31 changed files with 474 additions and 12 deletions

View File

@ -200,6 +200,11 @@ jobs:
- run: sudo chown -R circleci:circleci /usr/local/lib/python3.7/site-packages
- restore_cache:
key: deps9-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
- run:
command: |
cd python-packages/json_schemas
python -m ensurepip
python -m pip install .
- run:
command: |
cd python-packages/order_utils
@ -219,6 +224,10 @@ jobs:
- '.mypy_cache'
- '.pytest_cache'
- '.tox'
- run:
command: |
cd python-packages/json_schemas
coverage run setup.py test
- run:
command: |
cd python-packages/order_utils
@ -227,6 +236,10 @@ jobs:
command: |
cd python-packages/sra_client
coverage run setup.py test
- save_cache:
key: coverage-python-json-schemas-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ~/repo/python-packages/json_schemas/.coverage
- save_cache:
key: coverage-python-order-utils-{{ .Environment.CIRCLE_SHA1 }}
paths:
@ -273,6 +286,11 @@ jobs:
- run: sudo chown -R circleci:circleci /usr/local/lib/python3.7/site-packages
- restore_cache:
key: deps9-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
- run:
command: |
cd python-packages/json_schemas
python -m ensurepip
python -m pip install .
- run:
command: |
cd python-packages/order_utils
@ -283,6 +301,10 @@ jobs:
paths:
- '/usr/local/bin'
- '/usr/local/lib/python3.7/site-packages'
- run:
command: |
cd python-packages/json_schemas
python setup.py lint
- run:
command: |
cd python-packages/order_utils
@ -355,6 +377,9 @@ jobs:
- restore_cache:
keys:
- coverage-contracts-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-python-json-schemas-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-python-order-utils-{{ .Environment.CIRCLE_SHA1 }}

View File

@ -20,7 +20,7 @@ lib
/packages/contract-artifacts/artifacts
/python-packages/order_utils/src/zero_ex/contract_artifacts/artifacts
/packages/json-schemas/schemas
/python-packages/order_utils/src/zero_ex/json_schemas/schemas
/python-packages/json_schemas/src/zero_ex/json_schemas/schemas
/packages/metacoin/src/contract_wrappers
/packages/metacoin/artifacts
/packages/sra-spec/public/

View File

@ -24,10 +24,11 @@ Visit our [developer portal](https://0xproject.com/docs/order-utils) for a compr
### Python Packages
| Package | Version | Description |
| ------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| [`0x-order-utils`](/python-packages/order_utils) | [![PyPI](https://img.shields.io/pypi/v/0x-order-utils.svg)](https://pypi.org/project/0x-order-utils/) | A set of utilities for generating, parsing, signing and validating 0x orders |
| [`0x-sra-client`](/python-packages/sra_client) | [![PyPI](https://img.shields.io/pypi/v/0x-sra-client.svg)](https://pypi.org/project/0x-sra-client/) | A Python client for interacting with servers conforming to the Standard Relayer API specification |
| Package | Version | Description |
| -------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| [`0x-json-schemas`](/python-packages/json_schemas) | [![PyPI](https://img.shields.io/pypi/v/0x-json-schemas.svg)](https://pypi.org/project/0x-json-schemas/) | 0x-related JSON schemas |
| [`0x-order-utils`](/python-packages/order_utils) | [![PyPI](https://img.shields.io/pypi/v/0x-order-utils.svg)](https://pypi.org/project/0x-order-utils/) | A set of utilities for generating, parsing, signing and validating 0x orders |
| [`0x-sra-client`](/python-packages/sra_client) | [![PyPI](https://img.shields.io/pypi/v/0x-sra-client.svg)](https://pypi.org/project/0x-sra-client/) | A Python client for interacting with servers conforming to the Standard Relayer API specification |
### Typescript/Javascript Packages

View File

@ -0,0 +1,13 @@
{
"domain": "0x-json-schemas-py",
"build_command": "python setup.py build_sphinx",
"upload_directory": "build/docs/html",
"index_key": "index.html",
"error_key": "index.html",
"trailing_slashes": true,
"cache": 3600,
"aws_profile": "default",
"aws_region": "us-east-1",
"cdn": false,
"dns_configured": true
}

View File

@ -0,0 +1,3 @@
[MESSAGES CONTROL]
disable=C0330,line-too-long,fixme,too-few-public-methods,too-many-ancestors
# C0330 is "bad hanging indent". we use indents per `black`.

View File

@ -0,0 +1,45 @@
## 0x-json-schemas
0x JSON schemas for those developing on top of 0x protocol.
Read the [documentation](http://0x-json-schemas-py.s3-website-us-east-1.amazonaws.com/)
## Installing
```bash
pip install 0x-json-schemas
```
## Contributing
We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository.
Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
### Install Code and Dependencies
Ensure that you have installed Python >=3.6 and Docker. Then:
```bash
pip install -e .[dev]
```
### Test
Tests depend on a running ganache instance with the 0x contracts deployed in it. For convenience, a docker container is provided that has ganache-cli and a snapshot containing the necessary contracts. A shortcut is provided to run that docker container: `./setup.py ganache`. With that running, the tests can be run with `./setup.py test`.
### Clean
`./setup.py clean --all`
### Lint
`./setup.py lint`
### Build Documentation
`./setup.py build_sphinx`
### More
See `./setup.py --help-commands` for more info.

View File

@ -0,0 +1,191 @@
#!/usr/bin/env python
"""setuptools module for json_schemas package."""
import distutils.command.build_py
from distutils.command.clean import clean
import subprocess # nosec
from shutil import rmtree
from os import environ, path
from sys import argv
from setuptools import find_packages, setup
from setuptools.command.test import test as TestCommand
class TestCommandExtension(TestCommand):
"""Run pytest tests."""
def run_tests(self):
"""Invoke pytest."""
import pytest
exit(pytest.main())
class LintCommand(distutils.command.build_py.build_py):
"""Custom setuptools command class for running linters."""
description = "Run linters"
def run(self):
"""Run linter shell commands."""
lint_commands = [
# formatter:
"black --line-length 79 --check --diff src test setup.py".split(),
# style guide checker (formerly pep8):
"pycodestyle src test setup.py".split(),
# docstring style checker:
"pydocstyle src test setup.py".split(),
# static type checker:
"mypy src test setup.py".split(),
# security issue checker:
"bandit -r src ./setup.py".split(),
# general linter:
"pylint src test setup.py".split(),
# pylint takes relatively long to run, so it runs last, to enable
# fast failures.
]
# tell mypy where to find interface stubs for 3rd party libs
environ["MYPYPATH"] = path.join(
path.dirname(path.realpath(argv[0])), "stubs"
)
for lint_command in lint_commands:
print(
"Running lint command `", " ".join(lint_command).strip(), "`"
)
subprocess.check_call(lint_command) # nosec
class CleanCommandExtension(clean):
"""Custom command to do custom cleanup."""
def run(self):
"""Run the regular clean, followed by our custom commands."""
super().run()
rmtree("dist", ignore_errors=True)
rmtree(".mypy_cache", ignore_errors=True)
rmtree(".tox", ignore_errors=True)
rmtree(".pytest_cache", ignore_errors=True)
rmtree("src/*.egg-info", ignore_errors=True)
class TestPublishCommand(distutils.command.build_py.build_py):
"""Custom command to publish to test.pypi.org."""
description = (
"Publish dist/* to test.pypi.org. Run sdist & bdist_wheel first."
)
def run(self):
"""Run twine to upload to test.pypi.org."""
subprocess.check_call( # nosec
(
"twine upload --repository-url https://test.pypi.org/legacy/"
+ " --verbose dist/*"
).split()
)
class PublishCommand(distutils.command.build_py.build_py):
"""Custom command to publish to pypi.org."""
description = "Publish dist/* to pypi.org. Run sdist & bdist_wheel first."
def run(self):
"""Run twine to upload to pypi.org."""
subprocess.check_call("twine upload dist/*".split()) # nosec
class PublishDocsCommand(distutils.command.build_py.build_py):
"""Custom command to publish docs to S3."""
description = (
"Publish docs to "
+ "http://0x-json-schemas-py.s3-website-us-east-1.amazonaws.com/"
)
def run(self):
"""Run npm package `discharge` to build & upload docs."""
subprocess.check_call("discharge deploy".split()) # nosec
with open("README.md", "r") as file_handle:
README_MD = file_handle.read()
setup(
name="0x-json-schemas",
version="1.0.0",
description="JSON schemas for 0x applications",
long_description=README_MD,
long_description_content_type="text/markdown",
url=(
"https://github.com/0xProject/0x-monorepo/tree/development"
+ "/python-packages/json_schemas"
),
author="F. Eugene Aumson",
author_email="feuGeneA@users.noreply.github.com",
cmdclass={
"clean": CleanCommandExtension,
"lint": LintCommand,
"test": TestCommandExtension,
"test_publish": TestPublishCommand,
"publish": PublishCommand,
"publish_docs": PublishDocsCommand,
},
install_requires=["jsonschema", "mypy_extensions"],
extras_require={
"dev": [
"bandit",
"black",
"coverage",
"coveralls",
"mypy",
"mypy_extensions",
"pycodestyle",
"pydocstyle",
"pylint",
"pytest",
"sphinx",
"tox",
"twine",
]
},
python_requires=">=3.6, <4",
package_data={"zero_ex.json_schemas": ["py.typed", "schemas/*"]},
package_dir={"": "src"},
license="Apache 2.0",
keywords=(
"ethereum cryptocurrency 0x decentralized blockchain dex exchange"
),
namespace_packages=["zero_ex"],
packages=find_packages("src"),
classifiers=[
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Developers",
"Intended Audience :: Financial and Insurance Industry",
"License :: OSI Approved :: Apache Software License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Office/Business :: Financial",
"Topic :: Other/Nonlisted Topic",
"Topic :: Security :: Cryptography",
"Topic :: Software Development :: Libraries",
"Topic :: Utilities",
],
zip_safe=False, # required per mypy
command_options={
"build_sphinx": {
"source_dir": ("setup.py", "src"),
"build_dir": ("setup.py", "build/docs"),
}
},
)

View File

@ -0,0 +1,54 @@
"""Configuration file for the Sphinx documentation builder."""
# Reference: http://www.sphinx-doc.org/en/master/config
from typing import List
import pkg_resources
# pylint: disable=invalid-name
# because these variables are not named in upper case, as globals should be.
project = "0x-json-schemas"
# pylint: disable=redefined-builtin
copyright = "2018, ZeroEx, Intl."
author = "F. Eugene Aumson"
version = pkg_resources.get_distribution("0x-json-schemas").version
release = "" # The full version, including alpha/beta/rc tags
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
]
templates_path = ["doc_templates"]
source_suffix = ".rst"
# eg: source_suffix = [".rst", ".md"]
master_doc = "index" # The master toctree document.
language = None
exclude_patterns: List[str] = []
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None
html_theme = "alabaster"
html_static_path = ["doc_static"]
# 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".
# Output file base name for HTML help builder.
htmlhelp_basename = "order_utilspydoc"
# -- Extension configuration:
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {"https://docs.python.org/": None}

View File

@ -0,0 +1,18 @@
.. source for the sphinx-generated build/docs/web/index.html
Python zero_ex.order_utils
==========================
.. toctree::
:maxdepth: 2
:caption: Contents:
.. automodule:: zero_ex.json_schemas
:members:
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

View File

@ -0,0 +1,2 @@
"""0x Python API."""
__import__("pkg_resources").declare_namespace(__name__)

View File

@ -0,0 +1,7 @@
from distutils.core import Command
class clean(Command):
def initialize_options(self: clean) -> None: ...
def finalize_options(self: clean) -> None: ...
def run(self: clean) -> None: ...
...

View File

@ -0,0 +1 @@
def raises(exception: Exception) -> ExceptionInfo: ...

View File

@ -0,0 +1,8 @@
from distutils.dist import Distribution
from typing import Any, List
def setup(**attrs: Any) -> Distribution: ...
class Command: ...
def find_packages(where: str) -> List[str]: ...

View File

@ -0,0 +1,3 @@
from setuptools import Command
class test(Command): ...

View File

@ -0,0 +1 @@
"""Tests of zero_ex.json_schemas."""

View File

@ -0,0 +1,25 @@
"""Exercise doctests for all of our modules."""
from doctest import testmod
import pkgutil
import importlib
import zero_ex.json_schemas
def test_all_doctests():
"""Gather zero_ex.json_schemas.* modules and doctest them."""
# json_schemas module
module = "zero_ex.json_schemas"
print(module)
failure_count, _ = testmod(importlib.import_module(module))
assert failure_count == 0
# any json_schemas.* sub-modules
for (_, modname, _) in pkgutil.walk_packages(
path=zero_ex.json_schemas.__path__, prefix="zero_ex.json_schemas"
):
module = importlib.import_module(modname)
print(module)
(failure_count, _) = testmod(module)
assert failure_count == 0

View File

@ -1,10 +1,28 @@
"""Tests of zero_ex.json_schemas"""
from zero_ex.order_utils import make_empty_order
from zero_ex.json_schemas import _LOCAL_RESOLVER, assert_valid
NULL_ADDRESS = "0x0000000000000000000000000000000000000000"
EMPTY_ORDER = {
"makerAddress": NULL_ADDRESS,
"takerAddress": NULL_ADDRESS,
"senderAddress": NULL_ADDRESS,
"feeRecipientAddress": NULL_ADDRESS,
"makerAssetData": NULL_ADDRESS,
"takerAssetData": NULL_ADDRESS,
"salt": "0",
"makerFee": "0",
"takerFee": "0",
"makerAssetAmount": "0",
"takerAssetAmount": "0",
"expirationTimeSeconds": "0",
"exchangeAddress": NULL_ADDRESS,
}
def test_assert_valid_caches_resources():
"""Test that the JSON ref resolver in `assert_valid()` caches resources
@ -15,7 +33,7 @@ def test_assert_valid_caches_resources():
"""
_LOCAL_RESOLVER._remote_cache.cache_clear() # pylint: disable=W0212
assert_valid(make_empty_order(), "/orderSchema")
assert_valid(EMPTY_ORDER, "/orderSchema")
cache_info = (
_LOCAL_RESOLVER._remote_cache.cache_info() # pylint: disable=W0212
)

View File

@ -0,0 +1,25 @@
# tox (https://tox.readthedocs.io/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.
[tox]
envlist = py37
[testenv]
commands =
pip install -e .[dev]
python setup.py test
[testenv:run_tests_against_test_deployment]
commands =
# install dependencies from real PyPI
pip install jsonschema mypy_extensions pytest
# install package-under-test from test PyPI
pip install --index-url https://test.pypi.org/legacy/ 0x-json-schemas
pytest test
[testenv:run_tests_against_deployment]
commands =
pip install 0x-json-schemas
pytest test

View File

@ -171,9 +171,9 @@ setup(
"ganache": GanacheCommand,
},
install_requires=[
"0x-json-schemas",
"eth-abi",
"eth_utils",
"jsonschema",
"mypy_extensions",
"web3",
],
@ -198,7 +198,6 @@ setup(
package_data={
"zero_ex.order_utils": ["py.typed"],
"zero_ex.contract_artifacts": ["artifacts/*"],
"zero_ex.json_schemas": ["schemas/*"],
},
package_dir={"": "src"},
license="Apache 2.0",

View File

@ -22,9 +22,6 @@ See source for class properties. Sphinx does not easily generate class property
.. autoclass:: zero_ex.order_utils.asset_data_utils.ERC721AssetData
.. automodule:: zero_ex.json_schemas
:members:
Indices and tables
==================

View File

@ -0,0 +1,26 @@
from typing import Dict, Optional, Union
from web3.utils import datatypes
class Web3:
class HTTPProvider: ...
def __init__(self, provider: HTTPProvider) -> None: ...
@staticmethod
def sha3(
primitive: Optional[Union[bytes, int, None]] = None,
text: Optional[str] = None,
hexstr: Optional[str] = None
) -> bytes: ...
class net:
version: str
...
class eth:
@staticmethod
def contract(address: str, abi: Dict) -> datatypes.Contract: ...
...
...