From cbd6993f97e6d138aeff5688ffae34d5171d5e19 Mon Sep 17 00:00:00 2001 From: Eenae Date: Thu, 14 Dec 2017 18:16:43 +0300 Subject: [PATCH 1/5] accepting multiple paths via solc-paths --- README.md | 3 ++- flattener/core.py | 9 +++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e63ae9b..ed2ee5a 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ 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. ``` # Examples diff --git a/flattener/core.py b/flattener/core.py index 855c4a7..843f64f 100755 --- a/flattener/core.py +++ b/flattener/core.py @@ -85,14 +85,11 @@ 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.") 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_args = ["solc"] + args.solc_paths + ["--ast", args.target_solidity_file] solc_proc = subprocess.run(solc_args, stdout=subprocess.PIPE, universal_newlines=True) solc_proc.check_returncode() flatten_contract(solc_proc.stdout, args.output) From cdc9bf400f7aed8e67e0a682d1b18604d3d1a9e0 Mon Sep 17 00:00:00 2001 From: Eenae Date: Thu, 14 Dec 2017 20:40:44 +0300 Subject: [PATCH 2/5] added support for --allow-paths solc option --- .gitignore | 3 +++ flattener/core.py | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) 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/flattener/core.py b/flattener/core.py index 843f64f..8da1738 100755 --- a/flattener/core.py +++ b/flattener/core.py @@ -87,9 +87,14 @@ def main(): help="Specifies the output destination filename. Outputs to stdout by default.") 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() - solc_args = ["solc"] + args.solc_paths + ["--ast", args.target_solidity_file] + 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, universal_newlines=True) solc_proc.check_returncode() flatten_contract(solc_proc.stdout, args.output) From 3e73944cccbaeb64710c35c70e0494526cc08872 Mon Sep 17 00:00:00 2001 From: Eenae Date: Thu, 14 Dec 2017 20:41:53 +0300 Subject: [PATCH 3/5] readme updated --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index ed2ee5a..b9b948a 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,9 @@ optional arguments: Specifies the path replacements to pass onto solidity. 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 From 0ecd99f3049af7cd30f4ba1b3d5d6010bb304f04 Mon Sep 17 00:00:00 2001 From: Eenae Date: Tue, 8 May 2018 09:38:27 +0300 Subject: [PATCH 4/5] setup:py: Python version check --- setup.py | 4 ++++ 1 file changed, 4 insertions(+) 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( From 2bb43f35a6e16593b5b21c2cf61eacc3db3769c6 Mon Sep 17 00:00:00 2001 From: Eenae Date: Wed, 9 May 2018 19:40:36 +0300 Subject: [PATCH 5/5] fix for invalid utf-8 strings in --ast output --- flattener/core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flattener/core.py b/flattener/core.py index 8da1738..a514550 100755 --- a/flattener/core.py +++ b/flattener/core.py @@ -95,9 +95,10 @@ def main(): 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, universal_newlines=True) + 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