From b5dcebe234b13c7dd43b74fde3e92027e999963c Mon Sep 17 00:00:00 2001 From: Nat Chin Date: Fri, 10 Nov 2023 09:36:23 -0500 Subject: [PATCH] Matches solc output on uninstalled solc, the solidity compiler commandline interface (#204) Version: 0.8.23+commit.f704f362.Darwin.appleclang --- solc_select/__main__.py | 4 ++-- solc_select/solc_select.py | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/solc_select/__main__.py b/solc_select/__main__.py index bb20d30..fd0964f 100644 --- a/solc_select/__main__.py +++ b/solc_select/__main__.py @@ -60,7 +60,7 @@ def solc_select() -> None: install_artifacts(args.get(INSTALL_VERSIONS)) elif args.get(USE_VERSION) is not None: - switch_global_version(args.get(USE_VERSION), args.get("always_install")) + switch_global_version(args.get(USE_VERSION), args.get("always_install"), silent=False) elif args.get(SHOW_VERSIONS) is not None: versions_installed = installed_versions() @@ -86,7 +86,7 @@ def solc_select() -> None: def solc() -> None: if not installed_versions(): - switch_global_version(version="latest", always_install=True) + switch_global_version(version="latest", always_install=True, silent=True) res = current_version() if res: (version, _) = res diff --git a/solc_select/solc_select.py b/solc_select/solc_select.py index 78d1562..3aca587 100644 --- a/solc_select/solc_select.py +++ b/solc_select/solc_select.py @@ -87,7 +87,7 @@ def artifact_path(version: str) -> Path: return ARTIFACTS_DIR.joinpath(f"solc-{version}", f"solc-{version}") -def install_artifacts(versions: [str]) -> bool: +def install_artifacts(versions: [str], silent: bool = False) -> bool: releases = get_available_versions() versions = [get_latest_release() if ver == "latest" else ver for ver in versions] @@ -110,7 +110,8 @@ def install_artifacts(versions: [str]) -> bool: artifact_file_dir = ARTIFACTS_DIR.joinpath(f"solc-{version}") Path.mkdir(artifact_file_dir, parents=True, exist_ok=True) - print(f"Installing solc '{version}'...") + if not silent: + print(f"Installing solc '{version}'...") urllib.request.urlretrieve(url, artifact_file_dir.joinpath(f"solc-{version}")) verify_checksum(version) @@ -125,7 +126,8 @@ def install_artifacts(versions: [str]) -> bool: ) else: Path.chmod(artifact_file_dir.joinpath(f"solc-{version}"), 0o775) - print(f"Version '{version}' installed.") + if not silent: + print(f"Version '{version}' installed.") return True @@ -191,17 +193,18 @@ def get_url(version: str = "", artifact: str = "") -> (str, str): ) -def switch_global_version(version: str, always_install: bool) -> None: +def switch_global_version(version: str, always_install: bool, silent: bool = False) -> None: if version == "latest": version = get_latest_release() if version in installed_versions(): with open(f"{SOLC_SELECT_DIR}/global-version", "w", encoding="utf-8") as f: f.write(version) - print("Switched global version to", version) + if not silent: + print("Switched global version to", version) elif version in get_available_versions(): if always_install: - install_artifacts([version]) - switch_global_version(version, always_install) + install_artifacts([version], silent) + switch_global_version(version, always_install, silent) else: raise argparse.ArgumentTypeError(f"'{version}' must be installed prior to use.") else: