Skip to content

Commit adba388

Browse files
committed
Fail gracefully if solc doesn't find any contracts. Information how to install solc. Watch out for py.test / tox caches.
1 parent 92bdd73 commit adba388

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@ docs/_build
4949

5050
# Known Contracts
5151
**/known_contracts.json
52+
53+
# py.test cache
54+
.cache

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
[![PyPi downloads](https://pypip.in/d/py-solc/badge.png)](https://pypi.python.org/pypi/py-solc)
66

77

8-
Python wrapper around the `solc` solidity compiler.
8+
Python wrapper around the `solc` Solidity compiler.
99

1010

1111
# Dependency
1212

1313
This library requires the `solc` executable to be present.
1414

15+
solc 0.3.5 or newer is required. [solc installation instructions](http://solidity.readthedocs.io/en/latest/installing-solidity.html)
16+
1517

1618
# Quickstart
1719

solc/exceptions.py

+4
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ class SolcError(Exception):
44

55
class CompileError(Exception):
66
pass
7+
8+
9+
class ContractsNotFound(Exception):
10+
"""No contracts was found in the target folder."""

solc/main.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from .exceptions import (
88
SolcError,
9+
ContractsNotFound,
910
)
1011

1112
from .utils.formatting import (
@@ -39,7 +40,15 @@ def get_solc_version():
3940

4041

4142
def _parse_compiler_output(stdoutdata):
42-
contracts = json.loads(stdoutdata)['contracts']
43+
44+
output = json.loads(stdoutdata)
45+
46+
if not "contracts" in output:
47+
# {'sources': {}, 'version': 'xxx'}
48+
# solc did not pick up any contracts
49+
raise ContractsNotFound(output)
50+
51+
contracts = output['contracts']
4352

4453
for _, data in contracts.items():
4554
data['abi'] = json.loads(data['abi'])
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import tempfile
2+
3+
import pytest
4+
5+
from solc import (
6+
compile_files,
7+
)
8+
9+
from solc.exceptions import ContractsNotFound
10+
11+
12+
def test_compile_empty_folder():
13+
"""Execute compile on a folder without contracts."""
14+
15+
with tempfile.TemporaryDirectory() as tmpdirname:
16+
with pytest.raises(ContractsNotFound):
17+
compile_files(tmpdirname)

0 commit comments

Comments
 (0)