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
83import os
94import 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
0 commit comments