Skip to content

Commit c71505e

Browse files
miohtamapipermerriam
authored andcommitted
Added import remapping support.
1 parent 5d08282 commit c71505e

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,21 @@ pip install py-solc
6969
... "606060405260768060106000396000f3606060405260e060020a6000350463e7f09e058114601a575b005b60187f0c55699c00000000000000000000000000000000000000000000000000000000606090815273d3cda913deb6f67967b99d67acdfa1712c29360190630c55699c906064906000906004818660325a03f41560025750505056"
7070
```
7171

72-
7372
## Setting the path to the `solc` binary
7473

7574
You can use the environment variable `SOLC_BINARY` to set the path to your solc binary.
75+
76+
## Import path remappings
77+
78+
`solc` provides path aliasing allow you to have more reusable project configurations.
79+
80+
You can use this like:
81+
82+
```
83+
from solc import compile_source, compile_files, link_code
84+
85+
compile_files([source_file_path], remappings=["zeppeling=/my-zeppelin-checkout-folder"])
86+
```
87+
88+
[More information about solc import aliasing](http://solidity.readthedocs.io/en/develop/layout-of-source-files.html#paths)
89+

solc/wrapper.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def solc_wrapper(solc_binary=SOLC_BINARY,
2929
gas=None,
3030
assemble=None,
3131
link=None,
32+
remappings=None,
3233
source_files=None,
3334
import_remappings=None,
3435
ast=None,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
3+
from solc import (
4+
get_solc_version,
5+
compile_files,
6+
)
7+
8+
9+
def test_remappings(contracts_dir):
10+
IMPORT_SOURCE = "contract Bar {}"
11+
SOURCE = 'import "bar/moo.sol"; contract Foo is Bar { function Foo() {} function return13() returns (uint) { return 13; } }'
12+
13+
baz_path = os.path.abspath(os.path.join(contracts_dir, "baz"))
14+
os.makedirs(baz_path)
15+
16+
source_file_path = os.path.join(baz_path, 'Moo.sol')
17+
with open(source_file_path, 'w') as source_file:
18+
source_file.write(IMPORT_SOURCE)
19+
20+
source_file_path = os.path.join(contracts_dir, 'Foo.sol')
21+
with open(source_file_path, 'w') as source_file:
22+
source_file.write(SOURCE)
23+
24+
output = compile_files([source_file_path], remappings=["bar={}".format(baz_path)])
25+
26+
assert output
27+
assert 'Foo' in output

0 commit comments

Comments
 (0)