diff --git a/.gitignore b/.gitignore index 7bbc71c..46983e7 100644 --- a/.gitignore +++ b/.gitignore @@ -97,5 +97,8 @@ ENV/ # mkdocs documentation /site +# PyCharm +/.idea/ + # mypy .mypy_cache/ diff --git a/README.md b/README.md index e63ae9b..b9b948a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/flattener/core.py b/flattener/core.py index 855c4a7..a514550 100755 --- a/flattener/core.py +++ b/flattener/core.py @@ -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() \ No newline at end of file diff --git a/setup.py b/setup.py index 9135129..9e83957 100644 --- a/setup.py +++ b/setup.py @@ -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(