Skip to content

Commit 95e996c

Browse files
authored
Merge pull request #3 from miohtama/master
Fail gracefully if solc doesn't find any contracts. Information how t…
2 parents 92bdd73 + cae8d29 commit 95e996c

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 10 additions & 1 deletion
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 "contracts" not 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'])
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
import tempfile
3+
4+
import pytest
5+
6+
from solc import (
7+
compile_files,
8+
)
9+
10+
from solc.exceptions import ContractsNotFound
11+
12+
13+
def test_compile_empty_folder():
14+
"""Execute compile on a folder without contracts."""
15+
16+
tmpdirname = tempfile.mkdtemp()
17+
try:
18+
with pytest.raises(ContractsNotFound):
19+
compile_files(tmpdirname)
20+
finally:
21+
os.rmdir(tmpdirname)

0 commit comments

Comments
 (0)