Skip to content

Compiling a contract with import_remappings fails #44

@widelec-lab

Description

@widelec-lab
  • py-solc Version: 2.1.0
  • solc Version: 0.4.17
  • Python Version: 3.5.2
  • OS: Ubuntu 16.04, 4.4.0-104-generic

What was wrong?

I tried to compile a contract, say like this one:

pragma solidity 0.4.17;

contract Blah {
    uint public a;

    function Blah(uint _a) public {
        a = _a;
    }

    function getA() public view returns(uint) {
        return a;
    }
}

The python compilation code is as follows:

class Chain:
    ...
    @classmethod
    def compileContract(cls, filename):
	with open(filename,'r') as f:
            contract_source_code = f.read()
        compiled_sol = compile_source(contract_source_code, import_remappings=['='])                                                    
        return compiled_sol ['<stdin>:Blah']
    ...

Executing this function returns an error:

Traceback (most recent call last):
  File "compile.py", line 71, in <module>
    compiled = Chain.compileContract(sys.argv[1])
  File "compile.py", line 24, in compileContract
    compiled_sol = compile_source(contract_source_code, import_remappings=["="])
  File "/usr/local/lib/python3.5/dist-packages/solc/main.py", line 106, in compile_source
    stdoutdata, stderrdata, command, proc = solc_wrapper(**compiler_kwargs)
  File "/usr/local/lib/python3.5/dist-packages/solc/utils/string.py", line 85, in inner
    return force_obj_to_text(fn(*args, **kwargs))
  File "/usr/local/lib/python3.5/dist-packages/solc/wrapper.py", line 165, in solc_wrapper
    stderr_data=stderrdata,
solc.exceptions.SolcError: An error occurred during execution
> command: `solc --combined-json abi,asm,ast,bin,bin-runtime,clone-bin,devdoc,interface,opcodes,userdoc =`
> return code: `1`
> stderr:

> stdout:

Notes:

  • It fails whatever value I assign to import_remapings.
  • Executing with import_remappings removed works fine (it's not needed in this example, but I have another case where I'm importing other contracts and I need to use it).
  • Executing solc --combined-json abi,asm,ast,bin,bin-runtime,clone-bin,devdoc,interface,opcodes,userdoc = blah.sol directly from the command line works fine too (no errors, no warnings).
  • I tried also running with solc 0.4.19 in docker but problem persisted.
  • All files I have in one directory and all commands were executed inside this directory.

Cute Animal Picture

tumblr_mbyr4z1nm41rzey51o1_500

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions