From 57c138864cef53afac9439e90607f7c9ff09980f Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Wed, 23 Jan 2019 20:36:08 +0200 Subject: [PATCH 01/16] install rebuild, linux support --- solc/install.py | 639 ++++++++++++++++-------------------------------- 1 file changed, 205 insertions(+), 434 deletions(-) diff --git a/solc/install.py b/solc/install.py index 7401c56..098b0e6 100644 --- a/solc/install.py +++ b/solc/install.py @@ -11,515 +11,286 @@ import zipfile -V0_4_1 = 'v0.4.1' -V0_4_2 = 'v0.4.2' -V0_4_6 = 'v0.4.6' -V0_4_7 = 'v0.4.7' -V0_4_8 = 'v0.4.8' -V0_4_9 = 'v0.4.9' -V0_4_11 = 'v0.4.11' -V0_4_12 = 'v0.4.12' -V0_4_13 = 'v0.4.13' -V0_4_14 = 'v0.4.14' -V0_4_15 = 'v0.4.15' -V0_4_16 = 'v0.4.16' -V0_4_17 = 'v0.4.17' -V0_4_18 = 'v0.4.18' -V0_4_19 = 'v0.4.19' -V0_4_20 = 'v0.4.20' -V0_4_21 = 'v0.4.21' -V0_4_22 = 'v0.4.22' -V0_4_23 = 'v0.4.23' -V0_4_24 = 'v0.4.24' -V0_4_25 = 'v0.4.25' -V0_5_0 = 'v0.5.0' -V0_5_1 = 'v0.5.1' -V0_5_2 = 'v0.5.2' - -LINUX = 'linux' -OSX = 'darwin' -WINDOWS = 'win32' - +# V0_4_1 = 'v0.4.1' +# V0_4_2 = 'v0.4.2' +# V0_4_6 = 'v0.4.6' +# V0_4_7 = 'v0.4.7' +# V0_4_8 = 'v0.4.8' +# V0_4_9 = 'v0.4.9' +# V0_4_11 = 'v0.4.11' +# V0_4_12 = 'v0.4.12' +# V0_4_13 = 'v0.4.13' +# V0_4_14 = 'v0.4.14' +# V0_4_15 = 'v0.4.15' +# V0_4_16 = 'v0.4.16' +# V0_4_17 = 'v0.4.17' +# V0_4_18 = 'v0.4.18' +# V0_4_19 = 'v0.4.19' +# V0_4_20 = 'v0.4.20' +# V0_4_21 = 'v0.4.21' +# V0_4_22 = 'v0.4.22' +# V0_4_23 = 'v0.4.23' +# V0_4_24 = 'v0.4.24' +# V0_4_25 = 'v0.4.25' +# V0_5_0 = 'v0.5.0' +# V0_5_1 = 'v0.5.1' +# V0_5_2 = 'v0.5.2' # # System utilities. # -@contextlib.contextmanager -def chdir(path): - original_path = os.getcwd() - try: - os.chdir(path) - yield - finally: - os.chdir(original_path) - - -def get_platform(): - if sys.platform.startswith('linux'): - return LINUX - elif sys.platform == OSX: - return OSX - elif sys.platform == WINDOWS: - return WINDOWS - else: - raise KeyError("Unknown platform: {0}".format(sys.platform)) +# @contextlib.contextmanager +# def chdir(path): +# original_path = os.getcwd() +# try: +# os.chdir(path) +# yield +# finally: +# os.chdir(original_path) -def is_executable_available(program): - def is_exe(fpath): - return os.path.isfile(fpath) and os.access(fpath, os.X_OK) +# def is_executable_available(program): +# def is_exe(fpath): +# return os.path.isfile(fpath) and os.access(fpath, os.X_OK) - fpath = os.path.dirname(program) - if fpath: - if is_exe(program): - return True - else: - for path in os.environ["PATH"].split(os.pathsep): - path = path.strip('"') - exe_file = os.path.join(path, program) - if is_exe(exe_file): - return True +# fpath = os.path.dirname(program) +# if fpath: +# if is_exe(program): +# return True +# else: +# for path in os.environ["PATH"].split(os.pathsep): +# path = path.strip('"') +# exe_file = os.path.join(path, program) +# if is_exe(exe_file): +# return True - return False +# return False -def ensure_path_exists(dir_path): - """ - Make sure that a path exists - """ - if not os.path.exists(dir_path): - os.makedirs(dir_path) - return True - return False +# def ensure_path_exists(dir_path): +# """ +# Make sure that a path exists +# """ +# if not os.path.exists(dir_path): +# os.makedirs(dir_path) +# return True +# return False -def ensure_parent_dir_exists(path): - ensure_path_exists(os.path.dirname(path)) +# def ensure_parent_dir_exists(path): +# ensure_path_exists(os.path.dirname(path)) -def check_subprocess_call(command, message=None, stderr=subprocess.STDOUT, **proc_kwargs): - if message: - print(message) - print("Executing: {0}".format(" ".join(command))) +# def check_subprocess_call(command, message=None, stderr=subprocess.STDOUT, **proc_kwargs): +# if message: +# print(message) +# print("Executing: {0}".format(" ".join(command))) - return subprocess.check_call( - command, - stderr=subprocess.STDOUT, - **proc_kwargs - ) +# return subprocess.check_call( +# command, +# stderr=subprocess.STDOUT, +# **proc_kwargs +# ) -def check_subprocess_output(command, message=None, stderr=subprocess.STDOUT, **proc_kwargs): - if message: - print(message) - print("Executing: {0}".format(" ".join(command))) - return subprocess.check_output( - command, - stderr=subprocess.STDOUT, - **proc_kwargs - ) -def chmod_plus_x(executable_path): - current_st = os.stat(executable_path) - os.chmod(executable_path, current_st.st_mode | stat.S_IEXEC) -SOLIDITY_GIT_URI = "https://github.com/ethereum/solidity.git" +# SOLIDITY_GIT_URI = "https://github.com/ethereum/solidity.git" -def is_git_repository(path): - git_dir = os.path.join( - path, - '.git', - ) - return os.path.exists(git_dir) +# def is_git_repository(path): +# git_dir = os.path.join( +# path, +# '.git', +# ) +# return os.path.exists(git_dir) -# -# Installation filesystem path utilities -# -def get_base_install_path(identifier): - if 'SOLC_BASE_INSTALL_PATH' in os.environ: - return os.path.join( - os.environ['SOLC_BASE_INSTALL_PATH'], - 'solc-{0}'.format(identifier), - ) - else: - return os.path.expanduser(os.path.join( - '~', - '.py-solc', - 'solc-{0}'.format(identifier), - )) - - -def get_repository_path(identifier): - return os.path.join( - get_base_install_path(identifier), - 'source', - ) +# # +# # Installation filesystem path utilities +# # +# def get_base_install_path(identifier): +# if 'SOLC_BASE_INSTALL_PATH' in os.environ: +# return os.path.join( +# os.environ['SOLC_BASE_INSTALL_PATH'], +# 'solc-{0}'.format(identifier), +# ) +# else: +# return os.path.expanduser(os.path.join( +# '~', +# '.py-solc', +# 'solc-{0}'.format(identifier), +# )) -def get_release_zipfile_path(identifier): - return os.path.join( - get_base_install_path(identifier), - 'release.zip', - ) +# def get_repository_path(identifier): +# return os.path.join( +# get_base_install_path(identifier), +# 'source', +# ) -def get_extract_path(identifier): - return os.path.join( - get_base_install_path(identifier), - 'bin', - ) +# def get_executable_path(identifier): +# return __file__.rsplit('/', maxsplit=2)[0] + '/bin/solc-' + identifier -def get_executable_path(identifier): - return __file__.rsplit('/', maxsplit=2)[0] + '/bin/solc-' + identifier +# def get_build_dir(identifier): +# repository_path = get_repository_path(identifier) +# return os.path.join( +# repository_path, +# 'build', +# ) -def get_build_dir(identifier): - repository_path = get_repository_path(identifier) - return os.path.join( - repository_path, - 'build', - ) +# def get_built_executable_path(identifier): +# build_dir = get_build_dir(identifier) +# return os.path.join( +# build_dir, +# 'solc', +# 'solc', +# ) -def get_built_executable_path(identifier): - build_dir = get_build_dir(identifier) - return os.path.join( - build_dir, - 'solc', - 'solc', - ) +# # +# # Installation primitives. +# # +# def clone_solidity_repository(identifier): +# if not is_executable_available('git'): +# raise OSError("The `git` is required but was not found") -# -# Installation primitives. -# -def clone_solidity_repository(identifier): - if not is_executable_available('git'): - raise OSError("The `git` is required but was not found") +# repository_path = get_repository_path(identifier) +# ensure_parent_dir_exists(repository_path) +# command = [ +# "git", "clone", +# "--recurse-submodules", +# "--branch", identifier, +# "--depth", "10", +# SOLIDITY_GIT_URI, +# repository_path, +# ] - repository_path = get_repository_path(identifier) - ensure_parent_dir_exists(repository_path) - command = [ - "git", "clone", - "--recurse-submodules", - "--branch", identifier, - "--depth", "10", - SOLIDITY_GIT_URI, - repository_path, - ] +# return check_subprocess_call( +# command, +# message="Checking out solidity repository @ {0}".format(identifier), +# ) - return check_subprocess_call( - command, - message="Checking out solidity repository @ {0}".format(identifier), - ) +# def install_solc_dependencies(identifier): +# repository_path = get_repository_path(identifier) +# if not is_git_repository(repository_path): +# raise OSError("Git repository not found @ {0}".format(repository_path)) -def initialize_repository_submodules(identifier): - if not is_executable_available('git'): - raise OSError("The `git` is required but was not found") +# with chdir(repository_path): +# install_deps_script_path = os.path.join(repository_path, 'scripts', 'install_deps.sh') - repository_path = get_repository_path(identifier) - command = [ - "git", "submodule", "update", "--init", "--recursive", - ] - check_subprocess_call( - command, - "Initializing repository submodules @ {0}".format(repository_path), - ) +# return check_subprocess_call( +# command=["sh", install_deps_script_path], +# message="Running dependency installation script `install_deps.sh` @ {0}".format( +# install_deps_script_path, +# ), +# ) -DOWNLOAD_UBUNTU_RELEASE_URI_TEMPLATE = "https://github.com/ethereum/solidity/releases/download/{0}/solidity-ubuntu-trusty.zip" # noqa: E501 +SOLC_BASE = __file__[:__file__.rindex('/')] + "/bin/solc-{}" +DOWNLOAD_BASE = "https://github.com/ethereum/solidity/releases/download/{}/{}" -def download_ubuntu_release(identifier): - download_uri = DOWNLOAD_UBUNTU_RELEASE_URI_TEMPLATE.format(identifier) - release_zipfile_path = get_release_zipfile_path(identifier) - ensure_parent_dir_exists(release_zipfile_path) - command = [ - "wget", download_uri, - '-c', # resume previously incomplete download. - '-O', release_zipfile_path, - ] +def _check_subprocess_output(command, message=None, stderr=subprocess.STDOUT, **proc_kwargs): + if message: + print(message) + print("Executing: {0}".format(" ".join(command))) - return check_subprocess_call( + return subprocess.check_output( command, - message="Downloading ubuntu release from {0}".format(download_uri), + stderr=subprocess.STDOUT, + **proc_kwargs ) +def _chmod_plus_x(executable_path): + current_st = os.stat(executable_path) + os.chmod(executable_path, current_st.st_mode | stat.S_IEXEC) -DOWNLOAD_STATIC_RELEASE_URI_TEMPLATE = "https://github.com/ethereum/solidity/releases/download/{0}/solc-static-linux" # noqa: E501 - - -def download_static_release(identifier): - download_uri = DOWNLOAD_STATIC_RELEASE_URI_TEMPLATE.format(identifier) - static_binary_path = get_executable_path(identifier) - - ensure_parent_dir_exists(static_binary_path) - +def install_solc_from_static_linux(identifier): + download = DOWNLOAD_BASE.format(identifier, "solc-static-linux") + binary_path = SOLC_BASE.format(identifier) + command = [ - "wget", download_uri, + "wget", download, '-c', # resume previously incomplete download. - '-O', static_binary_path, + '-O', binary_path, ] - return check_subprocess_call( + _check_subprocess_output( command, - message="Downloading static linux binary from {0}".format(download_uri), + message="Downloading static linux binary from {0}".format(download), ) - -def extract_release(identifier): - release_zipfile_path = get_release_zipfile_path(identifier) - - extract_path = get_extract_path(identifier) - ensure_path_exists(extract_path) - - print("Extracting zipfile: {0} -> {1}".format(release_zipfile_path, extract_path)) - - with zipfile.ZipFile(release_zipfile_path) as zipfile_file: - zipfile_file.extractall(extract_path) - - executable_path = get_executable_path(identifier) - - print("Making `solc` binary executable: `chmod +x {0}`".format(executable_path)) - chmod_plus_x(executable_path) - - -def install_solc_dependencies(identifier): - repository_path = get_repository_path(identifier) - if not is_git_repository(repository_path): - raise OSError("Git repository not found @ {0}".format(repository_path)) - - with chdir(repository_path): - install_deps_script_path = os.path.join(repository_path, 'scripts', 'install_deps.sh') - - return check_subprocess_call( - command=["sh", install_deps_script_path], - message="Running dependency installation script `install_deps.sh` @ {0}".format( - install_deps_script_path, - ), - ) - - -def install_solc_from_ubuntu_release_zip(identifier): - download_ubuntu_release(identifier) - extract_release(identifier) - - extract_path = get_extract_path(identifier) - executable_path = get_executable_path(identifier) - assert os.path.exists(executable_path), "Executable not found @ {}".format(executable_path) - - check_version_command = [executable_path, '--version'] + _chmod_plus_x(binary_path) check_subprocess_output( - check_version_command, + [executable_path, '--version'], message="Checking installed executable version @ {0}".format(executable_path), - env={'LD_LIBRARY_PATH': extract_path}, ) print("solc successfully installed at: {0}".format(executable_path)) -def install_solc_from_static_linux(identifier): - download_static_release(identifier) +# def build_solc_from_source(identifier): +# if not is_git_repository(get_repository_path(identifier)): +# clone_solidity_repository(identifier) - executable_path = get_executable_path(identifier) - chmod_plus_x(executable_path) +# build_dir = get_build_dir(identifier) +# ensure_path_exists(build_dir) - check_version_command = [executable_path, '--version'] +# with chdir(build_dir): +# cmake_command = ["cmake", ".."] +# check_subprocess_call( +# cmake_command, +# message="Running cmake build command", +# ) +# make_command = ["make"] +# check_subprocess_call( +# make_command, +# message="Running make command", +# ) - check_subprocess_output( - check_version_command, - message="Checking installed executable version @ {0}".format(executable_path), - ) +# built_executable_path = get_built_executable_path(identifier) +# chmod_plus_x(built_executable_path) - print("solc successfully installed at: {0}".format(executable_path)) +# executable_path = get_executable_path(identifier) +# ensure_parent_dir_exists(executable_path) +# os.symlink(built_executable_path, executable_path) +# chmod_plus_x(executable_path) -def build_solc_from_source(identifier): - if not is_git_repository(get_repository_path(identifier)): - clone_solidity_repository(identifier) - - build_dir = get_build_dir(identifier) - ensure_path_exists(build_dir) - - with chdir(build_dir): - cmake_command = ["cmake", ".."] - check_subprocess_call( - cmake_command, - message="Running cmake build command", - ) - make_command = ["make"] - check_subprocess_call( - make_command, - message="Running make command", - ) - - built_executable_path = get_built_executable_path(identifier) - chmod_plus_x(built_executable_path) - - executable_path = get_executable_path(identifier) - ensure_parent_dir_exists(executable_path) - os.symlink(built_executable_path, executable_path) - chmod_plus_x(executable_path) - - -def install_from_ubuntu_release(identifier): - if not is_git_repository(get_repository_path(identifier)): - clone_solidity_repository(identifier) - install_solc_dependencies(identifier) - install_solc_from_ubuntu_release_zip(identifier) - - executable_path = get_executable_path(identifier) - print("Succesfully installed solc @ `{0}`".format(executable_path)) - - -install_v0_4_1_linux = functools.partial(install_from_ubuntu_release, V0_4_1) -install_v0_4_2_linux = functools.partial(install_from_ubuntu_release, V0_4_2) -install_v0_4_6_linux = functools.partial(install_from_ubuntu_release, V0_4_6) -install_v0_4_7_linux = functools.partial(install_from_ubuntu_release, V0_4_7) -install_v0_4_8_linux = functools.partial(install_from_ubuntu_release, V0_4_8) -install_v0_4_9_linux = functools.partial(install_from_ubuntu_release, V0_4_9) - - -def install_from_static_linux(identifier): - install_solc_from_static_linux(identifier) - - executable_path = get_executable_path(identifier) - print("Succesfully installed solc @ `{0}`".format(executable_path)) - - -install_v0_4_11_linux = functools.partial(install_solc_from_static_linux, V0_4_11) -install_v0_4_12_linux = functools.partial(install_solc_from_static_linux, V0_4_12) -install_v0_4_13_linux = functools.partial(install_solc_from_static_linux, V0_4_13) -install_v0_4_14_linux = functools.partial(install_solc_from_static_linux, V0_4_14) -install_v0_4_15_linux = functools.partial(install_solc_from_static_linux, V0_4_15) -install_v0_4_16_linux = functools.partial(install_solc_from_static_linux, V0_4_16) -install_v0_4_17_linux = functools.partial(install_solc_from_static_linux, V0_4_17) -install_v0_4_18_linux = functools.partial(install_solc_from_static_linux, V0_4_18) -install_v0_4_19_linux = functools.partial(install_solc_from_static_linux, V0_4_19) -install_v0_4_20_linux = functools.partial(install_solc_from_static_linux, V0_4_20) -install_v0_4_21_linux = functools.partial(install_solc_from_static_linux, V0_4_21) -install_v0_4_22_linux = functools.partial(install_solc_from_static_linux, V0_4_22) -install_v0_4_23_linux = functools.partial(install_solc_from_static_linux, V0_4_23) -install_v0_4_24_linux = functools.partial(install_solc_from_static_linux, V0_4_24) -install_v0_4_25_linux = functools.partial(install_solc_from_static_linux, V0_4_25) -install_v0_5_0_linux = functools.partial(install_solc_from_static_linux, V0_5_0) -install_v0_5_1_linux = functools.partial(install_solc_from_static_linux, V0_5_1) -install_v0_5_2_linux = functools.partial(install_solc_from_static_linux, V0_5_2) - - -def install_from_source(identifier): - if not is_git_repository(get_repository_path(identifier)): - clone_solidity_repository(identifier) - install_solc_dependencies(identifier) - build_solc_from_source(identifier) - - executable_path = get_executable_path(identifier) - print("Succesfully installed solc @ `{0}`".format(executable_path)) - - -install_v0_4_8_osx = functools.partial(install_from_source, V0_4_8) -install_v0_4_11_osx = functools.partial(install_from_source, V0_4_11) -install_v0_4_12_osx = functools.partial(install_from_source, V0_4_12) -install_v0_4_13_osx = functools.partial(install_from_source, V0_4_13) -install_v0_4_14_osx = functools.partial(install_from_source, V0_4_14) -install_v0_4_15_osx = functools.partial(install_from_source, V0_4_15) -install_v0_4_16_osx = functools.partial(install_from_source, V0_4_16) -install_v0_4_17_osx = functools.partial(install_from_source, V0_4_17) -install_v0_4_18_osx = functools.partial(install_from_source, V0_4_18) -install_v0_4_19_osx = functools.partial(install_from_source, V0_4_19) -install_v0_4_20_osx = functools.partial(install_from_source, V0_4_20) -install_v0_4_21_osx = functools.partial(install_from_source, V0_4_21) -install_v0_4_22_osx = functools.partial(install_from_source, V0_4_22) -install_v0_4_23_osx = functools.partial(install_from_source, V0_4_23) -install_v0_4_24_osx = functools.partial(install_from_source, V0_4_24) -install_v0_4_25_osx = functools.partial(install_from_source, V0_4_25) -install_v0_5_0_osx = functools.partial(install_from_source, V0_5_0) -install_v0_5_1_osx = functools.partial(install_from_source, V0_5_1) -install_v0_5_2_osx = functools.partial(install_from_source, V0_5_2) - -INSTALL_FUNCTIONS = { - LINUX: { - V0_4_1: install_v0_4_1_linux, - V0_4_2: install_v0_4_2_linux, - V0_4_6: install_v0_4_6_linux, - V0_4_7: install_v0_4_7_linux, - V0_4_8: install_v0_4_8_linux, - V0_4_9: install_v0_4_9_linux, - V0_4_11: install_v0_4_11_linux, - V0_4_12: install_v0_4_12_linux, - V0_4_13: install_v0_4_13_linux, - V0_4_14: install_v0_4_14_linux, - V0_4_15: install_v0_4_15_linux, - V0_4_16: install_v0_4_16_linux, - V0_4_17: install_v0_4_17_linux, - V0_4_18: install_v0_4_18_linux, - V0_4_19: install_v0_4_19_linux, - V0_4_20: install_v0_4_20_linux, - V0_4_21: install_v0_4_21_linux, - V0_4_22: install_v0_4_22_linux, - V0_4_23: install_v0_4_23_linux, - V0_4_24: install_v0_4_24_linux, - V0_4_25: install_v0_4_25_linux, - V0_5_0: install_v0_5_0_linux, - V0_5_1: install_v0_5_1_linux, - V0_5_2: install_v0_5_2_linux - }, - OSX: { - V0_4_8: install_v0_4_8_osx, - V0_4_11: install_v0_4_11_osx, - V0_4_12: install_v0_4_12_osx, - V0_4_13: install_v0_4_13_osx, - V0_4_14: install_v0_4_14_osx, - V0_4_15: install_v0_4_15_osx, - V0_4_16: install_v0_4_16_osx, - V0_4_17: install_v0_4_17_osx, - V0_4_18: install_v0_4_18_osx, - V0_4_19: install_v0_4_19_osx, - V0_4_20: install_v0_4_20_osx, - V0_4_21: install_v0_4_21_osx, - V0_4_22: install_v0_4_22_osx, - V0_4_23: install_v0_4_23_osx, - V0_4_24: install_v0_4_24_osx, - V0_4_25: install_v0_4_25_osx, - V0_5_0: install_v0_5_0_osx, - V0_5_1: install_v0_5_1_osx, - V0_5_2: install_v0_5_2_osx - } -} - - -def install_solc(identifier, platform=None): - if platform is None: - platform = get_platform() - - if platform not in INSTALL_FUNCTIONS: - raise ValueError( - "Installation of solidity is not supported on your platform ({0}). " - "Supported platforms are: {1}".format( - platform, - ', '.join(sorted(INSTALL_FUNCTIONS.keys())), - ) - ) - elif identifier not in INSTALL_FUNCTIONS[platform]: - raise ValueError( - "Installation of solidity=={0} is not supported. Must be one of {1}".format( - identifier, - ', '.join(sorted(INSTALL_FUNCTIONS[platform].keys())), - ) - ) - - install_fn = INSTALL_FUNCTIONS[platform][identifier] - install_fn() +# def install_from_source(identifier): +# if not is_git_repository(get_repository_path(identifier)): +# clone_solidity_repository(identifier) +# install_solc_dependencies(identifier) +# build_solc_from_source(identifier) + +# executable_path = get_executable_path(identifier) +# print("Succesfully installed solc @ `{0}`".format(executable_path)) + + + +def install_solc(identifier): + identifier = "v0." + identifier.lstrip("v0.") + if not os.path.exists(__file__[:__file__.rindex('/')] + "/bin"): + os.mkdir(__file__[:__file__.rindex('/')] + "/bin") + if sys.platform.startswith('linux'): + return install_solc_from_static_linux(identifier) + elif sys.platform == 'darwin' + return install_from_source(identifier) + elif sys.platform == 'win32': + return ## + raise KeyError("Unknown platform: {}".format(sys.platform)) if __name__ == "__main__": From ab9a63fe796957978ddf674bd7fe08f7f56c537f Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Wed, 23 Jan 2019 20:50:17 +0200 Subject: [PATCH 02/16] binary_path --- solc/__init__.py | 3 ++- solc/install.py | 18 +++++++++--------- solc/main.py | 2 +- solc/wrapper.py | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/solc/__init__.py b/solc/__init__.py index 0658b64..2f3d075 100644 --- a/solc/__init__.py +++ b/solc/__init__.py @@ -25,7 +25,8 @@ )) warnings.resetwarnings() -solc_folder = __file__.rsplit('/', maxsplit=2)[0] + "/bin" +solc_folder = __file__[:__file__.rindex('/')] + "/bin" + if not os.path.exists(solc_folder): os.mkdir(solc_folder) diff --git a/solc/install.py b/solc/install.py index 098b0e6..4a21553 100644 --- a/solc/install.py +++ b/solc/install.py @@ -201,14 +201,14 @@ -def _check_subprocess_output(command, message=None, stderr=subprocess.STDOUT, **proc_kwargs): +def _check_subprocess_call(command, message=None, verbose=True, **proc_kwargs): if message: print(message) print("Executing: {0}".format(" ".join(command))) - return subprocess.check_output( + return subprocess.check_call( command, - stderr=subprocess.STDOUT, + stderr=subprocess.STDOUT if verbose else subprocess.DEVNULL, **proc_kwargs ) @@ -226,19 +226,19 @@ def install_solc_from_static_linux(identifier): '-O', binary_path, ] - _check_subprocess_output( + _check_subprocess_call( command, message="Downloading static linux binary from {0}".format(download), ) _chmod_plus_x(binary_path) - check_subprocess_output( - [executable_path, '--version'], - message="Checking installed executable version @ {0}".format(executable_path), + _check_subprocess_call( + [binary_path, '--version'], + message="Checking installed executable version @ {0}".format(binary_path), ) - print("solc successfully installed at: {0}".format(executable_path)) + print("solc successfully installed at: {0}".format(binary_path)) # def build_solc_from_source(identifier): @@ -286,7 +286,7 @@ def install_solc(identifier): os.mkdir(__file__[:__file__.rindex('/')] + "/bin") if sys.platform.startswith('linux'): return install_solc_from_static_linux(identifier) - elif sys.platform == 'darwin' + elif sys.platform == 'darwin': return install_from_source(identifier) elif sys.platform == 'win32': return ## diff --git a/solc/main.py b/solc/main.py index 79eae27..a5d3d45 100644 --- a/solc/main.py +++ b/solc/main.py @@ -24,7 +24,7 @@ import semantic_version -SOLC_FOLDER = __file__.rsplit('/',maxsplit=2)[0]+'/bin' +SOLC_FOLDER = __file__[:__file__.rindex('/')] + "/bin" VERSION_DEV_DATE_MANGLER_RE = re.compile(r'(\d{4})\.0?(\d{1,2})\.0?(\d{1,2})') strip_zeroes_from_month_and_day = functools.partial(VERSION_DEV_DATE_MANGLER_RE.sub, r'\g<1>.\g<2>.\g<3>') diff --git a/solc/wrapper.py b/solc/wrapper.py index 7a134f2..7f51f82 100644 --- a/solc/wrapper.py +++ b/solc/wrapper.py @@ -11,7 +11,7 @@ coerce_return_to_text, ) -solc_folder = __file__.rsplit('/', maxsplit=2)[0] + "/bin" +solc_folder = __file__[:__file__.rindex('/')] + "/bin" def set_solc_binary_path(identifier): global solc_bin From 1f125ca99bc45c07ca495538f24a87e57dc81bcf Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Wed, 23 Jan 2019 20:54:53 +0200 Subject: [PATCH 03/16] linux prevent reinstall --- solc/install.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/solc/install.py b/solc/install.py index 4a21553..c4f4d83 100644 --- a/solc/install.py +++ b/solc/install.py @@ -216,29 +216,30 @@ def _chmod_plus_x(executable_path): current_st = os.stat(executable_path) os.chmod(executable_path, current_st.st_mode | stat.S_IEXEC) -def install_solc_from_static_linux(identifier): - download = DOWNLOAD_BASE.format(identifier, "solc-static-linux") - binary_path = SOLC_BASE.format(identifier) - - command = [ - "wget", download, - '-c', # resume previously incomplete download. - '-O', binary_path, - ] +def install_solc_from_static_linux(version): + download = DOWNLOAD_BASE.format(version, "solc-static-linux") + binary_path = SOLC_BASE.format(version) + if os.path.exists(binary_path): + print("solc {} already installed at: {}".format(version, binary_path)) + return _check_subprocess_call( - command, - message="Downloading static linux binary from {0}".format(download), + [ + "wget", download, + '-c', # resume previously incomplete download. + '-O', binary_path, + ], + message="Downloading static linux binary from {}".format(download) ) _chmod_plus_x(binary_path) _check_subprocess_call( [binary_path, '--version'], - message="Checking installed executable version @ {0}".format(binary_path), + message="Checking installed executable version @ {}".format(binary_path) ) - print("solc successfully installed at: {0}".format(binary_path)) + print("solc {} successfully installed at: {}".format(version, binary_path)) # def build_solc_from_source(identifier): @@ -280,14 +281,14 @@ def install_solc_from_static_linux(identifier): -def install_solc(identifier): - identifier = "v0." + identifier.lstrip("v0.") +def install_solc(version): + version = "v0." + version.lstrip("v0.") if not os.path.exists(__file__[:__file__.rindex('/')] + "/bin"): os.mkdir(__file__[:__file__.rindex('/')] + "/bin") if sys.platform.startswith('linux'): - return install_solc_from_static_linux(identifier) + return install_solc_from_static_linux(version) elif sys.platform == 'darwin': - return install_from_source(identifier) + return install_from_source(version) elif sys.platform == 'win32': return ## raise KeyError("Unknown platform: {}".format(sys.platform)) @@ -295,9 +296,9 @@ def install_solc(identifier): if __name__ == "__main__": try: - identifier = sys.argv[1] + version = sys.argv[1] except IndexError: print("Invocation error. Should be invoked as `./install_solc.py `") sys.exit(1) - install_solc(identifier) + install_solc(version) From 0dcb0268a91d51562326053886ef99c5c36ea62d Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Wed, 23 Jan 2019 22:10:10 +0200 Subject: [PATCH 04/16] install osx --- solc/install.py | 276 +++++++++--------------------------------------- 1 file changed, 50 insertions(+), 226 deletions(-) diff --git a/solc/install.py b/solc/install.py index c4f4d83..5277daa 100644 --- a/solc/install.py +++ b/solc/install.py @@ -1,206 +1,19 @@ """ Install solc """ -import functools import os +import shutil import stat import subprocess import sys -import contextlib +import tarfile -import zipfile - -# V0_4_1 = 'v0.4.1' -# V0_4_2 = 'v0.4.2' -# V0_4_6 = 'v0.4.6' -# V0_4_7 = 'v0.4.7' -# V0_4_8 = 'v0.4.8' -# V0_4_9 = 'v0.4.9' -# V0_4_11 = 'v0.4.11' -# V0_4_12 = 'v0.4.12' -# V0_4_13 = 'v0.4.13' -# V0_4_14 = 'v0.4.14' -# V0_4_15 = 'v0.4.15' -# V0_4_16 = 'v0.4.16' -# V0_4_17 = 'v0.4.17' -# V0_4_18 = 'v0.4.18' -# V0_4_19 = 'v0.4.19' -# V0_4_20 = 'v0.4.20' -# V0_4_21 = 'v0.4.21' -# V0_4_22 = 'v0.4.22' -# V0_4_23 = 'v0.4.23' -# V0_4_24 = 'v0.4.24' -# V0_4_25 = 'v0.4.25' -# V0_5_0 = 'v0.5.0' -# V0_5_1 = 'v0.5.1' -# V0_5_2 = 'v0.5.2' - -# -# System utilities. -# -# @contextlib.contextmanager -# def chdir(path): -# original_path = os.getcwd() -# try: -# os.chdir(path) -# yield -# finally: -# os.chdir(original_path) - - -# def is_executable_available(program): -# def is_exe(fpath): -# return os.path.isfile(fpath) and os.access(fpath, os.X_OK) - -# fpath = os.path.dirname(program) -# if fpath: -# if is_exe(program): -# return True -# else: -# for path in os.environ["PATH"].split(os.pathsep): -# path = path.strip('"') -# exe_file = os.path.join(path, program) -# if is_exe(exe_file): -# return True - -# return False - - -# def ensure_path_exists(dir_path): -# """ -# Make sure that a path exists -# """ -# if not os.path.exists(dir_path): -# os.makedirs(dir_path) -# return True -# return False - - -# def ensure_parent_dir_exists(path): -# ensure_path_exists(os.path.dirname(path)) - - -# def check_subprocess_call(command, message=None, stderr=subprocess.STDOUT, **proc_kwargs): -# if message: -# print(message) -# print("Executing: {0}".format(" ".join(command))) - -# return subprocess.check_call( -# command, -# stderr=subprocess.STDOUT, -# **proc_kwargs -# ) - - - - - - - -# SOLIDITY_GIT_URI = "https://github.com/ethereum/solidity.git" - - -# def is_git_repository(path): -# git_dir = os.path.join( -# path, -# '.git', -# ) -# return os.path.exists(git_dir) - - -# # -# # Installation filesystem path utilities -# # -# def get_base_install_path(identifier): -# if 'SOLC_BASE_INSTALL_PATH' in os.environ: -# return os.path.join( -# os.environ['SOLC_BASE_INSTALL_PATH'], -# 'solc-{0}'.format(identifier), -# ) -# else: -# return os.path.expanduser(os.path.join( -# '~', -# '.py-solc', -# 'solc-{0}'.format(identifier), -# )) - - -# def get_repository_path(identifier): -# return os.path.join( -# get_base_install_path(identifier), -# 'source', -# ) - - - -# def get_executable_path(identifier): -# return __file__.rsplit('/', maxsplit=2)[0] + '/bin/solc-' + identifier - - -# def get_build_dir(identifier): -# repository_path = get_repository_path(identifier) -# return os.path.join( -# repository_path, -# 'build', -# ) - - -# def get_built_executable_path(identifier): -# build_dir = get_build_dir(identifier) -# return os.path.join( -# build_dir, -# 'solc', -# 'solc', -# ) - - -# # -# # Installation primitives. -# # -# def clone_solidity_repository(identifier): -# if not is_executable_available('git'): -# raise OSError("The `git` is required but was not found") - -# repository_path = get_repository_path(identifier) -# ensure_parent_dir_exists(repository_path) -# command = [ -# "git", "clone", -# "--recurse-submodules", -# "--branch", identifier, -# "--depth", "10", -# SOLIDITY_GIT_URI, -# repository_path, -# ] - -# return check_subprocess_call( -# command, -# message="Checking out solidity repository @ {0}".format(identifier), -# ) - - -# def install_solc_dependencies(identifier): -# repository_path = get_repository_path(identifier) -# if not is_git_repository(repository_path): -# raise OSError("Git repository not found @ {0}".format(repository_path)) - -# with chdir(repository_path): -# install_deps_script_path = os.path.join(repository_path, 'scripts', 'install_deps.sh') - -# return check_subprocess_call( -# command=["sh", install_deps_script_path], -# message="Running dependency installation script `install_deps.sh` @ {0}".format( -# install_deps_script_path, -# ), -# ) - - - -SOLC_BASE = __file__[:__file__.rindex('/')] + "/bin/solc-{}" +BINARY_FOLDER = __file__[:__file__.rindex('/')] + "/bin/" +SOLC_BASE = BINARY_FOLDER+"solc-{}" DOWNLOAD_BASE = "https://github.com/ethereum/solidity/releases/download/{}/{}" - def _check_subprocess_call(command, message=None, verbose=True, **proc_kwargs): if message: print(message) @@ -212,11 +25,13 @@ def _check_subprocess_call(command, message=None, verbose=True, **proc_kwargs): **proc_kwargs ) + def _chmod_plus_x(executable_path): current_st = os.stat(executable_path) os.chmod(executable_path, current_st.st_mode | stat.S_IEXEC) -def install_solc_from_static_linux(version): + +def install_solc_linux(version): download = DOWNLOAD_BASE.format(version, "solc-static-linux") binary_path = SOLC_BASE.format(version) if os.path.exists(binary_path): @@ -242,43 +57,52 @@ def install_solc_from_static_linux(version): print("solc {} successfully installed at: {}".format(version, binary_path)) -# def build_solc_from_source(identifier): -# if not is_git_repository(get_repository_path(identifier)): -# clone_solidity_repository(identifier) - -# build_dir = get_build_dir(identifier) -# ensure_path_exists(build_dir) - -# with chdir(build_dir): -# cmake_command = ["cmake", ".."] -# check_subprocess_call( -# cmake_command, -# message="Running cmake build command", -# ) -# make_command = ["make"] -# check_subprocess_call( -# make_command, -# message="Running make command", -# ) - -# built_executable_path = get_built_executable_path(identifier) -# chmod_plus_x(built_executable_path) +def install_solc_osx(version): + tar_path = BINARY_FOLDER + "solc-{}.tar.gz".format(version) + source_folder = BINARY_FOLDER+"solidity_{}".format(version[1:]) + download = DOWNLOAD_BASE.format(version, "solidity_{}.tar.gz".format(version[1:])) + binary_path = SOLC_BASE.format(version) + + if os.path.exists(binary_path): + print("solc {} already installed at: {}".format(version, binary_path)) + return + + _check_subprocess_call( + [ + "wget", download, + '-c', # resume previously incomplete download. + '-O', tar_path, + ], + message="Downloading source from {}".format(download) + ) -# executable_path = get_executable_path(identifier) -# ensure_parent_dir_exists(executable_path) -# os.symlink(built_executable_path, executable_path) -# chmod_plus_x(executable_path) + with tarfile.open(tar_path, "w:gz") as tar: + tar.extractall() + os.remove(tar_path) + _check_subprocess_call( + ["sh", source_folder+'/scripts/install_deps.sh'], + message="Running dependency installation script `install_deps.sh` @ {}".format(tar_path) + ) + original_path = os.getcwd() + os.mkdir(source_folder+'/build') + os.chdir(source_folder) + _check_subprocess_call( + ["cmake", "..", "&&", "make"], + message="Running cmake and make commands", + ) + os.chdir(original_path) + os.rename(source_folder+'/build/solc/solc', binary_path) + shutil.rmtree(source_folder) -# def install_from_source(identifier): -# if not is_git_repository(get_repository_path(identifier)): -# clone_solidity_repository(identifier) -# install_solc_dependencies(identifier) -# build_solc_from_source(identifier) + _chmod_plus_x(binary_path) -# executable_path = get_executable_path(identifier) -# print("Succesfully installed solc @ `{0}`".format(executable_path)) + _check_subprocess_call( + [binary_path, '--version'], + message="Checking installed executable version @ {}".format(binary_path) + ) + print("solc {} successfully installed at: {}".format(version, binary_path)) def install_solc(version): @@ -286,9 +110,9 @@ def install_solc(version): if not os.path.exists(__file__[:__file__.rindex('/')] + "/bin"): os.mkdir(__file__[:__file__.rindex('/')] + "/bin") if sys.platform.startswith('linux'): - return install_solc_from_static_linux(version) + return install_solc_linux(version) elif sys.platform == 'darwin': - return install_from_source(version) + return install_solc_osx(version) elif sys.platform == 'win32': return ## raise KeyError("Unknown platform: {}".format(sys.platform)) From e190fc2989f15e910cef586e29e04c582baa7cb6 Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Wed, 23 Jan 2019 22:39:25 +0200 Subject: [PATCH 05/16] install windows --- solc/install.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/solc/install.py b/solc/install.py index 5277daa..d566948 100644 --- a/solc/install.py +++ b/solc/install.py @@ -7,7 +7,7 @@ import subprocess import sys import tarfile - +import zipfile BINARY_FOLDER = __file__[:__file__.rindex('/')] + "/bin/" SOLC_BASE = BINARY_FOLDER+"solc-{}" @@ -105,6 +105,35 @@ def install_solc_osx(version): print("solc {} successfully installed at: {}".format(version, binary_path)) +def install_solc_windows(version): + download = DOWNLOAD_BASE.format(version, "solidity-windows.zip") + zip_path = BINARY_FOLDER + 'solc_{}.zip'.format(version[1:]) + binary_path = SOLC_BASE.format(version) + if os.path.exists(binary_path): + print("solc {} already installed at: {}".format(version, binary_path)) + return + + _check_subprocess_call( + [ + "wget", download, + '-c', # resume previously incomplete download. + '-O', zip_path, + ], + message="Downloading solc for windows from {}".format(download) + ) + + with zipfile.ZipFile(zip_path) as zf: + zf.extractall("solc.exe") + os.remove(zip_path) + os.rename("solc.exe", binary_path) + + _check_subprocess_call( + [binary_path, '--version'], + message="Checking installed executable version @ {}".format(binary_path) + ) + + print("solc {} successfully installed at: {}".format(version, binary_path)) + def install_solc(version): version = "v0." + version.lstrip("v0.") if not os.path.exists(__file__[:__file__.rindex('/')] + "/bin"): @@ -114,7 +143,7 @@ def install_solc(version): elif sys.platform == 'darwin': return install_solc_osx(version) elif sys.platform == 'win32': - return ## + return install_solc_windows(version) raise KeyError("Unknown platform: {}".format(sys.platform)) From 92766ea2d0c6174c1623c1d22016f9b027f4c891 Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Wed, 23 Jan 2019 23:17:26 +0200 Subject: [PATCH 06/16] get latest version --- solc/install.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/solc/install.py b/solc/install.py index d566948..664ec15 100644 --- a/solc/install.py +++ b/solc/install.py @@ -2,6 +2,7 @@ Install solc """ import os +import requests import shutil import stat import subprocess @@ -12,6 +13,7 @@ BINARY_FOLDER = __file__[:__file__.rindex('/')] + "/bin/" SOLC_BASE = BINARY_FOLDER+"solc-{}" DOWNLOAD_BASE = "https://github.com/ethereum/solidity/releases/download/{}/{}" +API = "https://api.github.com/repos/ethereum/solidity/releases/latest" def _check_subprocess_call(command, message=None, verbose=True, **proc_kwargs): @@ -134,8 +136,11 @@ def install_solc_windows(version): print("solc {} successfully installed at: {}".format(version, binary_path)) -def install_solc(version): - version = "v0." + version.lstrip("v0.") +def install_solc(version = None): + if not version: + version = requests.get(API).json()['tag_name'] + else: + version = "v0." + version.lstrip("v0.") if not os.path.exists(__file__[:__file__.rindex('/')] + "/bin"): os.mkdir(__file__[:__file__.rindex('/')] + "/bin") if sys.platform.startswith('linux'): From 150971a154c0057930ba964ac1d89e0d74579cd0 Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Wed, 23 Jan 2019 23:49:08 +0200 Subject: [PATCH 07/16] cross-platform folders --- solc/__init__.py | 1 + solc/install.py | 17 +++++++++++++---- solc/main.py | 6 +++++- solc/wrapper.py | 5 +++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/solc/__init__.py b/solc/__init__.py index 2f3d075..b5ebc0f 100644 --- a/solc/__init__.py +++ b/solc/__init__.py @@ -16,6 +16,7 @@ ) from .install import ( install_solc, + get_solc_folder ) if sys.version_info.major < 3: diff --git a/solc/install.py b/solc/install.py index 664ec15..4e4cc65 100644 --- a/solc/install.py +++ b/solc/install.py @@ -10,8 +10,17 @@ import tarfile import zipfile -BINARY_FOLDER = __file__[:__file__.rindex('/')] + "/bin/" -SOLC_BASE = BINARY_FOLDER+"solc-{}" + +def get_solc_folder(): + if sys.platform=="win32": + s = '\\' + else: + s = '/' + return __file__[:__file__.rindex(s)] + s + 'bin' + s + + +BINARY_FOLDER = get_solc_folder() +SOLC_BASE = get_solc_folder()+"solc-{}" DOWNLOAD_BASE = "https://github.com/ethereum/solidity/releases/download/{}/{}" API = "https://api.github.com/repos/ethereum/solidity/releases/latest" @@ -141,8 +150,8 @@ def install_solc(version = None): version = requests.get(API).json()['tag_name'] else: version = "v0." + version.lstrip("v0.") - if not os.path.exists(__file__[:__file__.rindex('/')] + "/bin"): - os.mkdir(__file__[:__file__.rindex('/')] + "/bin") + if not os.path.exists(BINARY_FOLDER): + os.mkdir(BINARY_FOLDER) if sys.platform.startswith('linux'): return install_solc_linux(version) elif sys.platform == 'darwin': diff --git a/solc/main.py b/solc/main.py index a5d3d45..7365e71 100644 --- a/solc/main.py +++ b/solc/main.py @@ -15,6 +15,7 @@ ) from .install import ( # noqa: F401 install_solc, + get_solc_folder ) from .wrapper import ( get_solc_binary_path, @@ -24,7 +25,10 @@ import semantic_version -SOLC_FOLDER = __file__[:__file__.rindex('/')] + "/bin" + + + +SOLC_FOLDER = get_solc_folder() VERSION_DEV_DATE_MANGLER_RE = re.compile(r'(\d{4})\.0?(\d{1,2})\.0?(\d{1,2})') strip_zeroes_from_month_and_day = functools.partial(VERSION_DEV_DATE_MANGLER_RE.sub, r'\g<1>.\g<2>.\g<3>') diff --git a/solc/wrapper.py b/solc/wrapper.py index 7f51f82..afd7c41 100644 --- a/solc/wrapper.py +++ b/solc/wrapper.py @@ -11,11 +11,12 @@ coerce_return_to_text, ) -solc_folder = __file__[:__file__.rindex('/')] + "/bin" +from .install import get_solc_folder + def set_solc_binary_path(identifier): global solc_bin - solc_bin = "{}/solc-{}".format(solc_folder, identifier) + solc_bin = "{}solc-{}".format(get_solc_folder(), identifier) def get_solc_binary_path(): return solc_bin From 628ae4c7e457a2b4f413d135cb85c1fc88cf10f2 Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Wed, 23 Jan 2019 23:52:49 +0200 Subject: [PATCH 08/16] bugfix --- solc/__init__.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/solc/__init__.py b/solc/__init__.py index b5ebc0f..b868699 100644 --- a/solc/__init__.py +++ b/solc/__init__.py @@ -19,20 +19,11 @@ get_solc_folder ) -if sys.version_info.major < 3: - warnings.simplefilter('always', DeprecationWarning) - warnings.warn(DeprecationWarning( - "The `py-solc` library is dropping support for Python 2. Upgrade to Python 3." - )) - warnings.resetwarnings() - -solc_folder = __file__[:__file__.rindex('/')] + "/bin" - - +solc_folder = get_solc_folder() if not os.path.exists(solc_folder): os.mkdir(solc_folder) if not get_installed_solc_versions(): - install_solc("v0.5.1") + install_solc() set_solc_version(get_installed_solc_versions()[-1]) \ No newline at end of file From 694ade4f89391865decacf838a79f1ed0cbdbff9 Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Thu, 24 Jan 2019 00:02:07 +0200 Subject: [PATCH 09/16] windows --- solc/install.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/solc/install.py b/solc/install.py index 4e4cc65..62faff1 100644 --- a/solc/install.py +++ b/solc/install.py @@ -1,6 +1,7 @@ """ Install solc """ +from io import BytesIO import os import requests import shutil @@ -132,9 +133,9 @@ def install_solc_windows(version): ], message="Downloading solc for windows from {}".format(download) ) - - with zipfile.ZipFile(zip_path) as zf: - zf.extractall("solc.exe") + request = requests.get(download) + with zipfile.ZipFile(BytesIO(request.content)) as zf: + zf.extract("solc.exe") os.remove(zip_path) os.rename("solc.exe", binary_path) From 02e81411590b6a841cda37e226b6066f3f1edf48 Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Thu, 24 Jan 2019 00:04:24 +0200 Subject: [PATCH 10/16] bugfix --- solc/install.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/solc/install.py b/solc/install.py index 62faff1..231e466 100644 --- a/solc/install.py +++ b/solc/install.py @@ -125,14 +125,6 @@ def install_solc_windows(version): print("solc {} already installed at: {}".format(version, binary_path)) return - _check_subprocess_call( - [ - "wget", download, - '-c', # resume previously incomplete download. - '-O', zip_path, - ], - message="Downloading solc for windows from {}".format(download) - ) request = requests.get(download) with zipfile.ZipFile(BytesIO(request.content)) as zf: zf.extract("solc.exe") From 48e758aea94a12e0cc09537d2e10e7620a92c08f Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Thu, 24 Jan 2019 02:12:25 +0200 Subject: [PATCH 11/16] reorg --- solc/__init__.py | 17 +++------- solc/install.py | 83 ++++++++++++++++++++++++++++++++---------------- solc/main.py | 28 +++------------- solc/wrapper.py | 12 ++----- 4 files changed, 66 insertions(+), 74 deletions(-) diff --git a/solc/__init__.py b/solc/__init__.py index b868699..b09ae88 100644 --- a/solc/__init__.py +++ b/solc/__init__.py @@ -7,8 +7,6 @@ from .main import ( # noqa: F401 get_solc_version_string, get_solc_version, - get_installed_solc_versions, - set_solc_version, compile_files, compile_source, compile_standard, @@ -16,14 +14,7 @@ ) from .install import ( install_solc, - get_solc_folder -) - -solc_folder = get_solc_folder() -if not os.path.exists(solc_folder): - os.mkdir(solc_folder) - -if not get_installed_solc_versions(): - install_solc() - -set_solc_version(get_installed_solc_versions()[-1]) \ No newline at end of file + get_installed_solc_versions, + get_solc_folder, + set_solc_version +) \ No newline at end of file diff --git a/solc/install.py b/solc/install.py index 231e466..0af759e 100644 --- a/solc/install.py +++ b/solc/install.py @@ -11,19 +11,39 @@ import tarfile import zipfile +DOWNLOAD_BASE = "https://github.com/ethereum/solidity/releases/download/{}/{}" +API = "https://api.github.com/repos/ethereum/solidity/releases/latest" -def get_solc_folder(): - if sys.platform=="win32": - s = '\\' - else: - s = '/' - return __file__[:__file__.rindex(s)] + s + 'bin' + s +sep = "\\" if sys.platform == "win32" else "/" +solc_version = None -BINARY_FOLDER = get_solc_folder() -SOLC_BASE = get_solc_folder()+"solc-{}" -DOWNLOAD_BASE = "https://github.com/ethereum/solidity/releases/download/{}/{}" -API = "https://api.github.com/repos/ethereum/solidity/releases/latest" +def _check_version(version): + if not version: + return requests.get(API).json()['tag_name'] + return "v0." + version.lstrip("v0.") + +def set_solc_version(version = None): + version = _check_version(version) + if not os.path.exists(get_executable(version)): + install_solc(version) + global solc_version + solc_version = version + +def get_executable(version = None): + if not version: + version = solc_version + solc_bin = "{}solc-{}".format(get_solc_folder(), version) + if sys.platform == "win32": + return solc_bin + sep + "solc.exe" + return solc_bin + +def get_solc_folder(): + return __file__[:__file__.rindex(sep)] + sep + "bin" + sep + +def get_installed_solc_versions(): + return sorted([i[5:] for i in os.listdir(get_solc_folder()) if 'solc-v' in i]) + def _check_subprocess_call(command, message=None, verbose=True, **proc_kwargs): @@ -45,7 +65,7 @@ def _chmod_plus_x(executable_path): def install_solc_linux(version): download = DOWNLOAD_BASE.format(version, "solc-static-linux") - binary_path = SOLC_BASE.format(version) + binary_path = get_solc_folder()+"solc-{}".format(version) if os.path.exists(binary_path): print("solc {} already installed at: {}".format(version, binary_path)) return @@ -70,10 +90,10 @@ def install_solc_linux(version): def install_solc_osx(version): - tar_path = BINARY_FOLDER + "solc-{}.tar.gz".format(version) - source_folder = BINARY_FOLDER+"solidity_{}".format(version[1:]) + tar_path = get_solc_folder() + "solc-{}.tar.gz".format(version) + source_folder = get_solc_folder() + "solidity_{}".format(version[1:]) download = DOWNLOAD_BASE.format(version, "solidity_{}.tar.gz".format(version[1:])) - binary_path = SOLC_BASE.format(version) + binary_path = get_solc_folder()+"solc-{}".format(version) if os.path.exists(binary_path): print("solc {} already installed at: {}".format(version, binary_path)) @@ -119,18 +139,17 @@ def install_solc_osx(version): def install_solc_windows(version): download = DOWNLOAD_BASE.format(version, "solidity-windows.zip") - zip_path = BINARY_FOLDER + 'solc_{}.zip'.format(version[1:]) - binary_path = SOLC_BASE.format(version) - if os.path.exists(binary_path): - print("solc {} already installed at: {}".format(version, binary_path)) + zip_path = get_solc_folder() + 'solc_{}.zip'.format(version[1:]) + install_folder = get_solc_folder()+"solc-{}".format(version) + if os.path.exists(install_folder): + print("solc {} already installed at: {}".format(version, install_folder)) return request = requests.get(download) with zipfile.ZipFile(BytesIO(request.content)) as zf: - zf.extract("solc.exe") - os.remove(zip_path) - os.rename("solc.exe", binary_path) - + zf.extractall(install_folder) + + binary_path = get_executable(version) _check_subprocess_call( [binary_path, '--version'], message="Checking installed executable version @ {}".format(binary_path) @@ -139,12 +158,7 @@ def install_solc_windows(version): print("solc {} successfully installed at: {}".format(version, binary_path)) def install_solc(version = None): - if not version: - version = requests.get(API).json()['tag_name'] - else: - version = "v0." + version.lstrip("v0.") - if not os.path.exists(BINARY_FOLDER): - os.mkdir(BINARY_FOLDER) + version = _check_version(version) if sys.platform.startswith('linux'): return install_solc_linux(version) elif sys.platform == 'darwin': @@ -154,6 +168,19 @@ def install_solc(version = None): raise KeyError("Unknown platform: {}".format(sys.platform)) +if not os.path.exists(get_solc_folder()): + os.mkdir(get_solc_folder()) + +if not get_installed_solc_versions(): + install_solc() + +set_solc_version(get_installed_solc_versions()[-1]) + + + + + + if __name__ == "__main__": try: version = sys.argv[1] diff --git a/solc/main.py b/solc/main.py index 7365e71..cee12a9 100644 --- a/solc/main.py +++ b/solc/main.py @@ -13,29 +13,21 @@ from .utils.filesystem import ( is_executable_available, ) -from .install import ( # noqa: F401 - install_solc, - get_solc_folder -) -from .wrapper import ( - get_solc_binary_path, - set_solc_binary_path, - solc_wrapper, -) +from .wrapper import solc_wrapper -import semantic_version +from .install import get_executable +import semantic_version -SOLC_FOLDER = get_solc_folder() VERSION_DEV_DATE_MANGLER_RE = re.compile(r'(\d{4})\.0?(\d{1,2})\.0?(\d{1,2})') strip_zeroes_from_month_and_day = functools.partial(VERSION_DEV_DATE_MANGLER_RE.sub, r'\g<1>.\g<2>.\g<3>') def is_solc_available(): - solc_binary = get_solc_binary_path() + solc_binary = get_executable() return is_executable_available(solc_binary) @@ -63,18 +55,6 @@ def get_solc_version(**kwargs): [len('Version: '):] .replace('++', 'pp'))) -def set_solc_version(identifier): - if identifier[0]!="v": - identifier = "v"+identifier - if not os.path.exists(SOLC_FOLDER+"/solc-"+identifier): - install_solc(identifier) - set_solc_binary_path(identifier) - -def get_installed_solc_versions(): - return sorted([i[5:] for i in os.listdir(SOLC_FOLDER) if 'solc-v' in i]) - - - def solc_supports_standard_json_interface(**kwargs): return get_solc_version() in semantic_version.Spec('>=0.4.11') diff --git a/solc/wrapper.py b/solc/wrapper.py index afd7c41..c5855f8 100644 --- a/solc/wrapper.py +++ b/solc/wrapper.py @@ -2,6 +2,7 @@ import os import subprocess +import sys from .exceptions import ( SolcError, @@ -11,16 +12,9 @@ coerce_return_to_text, ) -from .install import get_solc_folder +from .install import get_executable -def set_solc_binary_path(identifier): - global solc_bin - solc_bin = "{}solc-{}".format(get_solc_folder(), identifier) - -def get_solc_binary_path(): - return solc_bin - @coerce_return_to_text def solc_wrapper(solc_binary=None, stdin=None, @@ -56,7 +50,7 @@ def solc_wrapper(solc_binary=None, success_return_code=0, evm_version=None): if solc_binary is None: - solc_binary = get_solc_binary_path() + solc_binary = get_executable() command = [solc_binary] From 3df27326b457f5ba15fad1781c48bcb635da393c Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Thu, 24 Jan 2019 10:04:55 +0200 Subject: [PATCH 12/16] reorg, cleanup --- solc/__init__.py | 17 +++++++++--- solc/install.py | 68 +++++++++++++++++++++--------------------------- solc/main.py | 1 - solc/wrapper.py | 2 -- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/solc/__init__.py b/solc/__init__.py index b09ae88..ab7f24e 100644 --- a/solc/__init__.py +++ b/solc/__init__.py @@ -1,8 +1,6 @@ from __future__ import absolute_import import os -import sys -import warnings from .main import ( # noqa: F401 get_solc_version_string, @@ -17,4 +15,17 @@ get_installed_solc_versions, get_solc_folder, set_solc_version -) \ No newline at end of file +) + +# check for an installed version of solc +# install if none found +# default to latest version + +if not os.path.exists(get_solc_folder()): + os.mkdir(get_solc_folder()) + +if not get_installed_solc_versions(): + print("Cannot find solc, installing...") + install_solc() + +set_solc_version(get_installed_solc_versions()[-1]) \ No newline at end of file diff --git a/solc/install.py b/solc/install.py index 0af759e..9dfc2f0 100644 --- a/solc/install.py +++ b/solc/install.py @@ -18,17 +18,9 @@ solc_version = None -def _check_version(version): - if not version: - return requests.get(API).json()['tag_name'] - return "v0." + version.lstrip("v0.") +def get_solc_folder(): + return __file__[:__file__.rindex(sep)] + sep + "bin" + sep -def set_solc_version(version = None): - version = _check_version(version) - if not os.path.exists(get_executable(version)): - install_solc(version) - global solc_version - solc_version = version def get_executable(version = None): if not version: @@ -38,13 +30,35 @@ def get_executable(version = None): return solc_bin + sep + "solc.exe" return solc_bin -def get_solc_folder(): - return __file__[:__file__.rindex(sep)] + sep + "bin" + sep + +def set_solc_version(version = None): + version = _check_version(version) + if not os.path.exists(get_executable(version)): + install_solc(version) + global solc_version + solc_version = version + def get_installed_solc_versions(): return sorted([i[5:] for i in os.listdir(get_solc_folder()) if 'solc-v' in i]) +def install_solc(version = None): + version = _check_version(version) + if sys.platform.startswith('linux'): + return _install_solc_linux(version) + elif sys.platform == 'darwin': + return _install_solc_osx(version) + elif sys.platform == 'win32': + return _install_solc_windows(version) + raise KeyError("Unknown platform: {}".format(sys.platform)) + + +def _check_version(version): + if not version: + return requests.get(API).json()['tag_name'] + return "v0." + version.lstrip("v0.") + def _check_subprocess_call(command, message=None, verbose=True, **proc_kwargs): if message: @@ -63,7 +77,7 @@ def _chmod_plus_x(executable_path): os.chmod(executable_path, current_st.st_mode | stat.S_IEXEC) -def install_solc_linux(version): +def _install_solc_linux(version): download = DOWNLOAD_BASE.format(version, "solc-static-linux") binary_path = get_solc_folder()+"solc-{}".format(version) if os.path.exists(binary_path): @@ -89,7 +103,7 @@ def install_solc_linux(version): print("solc {} successfully installed at: {}".format(version, binary_path)) -def install_solc_osx(version): +def _install_solc_osx(version): tar_path = get_solc_folder() + "solc-{}.tar.gz".format(version) source_folder = get_solc_folder() + "solidity_{}".format(version[1:]) download = DOWNLOAD_BASE.format(version, "solidity_{}.tar.gz".format(version[1:])) @@ -137,7 +151,7 @@ def install_solc_osx(version): print("solc {} successfully installed at: {}".format(version, binary_path)) -def install_solc_windows(version): +def _install_solc_windows(version): download = DOWNLOAD_BASE.format(version, "solidity-windows.zip") zip_path = get_solc_folder() + 'solc_{}.zip'.format(version[1:]) install_folder = get_solc_folder()+"solc-{}".format(version) @@ -145,6 +159,7 @@ def install_solc_windows(version): print("solc {} already installed at: {}".format(version, install_folder)) return + print("Downloading solc {} from {}".format(version, download)) request = requests.get(download) with zipfile.ZipFile(BytesIO(request.content)) as zf: zf.extractall(install_folder) @@ -157,29 +172,6 @@ def install_solc_windows(version): print("solc {} successfully installed at: {}".format(version, binary_path)) -def install_solc(version = None): - version = _check_version(version) - if sys.platform.startswith('linux'): - return install_solc_linux(version) - elif sys.platform == 'darwin': - return install_solc_osx(version) - elif sys.platform == 'win32': - return install_solc_windows(version) - raise KeyError("Unknown platform: {}".format(sys.platform)) - - -if not os.path.exists(get_solc_folder()): - os.mkdir(get_solc_folder()) - -if not get_installed_solc_versions(): - install_solc() - -set_solc_version(get_installed_solc_versions()[-1]) - - - - - if __name__ == "__main__": try: diff --git a/solc/main.py b/solc/main.py index cee12a9..5e9439f 100644 --- a/solc/main.py +++ b/solc/main.py @@ -2,7 +2,6 @@ import functools import json -import os import re from .exceptions import ( diff --git a/solc/wrapper.py b/solc/wrapper.py index c5855f8..428a311 100644 --- a/solc/wrapper.py +++ b/solc/wrapper.py @@ -1,8 +1,6 @@ from __future__ import absolute_import -import os import subprocess -import sys from .exceptions import ( SolcError, From 9d21424aa7ad327b586dd94a7e8b4eaeb5e95274 Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Thu, 24 Jan 2019 10:33:45 +0200 Subject: [PATCH 13/16] better version handling, reorg --- solc/install.py | 105 +++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 59 deletions(-) diff --git a/solc/install.py b/solc/install.py index 9dfc2f0..faccfcd 100644 --- a/solc/install.py +++ b/solc/install.py @@ -14,7 +14,7 @@ DOWNLOAD_BASE = "https://github.com/ethereum/solidity/releases/download/{}/{}" API = "https://api.github.com/repos/ethereum/solidity/releases/latest" -sep = "\\" if sys.platform == "win32" else "/" +sep = "\\" if sys.platform == "win32" else "/" solc_version = None @@ -46,18 +46,31 @@ def get_installed_solc_versions(): def install_solc(version = None): version = _check_version(version) if sys.platform.startswith('linux'): - return _install_solc_linux(version) + _install_solc_linux(version) elif sys.platform == 'darwin': - return _install_solc_osx(version) + _install_solc_osx(version) elif sys.platform == 'win32': - return _install_solc_windows(version) - raise KeyError("Unknown platform: {}".format(sys.platform)) + _install_solc_windows(version) + else: + raise KeyError("Unknown platform: {}".format(sys.platform)) + binary_path = get_executable(version) + _check_subprocess_call( + [binary_path, '--version'], + message="Checking installed executable version @ {}".format(binary_path) + ) + print("solc {} successfully installed at: {}".format(version, binary_path)) def _check_version(version): if not version: return requests.get(API).json()['tag_name'] - return "v0." + version.lstrip("v0.") + version = "v0." + version.lstrip("v0.") + if version.count('.') != 2: + raise ValueError("solc version must be in the format v0.x.x") + v = [int(i) for i in version[1:].split('.')] + if v[1] < 4 or (v[1] == 4 and v[2] < 11): + raise ValueError("py-solc-x does not support solc versions <0.4.11") + return version def _check_subprocess_call(command, message=None, verbose=True, **proc_kwargs): @@ -77,30 +90,39 @@ def _chmod_plus_x(executable_path): os.chmod(executable_path, current_st.st_mode | stat.S_IEXEC) +def _wget(url, path): + try: + _check_subprocess_call( + ["wget", url, "-O", path], + "Downloading solc from {}".format(url) + ) + except subprocess.CalledProcessError: + if os.path.exists(path): + os.remove(path) + raise + + def _install_solc_linux(version): download = DOWNLOAD_BASE.format(version, "solc-static-linux") binary_path = get_solc_folder()+"solc-{}".format(version) if os.path.exists(binary_path): print("solc {} already installed at: {}".format(version, binary_path)) return - - _check_subprocess_call( - [ - "wget", download, - '-c', # resume previously incomplete download. - '-O', binary_path, - ], - message="Downloading static linux binary from {}".format(download) - ) - + _wget(download, binary_path) _chmod_plus_x(binary_path) - _check_subprocess_call( - [binary_path, '--version'], - message="Checking installed executable version @ {}".format(binary_path) - ) - print("solc {} successfully installed at: {}".format(version, binary_path)) +def _install_solc_windows(version): + download = DOWNLOAD_BASE.format(version, "solidity-windows.zip") + zip_path = get_solc_folder() + 'solc_{}.zip'.format(version[1:]) + install_folder = get_solc_folder()+"solc-{}".format(version) + if os.path.exists(install_folder): + print("solc {} already installed at: {}".format(version, install_folder)) + return + print("Downloading solc {} from {}".format(version, download)) + request = requests.get(download) + with zipfile.ZipFile(BytesIO(request.content)) as zf: + zf.extractall(install_folder) def _install_solc_osx(version): @@ -112,19 +134,13 @@ def _install_solc_osx(version): if os.path.exists(binary_path): print("solc {} already installed at: {}".format(version, binary_path)) return - - _check_subprocess_call( - [ - "wget", download, - '-c', # resume previously incomplete download. - '-O', tar_path, - ], - message="Downloading source from {}".format(download) - ) + + _wget(download, tar_path) with tarfile.open(tar_path, "w:gz") as tar: tar.extractall() os.remove(tar_path) + _check_subprocess_call( ["sh", source_folder+'/scripts/install_deps.sh'], message="Running dependency installation script `install_deps.sh` @ {}".format(tar_path) @@ -143,35 +159,6 @@ def _install_solc_osx(version): _chmod_plus_x(binary_path) - _check_subprocess_call( - [binary_path, '--version'], - message="Checking installed executable version @ {}".format(binary_path) - ) - - print("solc {} successfully installed at: {}".format(version, binary_path)) - - -def _install_solc_windows(version): - download = DOWNLOAD_BASE.format(version, "solidity-windows.zip") - zip_path = get_solc_folder() + 'solc_{}.zip'.format(version[1:]) - install_folder = get_solc_folder()+"solc-{}".format(version) - if os.path.exists(install_folder): - print("solc {} already installed at: {}".format(version, install_folder)) - return - - print("Downloading solc {} from {}".format(version, download)) - request = requests.get(download) - with zipfile.ZipFile(BytesIO(request.content)) as zf: - zf.extractall(install_folder) - - binary_path = get_executable(version) - _check_subprocess_call( - [binary_path, '--version'], - message="Checking installed executable version @ {}".format(binary_path) - ) - - print("solc {} successfully installed at: {}".format(version, binary_path)) - if __name__ == "__main__": try: From 0712c06b9d1d674ab29be236391147f23d5e11b3 Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Thu, 24 Jan 2019 10:36:20 +0200 Subject: [PATCH 14/16] update docs --- README.md | 93 +++++++++++++++++++------------------------------------ 1 file changed, 32 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 44a8514..51e898b 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,18 @@ -# py-solc +# py-solc-x [![Build Status](https://travis-ci.org/ethereum/py-solc.png)](https://travis-ci.org/ethereum/py-solc) [![PyPi version](https://img.shields.io/pypi/v/py-solc.svg)](https://pypi.python.org/pypi/py-solc) -Python wrapper around the `solc` Solidity compiler. +Python wrapper around the `solc` Solidity compiler with `0.5.x` support. +Forked from [py-solc](https://github.com/ethereum/py-solc). ## Dependency -This library requires the `solc` executable to be present. +This library allows the use of multiple versions of solc, and installs them as needed. You must have all required [solc dependencies](http://solidity.readthedocs.io/en/latest/installing-solidity.html) installed for it to work properly. -Only versions `>=0.4.2` are supported and tested though this library may work -with other versions. - -[solc installation instructions](http://solidity.readthedocs.io/en/latest/installing-solidity.html) +Versions `>=0.4.11` may be installed, however only versions `>=0.4.2` are supported and tested. ## Quickstart @@ -22,7 +20,7 @@ with other versions. Installation ```sh -pip install py-solc +pip install py-solc-x ``` ## Development @@ -36,6 +34,8 @@ pip install -e . -r requirements-dev.txt ### Running the tests +> Tests have not been updated from py-solc and will likely fail. Pull requests welcomed. + You can run the tests with: ```sh @@ -85,6 +85,30 @@ To issue an unstable version when the current version is stable, specify the new version explicitly, like `bumpversion --new-version 4.0.0-alpha.1 devnum` +## Installing the `solc` binary + +The first time py-solc-x is imported it will automatically install the latest version of solc. If you wish to install a different version you may do so from within python: + +```python +>>> from solc import install_solc +>>> install_solc('v0.4.25') +``` + +Or via the command line: + +```bash +$ python -m solc.install v0.4.25 +``` + +You can also view available versions or change the active version of solc: + +```python +>>> from solc import get_installed_solc_versions, set_solc_version +>>> get_installed_solc_versions() +['v0.4.25', 'v0.5.3'] + +>>> set_solc_version('v0.4.25) +``` ## Standard JSON Compilation @@ -118,7 +142,6 @@ Use the `solc.compile_standard` function to make use the [standard-json] compila ## Legacy Combined JSON compilation - ```python >>> from solc import compile_source, compile_files, link_code >>> compile_source("contract Foo { function Foo() {} }") @@ -165,58 +188,6 @@ Use the `solc.compile_standard` function to make use the [standard-json] compila ... "606060405260768060106000396000f3606060405260e060020a6000350463e7f09e058114601a575b005b60187f0c55699c00000000000000000000000000000000000000000000000000000000606090815273d3cda913deb6f67967b99d67acdfa1712c29360190630c55699c906064906000906004818660325a03f41560025750505056" ``` -## Setting the path to the `solc` binary - -You can use the environment variable `SOLC_BINARY` to set the path to your solc binary. - - -## Installing the `solc` binary - -> This feature is experimental and subject to breaking changes. - -Any of the following versions of `solc` can be installed using `py-solc` on the -listed platforms. - -* `v0.4.1` (linux) -* `v0.4.2` (linux) -* `v0.4.6` (linux) -* `v0.4.7` (linux) -* `v0.4.8` (linux/osx) -* `v0.4.9` (linux) -* `v0.4.11` (linux/osx) -* `v0.4.12` (linux/osx) -* `v0.4.13` (linux/osx) -* `v0.4.14` (linux/osx) -* `v0.4.15` (linux/osx) -* `v0.4.16` (linux/osx) -* `v0.4.17` (linux/osx) -* `v0.4.18` (linux/osx) -* `v0.4.19` (linux/osx) -* `v0.4.20` (linux/osx) -* `v0.4.21` (linux/osx) -* `v0.4.22` (linux/osx) -* `v0.4.23` (linux/osx) -* `v0.4.24` (linux/osx) -* `v0.4.25` (linux/osx) - -Installation can be done via the command line: - -```bash -$ python -m solc.install v0.4.25 -``` - -Or from python using the `install_solc` function. - -```python ->>> from solc import install_solc ->>> install_solc('v0.4.25') -``` - -The installed binary can be found under your home directory. The `v0.4.25` -binary would be located at `$HOME/.py-solc/solc-v0.4.25/bin/solc`. Older linux -installs will also require that you set the environment variable -`LD_LIBRARY_PATH=$HOME/.py-solc/solc-v0.4.25/bin` - ## Import path remappings From 2e990efb36bf297d633484c7269a86c54d55c8c3 Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Thu, 24 Jan 2019 23:14:50 +0100 Subject: [PATCH 15/16] prep for 0.1.0 release as solcx --- .bumpversion.cfg | 23 ------ CHANGELOG | 13 +++ CONTRIBUTING.md | 10 +-- README.md | 122 ++++++++-------------------- setup.py | 19 ++--- {solc => solcx}/__init__.py | 0 {solc => solcx}/exceptions.py | 0 {solc => solcx}/install.py | 0 {solc => solcx}/main.py | 0 {solc => solcx}/utils/__init__.py | 0 {solc => solcx}/utils/filesystem.py | 0 {solc => solcx}/utils/string.py | 0 {solc => solcx}/utils/types.py | 0 {solc => solcx}/wrapper.py | 0 14 files changed, 61 insertions(+), 126 deletions(-) delete mode 100644 .bumpversion.cfg rename {solc => solcx}/__init__.py (100%) rename {solc => solcx}/exceptions.py (100%) rename {solc => solcx}/install.py (100%) rename {solc => solcx}/main.py (100%) rename {solc => solcx}/utils/__init__.py (100%) rename {solc => solcx}/utils/filesystem.py (100%) rename {solc => solcx}/utils/string.py (100%) rename {solc => solcx}/utils/types.py (100%) rename {solc => solcx}/wrapper.py (100%) diff --git a/.bumpversion.cfg b/.bumpversion.cfg deleted file mode 100644 index ceefb01..0000000 --- a/.bumpversion.cfg +++ /dev/null @@ -1,23 +0,0 @@ -[bumpversion] -current_version = 3.2.0 -commit = True -tag = True -parse = (?P\d+)\.(?P\d+)\.(?P\d+)(-(?P[^.]*)\.(?P\d+))? -serialize = - {major}.{minor}.{patch}-{stage}.{devnum} - {major}.{minor}.{patch} - -[bumpversion:part:stage] -optional_value = stable -first_value = stable -values = - alpha - beta - stable - -[bumpversion:part:devnum] - -[bumpversion:file:setup.py] -search = version='{current_version}', -replace = version='{new_version}', - diff --git a/CHANGELOG b/CHANGELOG index c85576c..c12796d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,16 @@ +0.1.0 +----- + + - Initial forked release + - Support for `solc 0.5.x` + - Drop support for `solc < 0.4.11` + - Add Windows installer + - Change install location to ./solcx/bin - no longer uses standard installed verion + - Change active solc version with `solcx.set_solc_version` + + +Original py-solc changelog: + 3.0.0 ----- diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 238a17d..7463ba3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,19 +1,17 @@ # Development -To start development for Populus you should begin by cloning the repo. +To start development for py-solc-x you should begin by cloning the repo. ```bash -$ git clone git@github.com/pipermerriam/py-solc.git +$ git clone https://github.com/iamdefinitelyahuman/py-solc.git ``` - -# Cute Animal Pictures +## Cute Animal Pictures All pull requests need to have a cute animal picture. This is a very important part of the development process. - -# Pull Requests +## Pull Requests In general, pull requests are welcome. Please try to adhere to the following. diff --git a/README.md b/README.md index 51e898b..e276dea 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,15 @@ # py-solc-x -[![Build Status](https://travis-ci.org/ethereum/py-solc.png)](https://travis-ci.org/ethereum/py-solc) -[![PyPi version](https://img.shields.io/pypi/v/py-solc.svg)](https://pypi.python.org/pypi/py-solc) - - Python wrapper around the `solc` Solidity compiler with `0.5.x` support. Forked from [py-solc](https://github.com/ethereum/py-solc). -## Dependency +## Dependencies -This library allows the use of multiple versions of solc, and installs them as needed. You must have all required [solc dependencies](http://solidity.readthedocs.io/en/latest/installing-solidity.html) installed for it to work properly. +This library allows the use of multiple versions of solc, and installs them as needed. You must have all required [solc dependencies](https://solidity.readthedocs.io/en/latest/installing-solidity.html#building-from-source) installed for it to work properly. Versions `>=0.4.11` may be installed, however only versions `>=0.4.2` are supported and tested. - ## Quickstart Installation @@ -23,102 +18,37 @@ Installation pip install py-solc-x ``` -## Development - -Clone the repository and then run: - -```sh -pip install -e . -r requirements-dev.txt -``` - - -### Running the tests - -> Tests have not been updated from py-solc and will likely fail. Pull requests welcomed. - -You can run the tests with: - -```sh -py.test tests -``` - -Or you can install `tox` to run the full test suite. - - -### Releasing - -Pandoc is required for transforming the markdown README to the proper format to -render correctly on pypi. - -For Debian-like systems: - -``` -apt install pandoc -``` - -Or on OSX: - -```sh -brew install pandoc -``` - -To release a new version: - -```sh -bumpversion $$VERSION_PART_TO_BUMP$$ -git push && git push --tags -make release -``` - - -#### How to bumpversion - -The version format for this repo is `{major}.{minor}.{patch}` for stable, and -`{major}.{minor}.{patch}-{stage}.{devnum}` for unstable (`stage` can be alpha or beta). - -To issue the next version in line, use bumpversion and specify which part to bump, -like `bumpversion minor` or `bumpversion devnum`. - -If you are in a beta version, `bumpversion stage` will switch to a stable. - -To issue an unstable version when the current version is stable, specify the -new version explicitly, like `bumpversion --new-version 4.0.0-alpha.1 devnum` - - -## Installing the `solc` binary +## Installing the `solc` Executable The first time py-solc-x is imported it will automatically install the latest version of solc. If you wish to install a different version you may do so from within python: ```python ->>> from solc import install_solc +>>> from solcx import install_solc >>> install_solc('v0.4.25') ``` Or via the command line: ```bash -$ python -m solc.install v0.4.25 +$ python -m solcx.install v0.4.25 ``` You can also view available versions or change the active version of solc: ```python ->>> from solc import get_installed_solc_versions, set_solc_version +>>> from solcx import get_installed_solc_versions, set_solc_version >>> get_installed_solc_versions() ['v0.4.25', 'v0.5.3'] >>> set_solc_version('v0.4.25) ``` - ## Standard JSON Compilation -Use the `solc.compile_standard` function to make use the [standard-json] compilation feature. +Use the `solcx.compile_standard` function to make use of the [standard-json](http://solidity.readthedocs.io/en/latest/using-the-compiler.html#compiler-input-and-output-json-description) compilation feature. -[Solidity Documentation for Standard JSON input and ouptup format](http://solidity.readthedocs.io/en/develop/using-the-compiler.html#compiler-input-and-output-json-description) - -``` ->>> from solc import compile_standard +```python +>>> from solcx import compile_standard >>> compile_standard({ ... 'language': 'Solidity', ... 'sources': {'Foo.sol': 'content': "...."}, @@ -139,11 +69,10 @@ Use the `solc.compile_standard` function to make use the [standard-json] compila } ``` - ## Legacy Combined JSON compilation ```python ->>> from solc import compile_source, compile_files, link_code +>>> from solcx import compile_source, compile_files, link_code >>> compile_source("contract Foo { function Foo() {} }") { 'Foo': { @@ -188,17 +117,36 @@ Use the `solc.compile_standard` function to make use the [standard-json] compila ... "606060405260768060106000396000f3606060405260e060020a6000350463e7f09e058114601a575b005b60187f0c55699c00000000000000000000000000000000000000000000000000000000606090815273d3cda913deb6f67967b99d67acdfa1712c29360190630c55699c906064906000906004818660325a03f41560025750505056" ``` - -## Import path remappings +## Import Path Remappings `solc` provides path aliasing allow you to have more reusable project configurations. - + You can use this like: -``` -from solc import compile_source, compile_files, link_code +```python +>>> from solcx import compile_source, compile_files, link_code -compile_files([source_file_path], import_remappings=["zeppeling=/my-zeppelin-checkout-folder"]) +>>> compile_files([source_file_path], import_remappings=["zeppeling=/my-zeppelin-checkout-folder"]) ``` [More information about solc import aliasing](http://solidity.readthedocs.io/en/develop/layout-of-source-files.html#paths) + +## Development + +This project was recently forked from [py-solc](https://github.com/ethereum/py-solc) and should be considered a beta. Comments, questions, criticisms and pull requests are welcomed. + +### Running the tests + +> Tests have not been updated from py-solc and will likely fail. + +You can run the tests with: + +```sh +py.test tests +``` + +Or you can install `tox` to run the full test suite. + +## License + +This project is licensed under the [MIT license](LICENSE). \ No newline at end of file diff --git a/setup.py b/setup.py index d468787..585648c 100644 --- a/setup.py +++ b/setup.py @@ -7,20 +7,20 @@ setup( - name='py-solc', - # *IMPORTANT*: Don't manually change the version here. Use the 'bumpversion' utility. - version='3.2.0', - description="""Python wrapper around the solc binary""", + name='py-solc-x', + version='0.1.0', + description="""Python wrapper around the solc binary with 0.5.x support""", long_description_markdown_filename='README.md', - author='Piper Merriam', - author_email='pipermerriam@gmail.com', - url='https://github.com/ethereum/py-solc', + author='Benjamin Hauser (forked from py-solc by Piper Merriam)', + author_email='ben.hauser@hyperlink.technology', + url='https://github.com/iamdefinitelyahuman/py-solc-x', include_package_data=True, - py_modules=['solc'], + py_modules=['solcx'], setup_requires=['setuptools-markdown'], python_requires='>=3.4, <4', install_requires=[ "semantic_version>=2.6.0", + "requests>=2.9.1" ], license="MIT", zip_safe=False, @@ -30,10 +30,9 @@ 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Natural Language :: English', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6' ], ) diff --git a/solc/__init__.py b/solcx/__init__.py similarity index 100% rename from solc/__init__.py rename to solcx/__init__.py diff --git a/solc/exceptions.py b/solcx/exceptions.py similarity index 100% rename from solc/exceptions.py rename to solcx/exceptions.py diff --git a/solc/install.py b/solcx/install.py similarity index 100% rename from solc/install.py rename to solcx/install.py diff --git a/solc/main.py b/solcx/main.py similarity index 100% rename from solc/main.py rename to solcx/main.py diff --git a/solc/utils/__init__.py b/solcx/utils/__init__.py similarity index 100% rename from solc/utils/__init__.py rename to solcx/utils/__init__.py diff --git a/solc/utils/filesystem.py b/solcx/utils/filesystem.py similarity index 100% rename from solc/utils/filesystem.py rename to solcx/utils/filesystem.py diff --git a/solc/utils/string.py b/solcx/utils/string.py similarity index 100% rename from solc/utils/string.py rename to solcx/utils/string.py diff --git a/solc/utils/types.py b/solcx/utils/types.py similarity index 100% rename from solc/utils/types.py rename to solcx/utils/types.py diff --git a/solc/wrapper.py b/solcx/wrapper.py similarity index 100% rename from solc/wrapper.py rename to solcx/wrapper.py From b64265b4891ceccbd7577f80683c648f3992d0a6 Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Sat, 26 Jan 2019 21:30:35 +0100 Subject: [PATCH 16/16] osx install bugfixes --- solcx/install.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/solcx/install.py b/solcx/install.py index faccfcd..26bba38 100644 --- a/solcx/install.py +++ b/solcx/install.py @@ -137,10 +137,10 @@ def _install_solc_osx(version): _wget(download, tar_path) - with tarfile.open(tar_path, "w:gz") as tar: - tar.extractall() + with tarfile.open(tar_path, "r") as tar: + tar.extractall(get_solc_folder()) os.remove(tar_path) - + _check_subprocess_call( ["sh", source_folder+'/scripts/install_deps.sh'], message="Running dependency installation script `install_deps.sh` @ {}".format(tar_path) @@ -148,11 +148,9 @@ def _install_solc_osx(version): original_path = os.getcwd() os.mkdir(source_folder+'/build') - os.chdir(source_folder) - _check_subprocess_call( - ["cmake", "..", "&&", "make"], - message="Running cmake and make commands", - ) + os.chdir(source_folder+'/build') + _check_subprocess_call(["cmake", ".."], message="Running cmake") + _check_subprocess_call(["make"], message="Running make") os.chdir(original_path) os.rename(source_folder+'/build/solc/solc', binary_path) shutil.rmtree(source_folder)