From 287c1a59e45a0a56b2412b03d3a199bb9b8c87e2 Mon Sep 17 00:00:00 2001 From: unparalleled-js Date: Wed, 24 Aug 2022 22:51:47 -0500 Subject: [PATCH 1/3] feat: make method not internal --- solcx/install.py | 6 +++--- solcx/main.py | 2 +- solcx/wrapper.py | 5 ++--- tests/install/test_compile.py | 4 ++-- tests/install/test_import_solc.py | 6 +++--- tests/install/test_validate_installation.py | 6 +++--- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/solcx/install.py b/solcx/install.py index e7be46e..0fe40f5 100644 --- a/solcx/install.py +++ b/solcx/install.py @@ -138,7 +138,7 @@ def import_installed_solc(solcx_binary_path: Union[Path, str] = None) -> List[Ve imported_versions = [] for path in path_list: try: - version = wrapper._get_solc_version(path) + version = wrapper.get_solc_version(path) assert version not in get_installed_solc_versions() except Exception: continue @@ -151,7 +151,7 @@ def import_installed_solc(solcx_binary_path: Union[Path, str] = None) -> List[Ve shutil.copy(path, copy_path) try: # confirm that solc still works after being copied - assert version == wrapper._get_solc_version(copy_path) + assert version == wrapper.get_solc_version(copy_path) imported_versions.append(version) except Exception: _unlink_solc(copy_path) @@ -630,7 +630,7 @@ def _install_solc_windows( def _validate_installation(version: Version, solcx_binary_path: Union[Path, str, None]) -> None: binary_path = get_executable(version, solcx_binary_path) try: - installed_version = wrapper._get_solc_version(binary_path) + installed_version = wrapper.get_solc_version(binary_path) except Exception: _unlink_solc(binary_path) raise SolcInstallationError( diff --git a/solcx/main.py b/solcx/main.py index a446f1b..9181d71 100644 --- a/solcx/main.py +++ b/solcx/main.py @@ -24,7 +24,7 @@ def get_solc_version(with_commit_hash: bool = False) -> Version: solc version """ solc_binary = get_executable() - return wrapper._get_solc_version(solc_binary, with_commit_hash) + return wrapper.get_solc_version(solc_binary, with_commit_hash) def compile_source( diff --git a/solcx/wrapper.py b/solcx/wrapper.py index b5c12fe..849c408 100644 --- a/solcx/wrapper.py +++ b/solcx/wrapper.py @@ -12,8 +12,7 @@ VERSION_REGEX = r"(\d+\.\d+\.\d+)(?:-nightly.\d+.\d+.\d+|)(\+commit.\w+)" -def _get_solc_version(solc_binary: Union[Path, str], with_commit_hash: bool = False) -> Version: - # private wrapper function to get `solc` version +def get_solc_version(solc_binary: Union[Path, str], with_commit_hash: bool = False) -> Version: stdout_data = subprocess.check_output([str(solc_binary), "--version"], encoding="utf8") try: match = next(re.finditer(VERSION_REGEX, stdout_data)) @@ -95,7 +94,7 @@ def solc_wrapper( else: solc_binary = install.get_executable() - solc_version = _get_solc_version(solc_binary) + solc_version = get_solc_version(solc_binary) command: List = [str(solc_binary)] if success_return_code is None: diff --git a/tests/install/test_compile.py b/tests/install/test_compile.py index 1cfbc7a..f11fbf6 100644 --- a/tests/install/test_compile.py +++ b/tests/install/test_compile.py @@ -22,7 +22,7 @@ def test_compile_already_installed(): @pytest.mark.skipif("sys.platform == 'win32'") def test_compile(compile_mock, solc_binary, cwd): - version = solcx.wrapper._get_solc_version(solc_binary) + version = solcx.wrapper.get_solc_version(solc_binary) solcx.compile_solc(version) assert os.getcwd() == cwd @@ -31,7 +31,7 @@ def test_compile(compile_mock, solc_binary, cwd): @pytest.mark.skipif("sys.platform == 'win32'") def test_compile_install_deps_fails(compile_mock, solc_binary, cwd): - version = solcx.wrapper._get_solc_version(solc_binary) + version = solcx.wrapper.get_solc_version(solc_binary) compile_mock.raise_on("sh") solcx.compile_solc(version) diff --git a/tests/install/test_import_solc.py b/tests/install/test_import_solc.py index 2feed6f..4d08a62 100644 --- a/tests/install/test_import_solc.py +++ b/tests/install/test_import_solc.py @@ -4,7 +4,7 @@ def test_import_solc(monkeypatch, solc_binary, nosolc): - version = solcx.wrapper._get_solc_version(solc_binary) + version = solcx.wrapper.get_solc_version(solc_binary) monkeypatch.setattr("solcx.install._get_which_solc", lambda: solc_binary) assert solcx.import_installed_solc() == [version] @@ -14,7 +14,7 @@ def test_import_solc(monkeypatch, solc_binary, nosolc): def test_import_solc_fails_after_importing(monkeypatch, solc_binary, nosolc): count = 0 - version = solcx.wrapper._get_solc_version(solc_binary) + version = solcx.wrapper.get_solc_version(solc_binary) def version_mock(*args): # the first version call succeeds, the second attempt fails @@ -26,7 +26,7 @@ def version_mock(*args): raise Exception monkeypatch.setattr("solcx.install._get_which_solc", lambda: solc_binary) - monkeypatch.setattr("solcx.wrapper._get_solc_version", version_mock) + monkeypatch.setattr("solcx.wrapper.get_solc_version", version_mock) assert solcx.import_installed_solc() == [] assert not nosolc.joinpath(solc_binary.name).exists() diff --git a/tests/install/test_validate_installation.py b/tests/install/test_validate_installation.py index d1d7068..353421b 100644 --- a/tests/install/test_validate_installation.py +++ b/tests/install/test_validate_installation.py @@ -10,7 +10,7 @@ def test_validate_installation_wrong_version(monkeypatch, install_mock, install_path): - monkeypatch.setattr("solcx.wrapper._get_solc_version", lambda k: Version("0.0.0")) + monkeypatch.setattr("solcx.wrapper.get_solc_version", lambda k: Version("0.0.0")) with pytest.raises(UnexpectedVersionError): solcx.install_solc() @@ -19,8 +19,8 @@ def test_validate_installation_wrong_version(monkeypatch, install_mock, install_ def test_validate_installation_nightly(monkeypatch, install_mock, solc_binary, install_path): - version = solcx.wrapper._get_solc_version(solc_binary) - monkeypatch.setattr("solcx.wrapper._get_solc_version", lambda k: Version(f"{version}-nightly")) + version = solcx.wrapper.get_solc_version(solc_binary) + monkeypatch.setattr("solcx.wrapper.get_solc_version", lambda k: Version(f"{version}-nightly")) with pytest.warns(UnexpectedVersionWarning): solcx.install_solc() From e7a76c31a0ff84ac291c4bf8ddf9e5bcdceddc8c Mon Sep 17 00:00:00 2001 From: unparalleled-js Date: Wed, 24 Aug 2022 22:53:48 -0500 Subject: [PATCH 2/3] feat: make method not internal --- solcx/wrapper.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/solcx/wrapper.py b/solcx/wrapper.py index 849c408..c127018 100644 --- a/solcx/wrapper.py +++ b/solcx/wrapper.py @@ -12,6 +12,11 @@ VERSION_REGEX = r"(\d+\.\d+\.\d+)(?:-nightly.\d+.\d+.\d+|)(\+commit.\w+)" +def _get_solc_version(solc_binary: Union[Path, str], with_commit_hash: bool = False) -> Version: + # TODO: Remove around 0.2.0. Was private, kept to prevent accidentally breaking downstream. + return get_solc_version(solc_binary, with_commit_hash=with_commit_hash) + + def get_solc_version(solc_binary: Union[Path, str], with_commit_hash: bool = False) -> Version: stdout_data = subprocess.check_output([str(solc_binary), "--version"], encoding="utf8") try: From 9ba3755e4ce38b9121c652bd2d97bb2f2a6cb178 Mon Sep 17 00:00:00 2001 From: unparalleled-js Date: Wed, 24 Aug 2022 22:56:05 -0500 Subject: [PATCH 3/3] feat: make method not internal --- solcx/wrapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solcx/wrapper.py b/solcx/wrapper.py index c127018..bb05771 100644 --- a/solcx/wrapper.py +++ b/solcx/wrapper.py @@ -13,7 +13,7 @@ def _get_solc_version(solc_binary: Union[Path, str], with_commit_hash: bool = False) -> Version: - # TODO: Remove around 0.2.0. Was private, kept to prevent accidentally breaking downstream. + # TODO: Remove around 1.2.0. Was private, kept to prevent accidentally breaking downstream. return get_solc_version(solc_binary, with_commit_hash=with_commit_hash)