Skip to content
Open
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 @@ -97,5 +97,8 @@ ENV/
# mkdocs documentation
/site

# PyCharm
/.idea/

# mypy
.mypy_cache/
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ optional arguments:
stdout by default.
--solc-paths SOLC_PATHS
Specifies the path replacements to pass onto solidity.
See solc --help for more information.
Can be specified multiple times. See solc --help for
more information.
--solc-allow-paths SOLC_ALLOW_PATHS
Specifies allowed paths for solidity imports. See solc
--help for more information.
```

# Examples
Expand Down
19 changes: 11 additions & 8 deletions flattener/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,20 @@ def main():
help="Specifies the target Solidity source file to flatten.")
parser.add_argument("--output", type=ap.FileType('w+'), default=sys.stdout, metavar="FILENAME",
help="Specifies the output destination filename. Outputs to stdout by default.")
parser.add_argument("--solc-paths", default="",
help="Specifies the path replacements to pass onto solidity. See solc --help for more information.")
parser.add_argument("--solc-paths", type=str, default=[], action='append',
help="Specifies the path replacements to pass onto solidity. Can be specified multiple times. See solc --help for more information.")
parser.add_argument("--solc-allow-paths", default="",
help="Specifies allowed paths for solidity imports. See solc --help for more information.")
args = parser.parse_args()

if args.solc_paths:
solc_args = ["solc", args.solc_paths, "--ast", args.target_solidity_file]
else:
solc_args = ["solc", "--ast", args.target_solidity_file]
solc_proc = subprocess.run(solc_args, stdout=subprocess.PIPE, universal_newlines=True)
solc_args = ["solc"] + args.solc_paths
if args.solc_allow_paths:
solc_args.extend(['--allow-paths', args.solc_allow_paths])
solc_args.extend(["--ast", args.target_solidity_file])
solc_proc = subprocess.run(solc_args, stdout=subprocess.PIPE)
solc_proc.check_returncode()
flatten_contract(solc_proc.stdout, args.output)
# AST output could contain invalid utf-8 strings (e.g. when solc is trying to decode hex"...")
flatten_contract(solc_proc.stdout.decode('utf-8', 'ignore'), args.output)

if __name__ == '__main__':
main()
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!python3

import sys
if sys.version_info < (3, 5):
sys.exit('Sorry, Python < 3.5 is not supported')

from setuptools import setup, find_packages

setup(
Expand Down