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

Python contract demo, with lots of refactoring #1485

Merged
merged 18 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
87 changes: 34 additions & 53 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,46 +202,30 @@ jobs:
key: deps9-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
- run:
command: |
cd python-packages/json_schemas
cd python-packages
python -m ensurepip
python -m pip install .[dev]
# HACK! installing the package should do the following
# copy for us, but it's not working in CircleCI for some
# reason. Zendesk support ticket raised (#43979) with
# CircleCI.
mkdir /usr/local/lib/python3.7/site-packages/zero_ex/json_schemas/schemas
cp -R src/zero_ex/json_schemas/schemas/* /usr/local/lib/python3.7/site-packages/zero_ex/json_schemas/schemas
- run:
command: |
cd python-packages/order_utils
python -m ensurepip
python -m pip install .[dev]
- run:
command: |
cd python-packages/sra_client
python -m ensurepip
python -m pip install .[dev]
./install
- save_cache:
key: deps9-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
paths:
- '/usr/local/bin'
- '/usr/local/lib/python3.7/site-packages'
- '.eggs'
- '.mypy_cache'
- '.pytest_cache'
- '.tox'
- run:
command: |
cd python-packages/json_schemas
coverage run setup.py test
- run:
command: |
cd python-packages/order_utils
coverage run setup.py test
- run:
command: |
cd python-packages/sra_client
coverage run setup.py test
cd python-packages
./cmd_pkgs_in_dep_order.py coverage run setup.py test
- save_cache:
key: coverage-python-contract-addresses-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ~/repo/python-packages/contract_addresses/.coverage
- save_cache:
key: coverage-python-contract-artifacts-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ~/repo/python-packages/contract_artifacts/.coverage
- save_cache:
key: coverage-python-contract-demo-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ~/repo/python-packages/contract_demo/.coverage
- save_cache:
key: coverage-python-json-schemas-{{ .Environment.CIRCLE_SHA1 }}
paths:
Expand Down Expand Up @@ -294,27 +278,10 @@ jobs:
key: deps9-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
- run:
command: |
cd python-packages/json_schemas
python -m ensurepip
python -m pip install .[dev]
- run:
command: |
cd python-packages/order_utils
python -m ensurepip
python -m pip install .[dev]
- save_cache:
key: deps9-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
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
python setup.py lint
cd python-packages
./install
./lint
static-tests:
working_directory: ~/repo
docker:
Expand Down Expand Up @@ -386,6 +353,18 @@ jobs:
- restore_cache:
keys:
- coverage-python-json-schemas-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-python-contract-addresses-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-python-contract-artifacts-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-python-contract-demo-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-python-sra-client-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-python-order-utils-{{ .Environment.CIRCLE_SHA1 }}
Expand Down Expand Up @@ -423,7 +402,9 @@ workflows:
requires:
- test-rest
- test-python
- static-tests-python:
requires:
- test-python
- test-python
- static-tests-python
# skip python tox run for now, as we don't yet have multiple test environments to support.
#- test-rest-python
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lib
/contracts/extensions/generated-artifacts
/packages/abi-gen-wrappers/src/generated-wrappers
/packages/contract-artifacts/artifacts
/python-packages/order_utils/src/zero_ex/contract_artifacts/artifacts
/python-packages/contract_artifacts/src/zero_ex/contract_artifacts/artifacts
/packages/json-schemas/schemas
/python-packages/json_schemas/src/zero_ex/json_schemas/schemas
/packages/metacoin/src/contract_wrappers
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ Visit our [developer portal](https://0xproject.com/docs/order-utils) for a compr

### Python Packages

| 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 |
| Package | Version | Description |
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| [`0x-contract-addresses`](/python-packages/contract_addresses) | [![PyPI](https://img.shields.io/pypi/v/0x-contract-addresses.svg)](https://pypi.org/project/0x-contract-addresses/) | A tiny utility library for getting known deployed contract addresses for a particular network |
| [`0x-contract-artifacts`](/python-packages/contract_artifacts) | [![PyPI](https://img.shields.io/pypi/v/0x-contract-artifacts.svg)](https://pypi.org/project/0x-contract-artifacts/) | 0x smart contract compilation artifacts |
| [`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

Expand Down
11 changes: 9 additions & 2 deletions packages/json-schemas/schemas/whole_number_schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"id": "/wholeNumberSchema",
"type": "string",
"pattern": "^\\d+$"
"anyOf": [
{
"type": "string",
"pattern": "^\\d+$"
},
{
"type": "integer"
}
]
}
25 changes: 25 additions & 0 deletions python-packages/cmd_pkgs_in_dep_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python

"""Run a command in every package, in order of increasing dependency."""

import os
import subprocess
import sys


PACKAGE_DEPENDENCY_LIST = [
# Order matters! Packages must be handled in dependency order (most
# independent first) in order for them to resolve properly.
"contract_addresses",
"contract_artifacts",
"json_schemas",
"sra_client",
"order_utils",
"contract_demo"
]

for package in PACKAGE_DEPENDENCY_LIST:
print(f"Running command `{sys.argv[1:]}` in package {package}")
os.chdir(package)
subprocess.check_call(sys.argv[1:])
os.chdir("..")
13 changes: 13 additions & 0 deletions python-packages/contract_addresses/.discharge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"domain": "0x-contract-addresses-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
}
45 changes: 45 additions & 0 deletions python-packages/contract_addresses/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## 0x-contract-addresses

Addresses at which the 0x smart contracts have been deployed.

Read the [documentation](http://0x-contract-addresses-py.s3-website-us-east-1.amazonaws.com/)

## Installing

```bash
pip install 0x-contract-addresses
```

## 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.
Loading