Skip to content

Commit bed3ade

Browse files
committed
Additional cleanup
1 parent 4732852 commit bed3ade

File tree

5 files changed

+86
-75
lines changed

5 files changed

+86
-75
lines changed

solc_select/models.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -294,43 +294,46 @@ def _create_default_capability(self) -> PlatformCapability:
294294
@classmethod
295295
def current(cls) -> "Platform":
296296
"""Get the current system platform."""
297-
if sys.platform == "linux":
298-
os_type = "linux"
299-
elif sys.platform == "darwin":
300-
os_type = "darwin"
301-
elif sys.platform in ["win32", "cygwin"]:
302-
os_type = "windows"
303-
else:
297+
os_mapping = {
298+
"linux": "linux",
299+
"darwin": "darwin",
300+
"win32": "windows",
301+
"cygwin": "windows",
302+
}
303+
os_type = os_mapping.get(sys.platform)
304+
if os_type is None:
304305
raise ValueError(f"Unsupported platform: {sys.platform}")
305306

306-
architecture = cls._get_arch()
307-
return cls(os_type=os_type, architecture=architecture)
307+
return cls(os_type=os_type, architecture=cls._get_arch())
308308

309309
@staticmethod
310310
def _get_arch() -> str:
311311
"""Get the current system architecture."""
312312
machine = platform.machine().lower()
313-
if machine in ["x86_64", "amd64"]:
314-
return "amd64"
315-
elif machine in ["aarch64", "arm64"]:
316-
return "arm64"
317-
return machine
313+
arch_mapping = {
314+
"x86_64": "amd64",
315+
"amd64": "amd64",
316+
"aarch64": "arm64",
317+
"arm64": "arm64",
318+
}
319+
return arch_mapping.get(machine, machine)
318320

319321
def get_soliditylang_key(self) -> str:
320322
"""Get the platform key used by binaries.soliditylang.org."""
321-
if self.os_type == "linux" and self.architecture == "amd64":
322-
return LINUX_AMD64
323-
elif self.os_type == "linux" and self.architecture == "arm64":
324-
return LINUX_ARM64
325-
elif self.os_type == "darwin" and self.architecture in ["amd64", "arm64"]:
326-
# soliditylang.org uses macosx-amd64 for both Intel and ARM (with Rosetta and universal binaries)
327-
return MACOSX_AMD64
328-
elif self.os_type == "windows" and self.architecture == "amd64":
329-
return WINDOWS_AMD64
330-
else:
323+
# soliditylang.org uses macosx-amd64 for both Intel and ARM (with Rosetta and universal binaries)
324+
platform_keys = {
325+
("linux", "amd64"): LINUX_AMD64,
326+
("linux", "arm64"): LINUX_ARM64,
327+
("darwin", "amd64"): MACOSX_AMD64,
328+
("darwin", "arm64"): MACOSX_AMD64,
329+
("windows", "amd64"): WINDOWS_AMD64,
330+
}
331+
key = platform_keys.get((self.os_type, self.architecture))
332+
if key is None:
331333
raise ValueError(
332334
f"Unsupported platform combination: {self.os_type}-{self.architecture}"
333335
)
336+
return key
334337

335338

336339
@dataclass(kw_only=True)

solc_select/repositories.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ def latest_version(self) -> SolcVersion:
9494
version_objs = [SolcVersion.parse(v) for v in versions]
9595
return max(version_objs)
9696

97-
def get_download_url(self, version: SolcVersion, artifact_filename: str) -> str:
98-
"""Get the download URL for a specific version."""
97+
def get_download_url(self, artifact_filename: str) -> str:
98+
"""Get the download URL for a specific artifact."""
9999
return f"{self.base_url}{artifact_filename}"
100100

101101
def get_checksums(self, version: SolcVersion) -> tuple[str, str | None]:

solc_select/services/artifact_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def create_artifact_metadata(self, version: SolcVersion) -> SolcArtifact:
106106
raise ValueError(f"Version {version} is not available")
107107

108108
artifact_filename = available[version_str]
109-
download_url = repo.get_download_url(version, artifact_filename)
109+
download_url = repo.get_download_url(artifact_filename)
110110
sha256_hash, keccak256_hash = repo.get_checksums(version)
111111

112112
return SolcArtifact(

solc_select/services/platform_service.py

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -59,67 +59,72 @@ def warn_about_arm64_compatibility(self, force: bool = False) -> None:
5959
if not force and warning_file.exists():
6060
return
6161

62-
print("\n⚠️ WARNING: ARM64 Architecture Detected", file=sys.stderr)
62+
print("\n[!] WARNING: ARM64 Architecture Detected", file=sys.stderr)
6363
print("=" * 50, file=sys.stderr)
6464

65-
show_remediation = False
65+
show_remediation = self._print_platform_status()
6666

67+
if show_remediation:
68+
self._print_remediation_steps()
69+
70+
print("=" * 50, file=sys.stderr)
71+
print(file=sys.stderr)
72+
73+
# Mark that we've shown the warning
74+
SOLC_SELECT_DIR.mkdir(parents=True, exist_ok=True)
75+
with contextlib.suppress(OSError):
76+
warning_file.touch()
77+
78+
def _print_platform_status(self) -> bool:
79+
"""Print platform-specific ARM64 status and return whether remediation is needed."""
6780
if self.platform.os_type == "darwin":
68-
print(" Native ARM64 binaries available for versions 0.8.5-0.8.23", file=sys.stderr)
69-
print(" Universal binaries available for versions 0.8.24+", file=sys.stderr)
81+
print("[+] Native ARM64 binaries available for versions 0.8.5-0.8.23", file=sys.stderr)
82+
print("[+] Universal binaries available for versions 0.8.24+", file=sys.stderr)
7083

7184
if detect_rosetta():
7285
print(
73-
"✓ Rosetta 2 detected - will use emulation for older versions", file=sys.stderr
74-
)
75-
print(" Note: Performance will be slower for emulated versions", file=sys.stderr)
76-
else:
77-
print(
78-
"⚠ Rosetta 2 not available - versions prior to 0.8.5 are x86_64 only and will not work",
86+
"[+] Rosetta 2 detected - will use emulation for older versions",
7987
file=sys.stderr,
8088
)
81-
show_remediation = True
89+
print(" Note: Performance will be slower for emulated versions", file=sys.stderr)
90+
return False
91+
92+
print(
93+
"[!] Rosetta 2 not available - versions prior to 0.8.5 are x86_64 only and will not work",
94+
file=sys.stderr,
95+
)
96+
return True
8297

83-
elif self.platform.os_type == "linux":
84-
print(" Native ARM64 binaries available for versions 0.8.31+", file=sys.stderr)
98+
if self.platform.os_type == "linux":
99+
print("[+] Native ARM64 binaries available for versions 0.8.31+", file=sys.stderr)
85100

86101
if detect_qemu():
87102
print(
88-
" qemu-x86_64 detected - will use emulation for versions < 0.8.31",
103+
"[+] qemu-x86_64 detected - will use emulation for versions < 0.8.31",
89104
file=sys.stderr,
90105
)
91106
print(" Note: Performance will be slower for emulated versions", file=sys.stderr)
92-
else:
93-
print(
94-
"⚠ Versions < 0.8.31 require x86_64 emulation, but qemu is not installed",
95-
file=sys.stderr,
96-
)
97-
show_remediation = True
98-
else:
99-
show_remediation = True
107+
return False
100108

101-
if show_remediation:
102-
print("\nTo use solc-select on ARM64, you can:", file=sys.stderr)
103-
print(" 1. Install software for x86_64 emulation:", file=sys.stderr)
109+
print(
110+
"[!] Versions < 0.8.31 require x86_64 emulation, but qemu is not installed",
111+
file=sys.stderr,
112+
)
113+
return True
104114

105-
if self.platform.os_type == "linux":
106-
print(
107-
" sudo apt-get install qemu-user-static # Debian/Ubuntu", file=sys.stderr
108-
)
109-
print(" sudo dnf install qemu-user-static # Fedora", file=sys.stderr)
110-
print(" sudo pacman -S qemu-user-static # Arch", file=sys.stderr)
111-
elif self.platform.os_type == "darwin":
112-
print(
113-
" Use Rosetta 2 (installed automatically on Apple Silicon)", file=sys.stderr
114-
)
115+
return True
115116

116-
print(" 2. Use an x86_64 Docker container", file=sys.stderr)
117-
print(" 3. Use a cloud-based development environment", file=sys.stderr)
117+
def _print_remediation_steps(self) -> None:
118+
"""Print remediation steps for ARM64 emulation setup."""
119+
print("\nTo use solc-select on ARM64, you can:", file=sys.stderr)
120+
print(" 1. Install software for x86_64 emulation:", file=sys.stderr)
118121

119-
print("=" * 50, file=sys.stderr)
120-
print(file=sys.stderr)
122+
if self.platform.os_type == "linux":
123+
print(" sudo apt-get install qemu-user-static # Debian/Ubuntu", file=sys.stderr)
124+
print(" sudo dnf install qemu-user-static # Fedora", file=sys.stderr)
125+
print(" sudo pacman -S qemu-user-static # Arch", file=sys.stderr)
126+
elif self.platform.os_type == "darwin":
127+
print(" Use Rosetta 2 (installed automatically on Apple Silicon)", file=sys.stderr)
121128

122-
# Mark that we've shown the warning
123-
SOLC_SELECT_DIR.mkdir(parents=True, exist_ok=True)
124-
with contextlib.suppress(OSError):
125-
warning_file.touch()
129+
print(" 2. Use an x86_64 Docker container", file=sys.stderr)
130+
print(" 3. Use a cloud-based development environment", file=sys.stderr)

solc_select/services/repository_matcher.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,13 @@ def _create_repository(
184184
platform_obj = Platform(os_type=platform.os_type, architecture=platform.architecture)
185185
return SoliditylangRepository(platform_obj, self.session)
186186

187-
if repository_id == "crytic":
188-
return CryticRepository(self.session)
189-
190-
if repository_id == "alloy":
191-
return AlloyRepository(self.session)
187+
# Factory functions that only require session
188+
factories = {
189+
"crytic": CryticRepository,
190+
"alloy": AlloyRepository,
191+
}
192+
factory = factories.get(repository_id)
193+
if factory is not None:
194+
return factory(self.session)
192195

193196
raise ValueError(f"Unknown repository: {repository_id}")

0 commit comments

Comments
 (0)