Skip to content

Commit

Permalink
Matches solc output on uninstalled solc, the solidity compiler comman…
Browse files Browse the repository at this point in the history
…dline interface (#204)

Version: 0.8.23+commit.f704f362.Darwin.appleclang
  • Loading branch information
Nat Chin authored Nov 10, 2023
1 parent 19f1dfd commit b5dcebe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions solc_select/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
17 changes: 10 additions & 7 deletions solc_select/solc_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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)
Expand All @@ -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


Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b5dcebe

Please sign in to comment.