Skip to content

Commit 3792cb6

Browse files
committed
Further cleanup
1 parent 7bce7e2 commit 3792cb6

15 files changed

+98
-712
lines changed
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
"""
2-
Infrastructure layer for solc-select.
3-
4-
This package contains low-level infrastructure concerns like
5-
filesystem operations and HTTP client configuration.
6-
"""
1+
"""Infrastructure layer for solc-select."""
Lines changed: 14 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
"""
2-
Filesystem operations for solc-select.
3-
4-
This module handles file system operations including version storage,
5-
configuration management, and directory operations.
6-
"""
1+
"""Filesystem operations for solc-select."""
72

83
import os
94
import shutil
@@ -22,80 +17,47 @@ def __init__(self) -> None:
2217
self._ensure_directories()
2318

2419
def _ensure_directories(self) -> None:
25-
"""Ensure required directories exist."""
2620
self.artifacts_dir.mkdir(parents=True, exist_ok=True)
2721
self.config_dir.mkdir(parents=True, exist_ok=True)
2822

2923
def get_current_version(self) -> SolcVersion | None:
30-
"""Get the currently selected version.
31-
32-
Returns:
33-
Currently selected version or None if not set
34-
"""
35-
# Check environment variable first
24+
"""Get the currently selected version."""
3625
env_version = os.environ.get("SOLC_VERSION")
3726
if env_version:
3827
try:
3928
return SolcVersion.parse(env_version)
4029
except ValueError:
4130
return None
4231

43-
# Check global version file
4432
global_version_file = self.config_dir / "global-version"
4533
if global_version_file.exists():
4634
try:
4735
with open(global_version_file, encoding="utf-8") as f:
48-
version_str = f.read().strip()
49-
return SolcVersion.parse(version_str)
36+
return SolcVersion.parse(f.read().strip())
5037
except (OSError, ValueError):
5138
return None
5239

5340
return None
5441

5542
def set_global_version(self, version: SolcVersion) -> None:
56-
"""Set the global version.
57-
58-
Args:
59-
version: Version to set as global
60-
"""
43+
"""Set the global version."""
6144
global_version_file = self.config_dir / "global-version"
6245
with open(global_version_file, "w", encoding="utf-8") as f:
6346
f.write(str(version))
6447

6548
def get_version_source(self) -> str:
66-
"""Get the source of the current version setting.
67-
68-
Returns:
69-
Source description (environment variable or file path)
70-
"""
49+
"""Get the source of the current version setting."""
7150
if os.environ.get("SOLC_VERSION"):
7251
return "SOLC_VERSION"
73-
74-
global_version_file = self.config_dir / "global-version"
75-
return global_version_file.as_posix()
52+
return (self.config_dir / "global-version").as_posix()
7653

7754
def get_artifact_directory(self, version: SolcVersion) -> Path:
78-
"""Get the directory for a version's artifacts.
79-
80-
Args:
81-
version: Version to get directory for
82-
83-
Returns:
84-
Path to the artifact directory
85-
"""
55+
"""Get the directory for a version's artifacts."""
8656
return self.artifacts_dir / f"solc-{version}"
8757

8858
def get_binary_path(self, version: SolcVersion) -> Path:
89-
"""Get the path to a version's binary.
90-
91-
Args:
92-
version: Version to get binary path for
93-
94-
Returns:
95-
Path to the binary executable
96-
"""
97-
artifact_dir = self.get_artifact_directory(version)
98-
return artifact_dir / f"solc-{version}"
59+
"""Get the path to a version's binary."""
60+
return self.get_artifact_directory(version) / f"solc-{version}"
9961

10062
def cleanup_artifacts_directory(self) -> None:
10163
"""Remove the entire artifacts directory for upgrades."""
@@ -104,24 +66,12 @@ def cleanup_artifacts_directory(self) -> None:
10466
self.artifacts_dir.mkdir(parents=True, exist_ok=True)
10567

10668
def is_legacy_installation(self, version: SolcVersion) -> bool:
107-
"""Check if a version uses the old installation format.
108-
109-
Args:
110-
version: Version to check
111-
112-
Returns:
113-
True if using legacy format, False otherwise
114-
"""
115-
# Legacy format: artifacts/solc-{version} (file instead of directory)
69+
"""Check if a version uses the old installation format (file instead of directory)."""
11670
legacy_path = self.artifacts_dir / f"solc-{version}"
11771
return legacy_path.exists() and legacy_path.is_file()
11872

11973
def get_installed_versions(self) -> list[SolcVersion]:
120-
"""Get list of installed versions by scanning artifacts directory.
121-
122-
Returns:
123-
List of installed SolcVersion objects sorted by version
124-
"""
74+
"""Get list of installed versions sorted by version number."""
12575
if not self.artifacts_dir.exists():
12676
return []
12777

@@ -134,33 +84,17 @@ def get_installed_versions(self) -> list[SolcVersion]:
13484
if self.is_installed(version):
13585
installed.append(version)
13686
except ValueError:
137-
# Skip invalid version directories
13887
continue
13988

14089
installed.sort()
14190
return installed
14291

14392
def is_installed(self, version: SolcVersion) -> bool:
144-
"""Check if a version is installed.
145-
146-
Args:
147-
version: Version to check
148-
149-
Returns:
150-
True if installed and binary exists, False otherwise
151-
"""
152-
binary_path = self.get_binary_path(version)
153-
return binary_path.exists()
93+
"""Check if a version is installed."""
94+
return self.get_binary_path(version).exists()
15495

15596
def ensure_artifact_directory(self, version: SolcVersion) -> Path:
156-
"""Ensure artifact directory exists for a version.
157-
158-
Args:
159-
version: Version to create directory for
160-
161-
Returns:
162-
Path to the artifact directory
163-
"""
97+
"""Ensure artifact directory exists for a version."""
16498
artifact_dir = self.get_artifact_directory(version)
16599
artifact_dir.mkdir(parents=True, exist_ok=True)
166100
return artifact_dir

solc_select/models/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
"""
2-
Domain models for solc-select.
3-
4-
This package contains the core business entities and value objects organized by concern.
5-
"""
1+
"""Domain models for solc-select."""

solc_select/models/artifacts.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class SolcArtifactOnDisk:
1717
version: SolcVersion
1818
platform: Platform
1919
file_path: Path
20-
emulation: EmulationCapability | None = None # Emulation info if not native
20+
emulation: EmulationCapability | None = None
2121

2222

2323
@dataclass(kw_only=True)
@@ -29,16 +29,14 @@ class SolcArtifact(SolcArtifactOnDisk):
2929
checksum_keccak256: str | None
3030

3131
def __post_init__(self) -> None:
32-
"""Validate artifact properties."""
3332
if not self.download_url:
3433
raise ValueError("Download URL cannot be empty")
3534
if not self.checksum_sha256:
3635
raise ValueError("SHA256 checksum cannot be empty")
36+
# Normalize by removing 0x prefix
3737
if self.checksum_sha256.startswith("0x"):
38-
# Normalize by removing 0x prefix
3938
object.__setattr__(self, "checksum_sha256", self.checksum_sha256[2:])
4039
if self.checksum_keccak256 and self.checksum_keccak256.startswith("0x"):
41-
# Normalize by removing 0x prefix
4240
object.__setattr__(self, "checksum_keccak256", self.checksum_keccak256[2:])
4341

4442
@property

solc_select/models/platforms.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,29 @@ class Platform:
1616
architecture: str # 'amd64', 'arm64'
1717

1818
def __post_init__(self) -> None:
19-
"""Validate platform components."""
2019
valid_os = {"linux", "darwin", "windows"}
2120
valid_arch = {"amd64", "arm64"}
22-
2321
if self.os_type not in valid_os:
2422
raise ValueError(f"Invalid OS type: {self.os_type}")
2523
if self.architecture not in valid_arch:
2624
raise ValueError(f"Invalid architecture: {self.architecture}")
2725

2826
def get_capability(self) -> PlatformCapability:
29-
"""Get the capability declaration for this platform.
30-
31-
Returns:
32-
PlatformCapability for this platform (default if not registered)
33-
"""
34-
# Import at runtime to avoid circular dependency
27+
"""Get the capability declaration for this platform."""
3528
from ..platform_capabilities import CAPABILITY_REGISTRY
3629

3730
key = f"{self.os_type}-{self.architecture}"
3831
return CAPABILITY_REGISTRY.get(key, self._create_default_capability())
3932

4033
def _create_default_capability(self) -> PlatformCapability:
41-
"""Create default capability (native-only, no emulation).
42-
43-
Returns:
44-
PlatformCapability with only native support
45-
"""
34+
"""Create default capability (native-only, no emulation)."""
4635
platform_id = PlatformIdentifier(self.os_type, self.architecture)
4736
return PlatformCapability(
4837
host_platform=platform_id,
4938
native_support=platform_id,
5039
emulation_capabilities=[],
5140
)
5241

53-
# ========================================
54-
# CORE PLATFORM DETECTION
55-
# ========================================
56-
5742
@classmethod
5843
def current(cls) -> "Platform":
5944
"""Get the current system platform."""
@@ -66,7 +51,6 @@ def current(cls) -> "Platform":
6651
os_type = os_mapping.get(sys.platform)
6752
if os_type is None:
6853
raise ValueError(f"Unsupported platform: {sys.platform}")
69-
7054
return cls(os_type=os_type, architecture=cls._get_arch())
7155

7256
@staticmethod
@@ -83,7 +67,6 @@ def _get_arch() -> str:
8367

8468
def get_soliditylang_key(self) -> str:
8569
"""Get the platform key used by binaries.soliditylang.org."""
86-
# soliditylang.org uses macosx-amd64 for both Intel and ARM (with Rosetta and universal binaries)
8770
platform_keys = {
8871
("linux", "amd64"): LINUX_AMD64,
8972
("linux", "arm64"): LINUX_ARM64,

solc_select/models/repositories.py

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,25 @@
88

99
@dataclass(frozen=True)
1010
class PlatformSupport:
11-
"""Declares what versions a repository provides for a specific platform.
12-
13-
Example: Soliditylang provides linux-amd64 binaries from version 0.4.10+
14-
"""
11+
"""Declares what versions a repository provides for a specific platform."""
1512

1613
platform: PlatformIdentifier
1714
version_range: VersionRange
1815

1916
def supports(self, version: SolcVersion, target_platform: PlatformIdentifier) -> bool:
20-
"""Check if this support matches version + platform.
21-
22-
Args:
23-
version: Version to check
24-
target_platform: Platform to check
25-
26-
Returns:
27-
True if this support provides the version for the platform
28-
"""
17+
"""Check if this support matches version + platform."""
2918
return self.platform == target_platform and self.version_range.contains(version)
3019

3120

3221
@dataclass
3322
class RepositoryManifest:
34-
"""Declarative manifest of what a repository provides.
35-
36-
Example:
37-
SOLIDITYLANG_MANIFEST = RepositoryManifest(
38-
repository_id="soliditylang",
39-
base_url="https://binaries.soliditylang.org",
40-
platform_supports=[...],
41-
priority=100,
42-
)
43-
"""
23+
"""Declarative manifest of what a repository provides."""
4424

4525
repository_id: str # 'soliditylang', 'crytic', 'alloy'
4626
base_url: str
4727
platform_supports: list[PlatformSupport]
4828
priority: int = 50 # Higher = checked first (100=primary, 50=fallback, 10=legacy)
4929

5030
def supports_version(self, version: SolcVersion, platform: PlatformIdentifier) -> bool:
51-
"""Check if this repository can provide version for platform.
52-
53-
Args:
54-
version: Version to check
55-
platform: Platform to check
56-
57-
Returns:
58-
True if repository provides this version/platform combo
59-
"""
31+
"""Check if this repository can provide version for platform."""
6032
return any(ps.supports(version, platform) for ps in self.platform_supports)

0 commit comments

Comments
 (0)