Skip to content

Commit

Permalink
Merge pull request #164 from antazoey/fix/over-warning
Browse files Browse the repository at this point in the history
 fix: issue where always warned
  • Loading branch information
antazoey authored Feb 5, 2024
2 parents 164dabe + eee4fc6 commit 8136179
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 9 additions & 4 deletions solcx/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,9 @@ def install_solc(
version, filename, show_progress, solcx_binary_path=solcx_binary_path
)

base_version = version if isinstance(version, str) else version.base_version
try:
_validate_installation(version, solcx_binary_path=solcx_binary_path)
_validate_installation(Version(base_version), solcx_binary_path=solcx_binary_path)
except SolcInstallationError as exc:
if os_name != "windows":
exc.args = (
Expand Down Expand Up @@ -703,16 +704,20 @@ def _validate_installation(version: Version, solcx_binary_path: Union[Path, str,
installed_version_clean = Version(
Version(installed_version.replace("-nightly", "")).base_version
)
if installed_version_clean.base_version != version.base_version:
base_version = version if isinstance(version, str) else version.base_version
if installed_version_clean.base_version != base_version:
# Without the nightly suffix, it should be the same!
_unlink_solc(binary_path)
raise UnexpectedVersionError(
f"Attempted to install solc v{version}, but got solc v{installed_version}"
)
if installed_version not in (version.base_version, f"{version}"):
if installed_version_clean not in (
Version(base_version),
f"{base_version}",
) or installed_version.endswith("-nightly"):
# If it does have the nightly suffix, then only warn.
warnings.warn(
f"Installed solc version is v{installed_version}, expecting v{version.base_version}",
f"Installed solc version is v{installed_version_clean}, expecting v{base_version}",
UnexpectedVersionWarning,
)

Expand Down
7 changes: 6 additions & 1 deletion tests/install/test_install.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import pytest

import solcx
Expand All @@ -23,7 +25,10 @@ def test_install_unknown_version():

@pytest.mark.skipif("'--no-install' in sys.argv")
def test_progress_bar(nosolc):
assert solcx.install_solc("0.6.9", show_progress=True).base_version == "0.6.9"
# There should be no warnings!
with warnings.catch_warnings():
warnings.simplefilter("error")
assert solcx.install_solc("0.6.9", show_progress=True).base_version == "0.6.9"


def test_environment_var_path(monkeypatch, tmp_path):
Expand Down

0 comments on commit 8136179

Please sign in to comment.