Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ docs/_build

# Known Contracts
**/known_contracts.json

# py.test cache
.cache
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
[![PyPi downloads](https://pypip.in/d/py-solc/badge.png)](https://pypi.python.org/pypi/py-solc)


Python wrapper around the `solc` solidity compiler.
Python wrapper around the `solc` Solidity compiler.


# Dependency

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

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


# Quickstart

Expand Down
4 changes: 4 additions & 0 deletions solc/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ class SolcError(Exception):

class CompileError(Exception):
pass


class ContractsNotFound(Exception):
"""No contracts was found in the target folder."""
11 changes: 10 additions & 1 deletion solc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .exceptions import (
SolcError,
ContractsNotFound,
)

from .utils.formatting import (
Expand Down Expand Up @@ -39,7 +40,15 @@ def get_solc_version():


def _parse_compiler_output(stdoutdata):
contracts = json.loads(stdoutdata)['contracts']

output = json.loads(stdoutdata)

if "contracts" not in output:
# {'sources': {}, 'version': 'xxx'}
# solc did not pick up any contracts
raise ContractsNotFound(output)

contracts = output['contracts']

for _, data in contracts.items():
data['abi'] = json.loads(data['abi'])
Expand Down
21 changes: 21 additions & 0 deletions tests/compilation/test_compile_empty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import tempfile

import pytest

from solc import (
compile_files,
)

from solc.exceptions import ContractsNotFound


def test_compile_empty_folder():
"""Execute compile on a folder without contracts."""

tmpdirname = tempfile.mkdtemp()
try:
with pytest.raises(ContractsNotFound):
compile_files(tmpdirname)
finally:
os.rmdir(tmpdirname)