Skip to content

Commit

Permalink
Merge pull request #79 from iamdefinitelyahuman/v0.9.0
Browse files Browse the repository at this point in the history
V0.9.0
  • Loading branch information
iamdefinitelyahuman authored Jun 10, 2020
2 parents d501abe + 5d75afa commit 58f7bd1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 28 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.9.0
-----

- Add `base_path` as a possible wrapper kwarg
- Bugfix: handle `stderr` output when calling `which`
- Bugfix: expect return code 1 when using `--help`

0.8.2
-----

Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.8.2
current_version = 0.9.0

[bumpversion:file:setup.py]

Expand All @@ -16,4 +16,3 @@ use_parentheses = True

[tool:pytest]
addopts = -v --cov=solcx --cov-branch --cov-report xml

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="py-solc-x",
version="0.8.2", # don't change this manually, use bumpversion instead
version="0.9.0", # don't change this manually, use bumpversion instead
description="Python wrapper around the solc binary with 0.5.x and 0.6.x support",
long_description_markdown_filename="README.md",
author="Ben Hauser (forked from py-solc by Piper Merriam)",
Expand Down
18 changes: 16 additions & 2 deletions solcx/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,25 @@ def solc_wrapper(
devdoc=None,
formal=None,
allow_paths=None,
base_path=None,
standard_json=None,
success_return_code=0,
success_return_code=None,
evm_version=None,
):
if solc_binary is None:
solc_binary = get_executable()

command = [solc_binary]

solc_minor = Version(solc_binary.rsplit("-v")[-1].split("\\")[0]).minor
solc_version = Version(solc_binary.rsplit("-v")[-1].split("\\")[0])
solc_minor = solc_version.minor

if help:
command.append("--help")
if success_return_code is None:
success_return_code = 1
elif success_return_code is None:
success_return_code = 0

if version:
command.append("--version")
Expand Down Expand Up @@ -133,6 +139,14 @@ def solc_wrapper(
if evm_version:
command.extend(("--evm-version", evm_version))

# unsupported by <0.6.9
if base_path:
if solc_version <= Version("0.6.8"):
raise AttributeError(
"solc {} does not support the --base-path flag".format(solc_version)
)
command.extend(("--base-path", base_path))

# unsupported by >=0.6.0
if ast:
if solc_minor >= 6:
Expand Down
61 changes: 38 additions & 23 deletions tests/test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess

import pytest
from semantic_version import Version

import solcx

Expand Down Expand Up @@ -39,8 +40,10 @@ def test_help(popen):
solcx.wrapper.solc_wrapper(help=True, success_return_code=1)


def test_boolean_kwargs(popen, foo_source):
kwargs = [
@pytest.mark.parametrize(
"kwarg",
[
"help",
"version",
"optimize",
"gas",
Expand All @@ -55,32 +58,44 @@ def test_boolean_kwargs(popen, foo_source):
"userdoc",
"devdoc",
"standard_json",
]
for value in kwargs:
popen.expect(value)
solcx.wrapper.solc_wrapper(stdin=foo_source, **{value: True})
],
)
def test_boolean_kwargs(popen, foo_source, kwarg):
popen.expect(kwarg)
solcx.wrapper.solc_wrapper(stdin=foo_source, **{kwarg: True})


def test_removed_kwargs(popen, foo_source):
@pytest.mark.parametrize("kwarg,min_solc_minor", [("ast", 6), ("clone_bin", 5), ("formal", 5)])
def test_removed_kwargs(popen, foo_source, kwarg, min_solc_minor):
solc_minor_version = solcx.get_solc_version().minor
kwargs = [("ast", 6), ("clone_bin", 5), ("formal", 5)]
for value, minor in kwargs:
popen.expect(value)
if solc_minor_version >= minor:
with pytest.raises(AttributeError):
solcx.wrapper.solc_wrapper(stdin=foo_source, **{value: True})
else:
solcx.wrapper.solc_wrapper(stdin=foo_source, **{value: True})


def test_value_kwargs(popen, foo_source):
kwargs = [

popen.expect(kwarg)
if solc_minor_version >= min_solc_minor:
with pytest.raises(AttributeError):
solcx.wrapper.solc_wrapper(stdin=foo_source, **{kwarg: True})
else:
solcx.wrapper.solc_wrapper(stdin=foo_source, **{kwarg: True})


@pytest.mark.parametrize(
"kwarg,value",
[
("optimize_runs", 200),
("libraries", "libraries:0x1234567890123456789012345678901234567890"),
("output_dir", "."),
("combined_json", "abi"),
("allow_paths", "."),
]
for value in kwargs:
popen.expect(value[0])
solcx.wrapper.solc_wrapper(stdin=foo_source, **{value[0]: value[1]})
],
)
def test_value_kwargs(popen, foo_source, kwarg, value):
popen.expect(kwarg)
solcx.wrapper.solc_wrapper(stdin=foo_source, **{kwarg: value})


@pytest.mark.parametrize("kwarg,min_version", [({"base_path": "."}, "0.6.9")])
def test_added_kwargs(popen, foo_source, kwarg, min_version):
if solcx.get_solc_version().truncate() >= Version(min_version):
solcx.wrapper.solc_wrapper(stdin=foo_source, **kwarg)
else:
with pytest.raises(AttributeError):
solcx.wrapper.solc_wrapper(stdin=foo_source, **kwarg)

0 comments on commit 58f7bd1

Please sign in to comment.