* abi-gen-wrappers: fix half-baked folder rename
* .circleci: give cache more descriptive name
* abi-gen: rename type field. tsName->langLocalName
* contract-artifacts: add devdoc to ERC20Token.json
Artifact changes crafted manually: re-generated artifacts from within
@0x/contracts-erc20, and then copied them into @0x/contract-artifacts,
but only committed the changes that added devdoc.
Modified @0x/contracts-erc20/compiler.json to include devdoc in the
hopes that next time contract-artifacts are re-generated en masse, the
devdoc output will just come along for the ride.
Compiling ERC20 TypeScript wrappers after adding devdoc to the artifacts
revealed some inconsistencies in the types. ethereum-types'
DevdocOutput REQUIRED many fields which are not always present,
depending the devdoc contents itself. Relaxing the requirement had some
ramifications.
* abi-gen: Python!
Lots more to come, but so far generating typed methods with some
parameter validation and with reasonable docstrings; enough to make
ERC20 work.
* existing erc20 python wrapper: re-order methods
In order to minimize the diff in the upcoming commit of the
auto-generated version.
* existing erc20 python wrapper: rename method
Rename method _erc20 to _get_contract_instance.
* existing erc20 python wrapper: rename vars
Rename method parameters to match names used in contract methods.
* existing erc20 python wrapper: correction
Contract method `allowance` previously was returning a transaction hash,
but it's a const method, so changed it to return the int that the
underlying method returns.
* contract_wrappers.py: pull in generated code
Custom setup.py command to pull in code previously generated into
../../packages/abi-gen-wrappers/src/generated-wrappers/py.
Changes to existing wrapper code reflect differences between the old,
manually-written wrapper and the new, auto-generated wrapper.
Reconfigured Circle CI to give Python build access to the output of the
TypeScript build, in order to import the generated wrappers from there.
* abi-gen: sanitize docstrings for pycodestyle lint
* abi-gen-templates.py: expose ABI from template
Use ABI given by template, not gotten by name from
zero_ex.contract_artifacts.
Also, expose ABI as a static method.
* py wrappers: contract addr to ctor, not methods
In all Python wrappers (old, manual ones; and new, generated ones), have
client pass the contract address to the wrapper's constructor, rather
than to the individual method calls.
* py wrappers: remove unused param `account_address`
* py wrappers: document use of `private_key`
* Rename file erc20_wrapper.py to erc20_token.py
To match the name of the underlying contract.
* Update CHANGELOG.json's
* git rm erc20_token.py
No need to keep it checked in. Doing so would require manual overhead
of keeping the generated copy in sync with the generation code, which
may get overlooked and cause confusion for others. Authoritative source
will be the published package on PyPI.
* abi-gen-templates: tweak CHANGELOG wording
Co-Authored-By: Fabio B <kandinsky454@protonmail.ch>
* Include transaction parameters in const calls too
* Doc contract_address param to gen'd wrapper ctor
* make myself a CODEOWNER of abi-gen*
* rename ids: langLocalName -> languageSpecificName
* Move Python generation to its own packages/ folder
* Stop duplicating contract artifacts in Python pkg!
Thanks to the way we're now using the `./setup.py pre_install`
convention, there's no longer a need to check the artifacts in to the
Python package.
* move py templates BACK to abi-gen-templates
I got a little overzealous in the previous commit that moved ALL the
python stuff into the new packages/python-contract-wrappers folder.
* Update known-good test output: prettify
* add getABIEncodedTransationData to gen'd code
It was added into the template in the following commit, but the
corresponding checked-in generated code was not updated accordingly.
f51c4f9617
* Fix missed instance of languageSpecificName change
* abi-gen: refine pipeline for testing gen'd code
- generate wrappers for test fixture contracts (dummy, etc) not in `yarn
build` but in `yarn test`
- rename folder test/generated-test/generated-wrappers to
test/generated-test/known-good, and stop writing test output to there,
instead writing it to a new test/generated-test/output folder.
- sol-compile test fixture contracts in every test run
- run unit tests separately from tests of generated and built TypeScript
wrappers. The existing `yarn run_mocha` will run unit tests, and
there's a new `yarn run_contract_wrapper_tests`.
* abi-gen: test Python gen [known test failures]
Also generate TypeScript wrapper test code into a TypeScript folder
(alongside the newly created Python folder).
Known-good code manually corrected (from generated code) to reflect
known problems that still need to be addressed. Namely:
- base contract and tx params should be imported from canonical
package, not relative path. relative path is working for wrapping
OUR contracts, but would not be usable in a more general
context.
- return type missing for some generated methods.
These outstanding problems are currently causing this test to fail.
* fix failing abi-gen test: missing return types
* fix failing abi-gen test: qualify imports
* in py wrapper, simplify base class initialization
per
https://github.com/0xProject/0x-monorepo/pull/1878#discussion_r299248641
* move 3rd party typings to typescript-typings
* make package python-contract-wrappers private
* make Xianny CODEOWNER of base-contract & templates
* abi-gen: clarify --help for --backend
* remove superfluous CHANGELOG entry
231 lines
7.3 KiB
Python
Executable File
231 lines
7.3 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
"""setuptools module for contract_artifacts package."""
|
|
|
|
import subprocess # nosec
|
|
from shutil import copytree, rmtree
|
|
from os import environ, path
|
|
from sys import argv
|
|
|
|
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 PreInstallCommand(distutils.command.build_py.build_py):
|
|
"""Custom setuptools command class for pulling in artifacts."""
|
|
|
|
description = "Pull in the artifacts that live in the TypeScript package."
|
|
|
|
def run(self):
|
|
"""Copy files from TS build area to local src, & `black` them."""
|
|
pkgdir = path.dirname(path.realpath(argv[0]))
|
|
rmtree(
|
|
path.join(
|
|
pkgdir, "src", "zero_ex", "contract_artifacts", "artifacts"
|
|
),
|
|
ignore_errors=True,
|
|
)
|
|
copytree(
|
|
path.join(
|
|
pkgdir,
|
|
"..",
|
|
"..",
|
|
"packages",
|
|
"contract-artifacts",
|
|
"artifacts",
|
|
),
|
|
path.join(
|
|
pkgdir, "src", "zero_ex", "contract_artifacts", "artifacts"
|
|
),
|
|
)
|
|
|
|
|
|
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 setup.py".split(),
|
|
# style guide checker (formerly pep8):
|
|
"pycodestyle --show-source --show-pep8 src setup.py".split(),
|
|
# docstring style checker:
|
|
"pydocstyle src setup.py".split(),
|
|
# static type checker:
|
|
"mypy src setup.py".split(),
|
|
# security issue checker:
|
|
"bandit -r src ./setup.py".split(),
|
|
# HACK: ensure contract artifacts match the authoritative copies:
|
|
# this is a hack. ideally we would symlink to the authoritative
|
|
# copies, but a problem with setuptools is preventing it from
|
|
# following symlinks when gathering package_data. see
|
|
# https://github.com/pypa/setuptools/issues/415.
|
|
(
|
|
"diff src/zero_ex/contract_artifacts/artifacts"
|
|
+ " ../../packages/contract-artifacts/artifacts"
|
|
).split(),
|
|
# general linter:
|
|
"pylint src 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/0x_contract_artifacts.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-contract-artifacts-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
|
|
|
|
|
|
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()
|
|
|
|
|
|
setup(
|
|
name="0x-contract-artifacts",
|
|
version="2.0.1",
|
|
description="0x smart contract compilation artifacts",
|
|
long_description=README_MD,
|
|
long_description_content_type="text/markdown",
|
|
url=(
|
|
"https://github.com/0xproject/0x-monorepo/tree/development"
|
|
+ "/python-packages/contract_artifacts"
|
|
),
|
|
author="F. Eugene Aumson",
|
|
author_email="feuGeneA@users.noreply.github.com",
|
|
cmdclass={
|
|
"pre_install": PreInstallCommand,
|
|
"clean": CleanCommandExtension,
|
|
"lint": LintCommand,
|
|
"test": TestCommandExtension,
|
|
"test_publish": TestPublishCommand,
|
|
"publish": PublishCommand,
|
|
"publish_docs": PublishDocsCommand,
|
|
},
|
|
install_requires=["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.contract_artifacts": ["py.typed", "artifacts/*"]},
|
|
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 :: 5 - Production/Stable",
|
|
"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"),
|
|
}
|
|
},
|
|
)
|