Skip to content

Commit 3c235dc

Browse files
committed
Skip already installed versions in install_artifacts
solc-select would blindly install versions even if they already existed, which can cause issues in certain scenarios such as rate limiting. When using 'solc-select install all', this could cause interruptions, but by skipping already installed versions, users can retry multiple times without redundant downloads. This change improves efficiency and reduces unnecessary network requests by checking if a version directory exists and contains files before attempting installation.
1 parent 647341b commit 3c235dc

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

solc_select/solc_select.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,26 @@ def install_artifacts(versions: [str], silent: bool = False) -> bool:
206206
print(f"{', '.join(not_available_versions)} solc versions are not available.")
207207
return False
208208

209+
already_installed = installed_versions()
209210
for version, artifact in releases.items():
210211
if "all" not in versions:
211212
if versions and version not in versions:
212213
continue
213214

215+
artifact_file_dir = ARTIFACTS_DIR.joinpath(f"solc-{version}")
216+
217+
if version in already_installed:
218+
if os.listdir(artifact_file_dir):
219+
if not silent:
220+
print(f"Version '{version}' is already installed, skipping...")
221+
continue
222+
214223
(url, _) = get_url(version, artifact)
215224

216225
if is_linux_0818(version):
217226
url = CRYTIC_SOLC_ARTIFACTS + artifact
218227
print(url)
219228

220-
artifact_file_dir = ARTIFACTS_DIR.joinpath(f"solc-{version}")
221229
Path.mkdir(artifact_file_dir, parents=True, exist_ok=True)
222230
if not silent:
223231
print(f"Installing solc '{version}'...")

tests/test_upgrade.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,18 @@ def test_upgrade_preserves_versions(self, isolated_python_env):
6666
assert old_versions == new_versions, (
6767
f"Installed versions changed during upgrade.\nOld: {old_versions}\nNew: {new_versions}"
6868
)
69+
70+
def test_cache_already_installed(self, isolated_python_env):
71+
venv = isolated_python_env
72+
project_root = Path(__file__).parent.parent
73+
74+
# Install development version
75+
run_in_venv(venv, f"pip install -e {project_root}", check=True)
76+
77+
run_in_venv(venv, "solc-select install 0.8.20", check=False)
78+
79+
result = run_in_venv(venv, "solc-select install 0.8.20", check=False)
80+
already_installed = result.stdout.strip()
81+
assert "Version '0.8.20' is already installed, skipping.." in already_installed, (
82+
"No skipping already installed versions"
83+
)

0 commit comments

Comments
 (0)