11import argparse
22import hashlib
3- import sha3
43import json
54from zipfile import ZipFile
65import os
76import shutil
87import re
98import sys
109import urllib .request
11- from distutils .version import StrictVersion
12- from .constants import *
10+ from pathlib import Path
11+ from packaging .version import Version
12+ import sha3
13+ from .constants import (
14+ LINUX_AMD64 ,
15+ MACOSX_AMD64 ,
16+ WINDOWS_AMD64 ,
17+ EARLIEST_RELEASE ,
18+ SOLC_SELECT_DIR ,
19+ ARTIFACTS_DIR ,
20+ )
1321
1422Path .mkdir (ARTIFACTS_DIR , parents = True , exist_ok = True )
1523
@@ -46,7 +54,7 @@ def current_version() -> (str, str):
4654 else :
4755 source = SOLC_SELECT_DIR .joinpath ("global-version" )
4856 if Path .is_file (source ):
49- with open (source ) as f :
57+ with open (source , encoding = "utf-8" ) as f :
5058 version = f .read ()
5159 else :
5260 raise argparse .ArgumentTypeError (
@@ -92,15 +100,11 @@ def install_artifacts(versions: [str]) -> bool:
92100
93101
94102def is_older_linux (version : str ) -> bool :
95- return soliditylang_platform () == LINUX_AMD64 and StrictVersion (version ) <= StrictVersion (
96- "0.4.10"
97- )
103+ return soliditylang_platform () == LINUX_AMD64 and Version (version ) <= Version ("0.4.10" )
98104
99105
100106def is_older_windows (version : str ) -> bool :
101- return soliditylang_platform () == WINDOWS_AMD64 and StrictVersion (version ) <= StrictVersion (
102- "0.7.1"
103- )
107+ return soliditylang_platform () == WINDOWS_AMD64 and Version (version ) <= Version ("0.7.1" )
104108
105109
106110def verify_checksum (version : str ) -> None :
@@ -118,7 +122,7 @@ def verify_checksum(version: str) -> None:
118122
119123 local_sha256_file_hash = f"0x{ sha256_factory .hexdigest ()} "
120124 local_keccak256_file_hash = f"0x{ keccak_factory .hexdigest ()} "
121-
125+
122126 if sha256_hash != local_sha256_file_hash or keccak256_hash != local_keccak256_file_hash :
123127 raise argparse .ArgumentTypeError (
124128 f"Error: Checksum mismatch { soliditylang_platform ()} - { version } "
@@ -127,6 +131,7 @@ def verify_checksum(version: str) -> None:
127131
128132def get_soliditylang_checksums (version : str ) -> (str , str ):
129133 (_ , list_url ) = get_url (version = version )
134+ # pylint: disable=consider-using-with
130135 list_json = urllib .request .urlopen (list_url ).read ()
131136 builds = json .loads (list_json )["builds" ]
132137 matches = list (filter (lambda b : b ["version" ] == version , builds ))
@@ -154,7 +159,7 @@ def get_url(version: str = "", artifact: str = "") -> (str, str):
154159
155160def switch_global_version (version : str , always_install : bool ) -> None :
156161 if version in installed_versions ():
157- with open (f"{ SOLC_SELECT_DIR } /global-version" , "w" ) as f :
162+ with open (f"{ SOLC_SELECT_DIR } /global-version" , "w" , encoding = "utf-8" ) as f :
158163 f .write (version )
159164 print ("Switched global version to" , version )
160165 elif version in get_available_versions ():
@@ -173,15 +178,17 @@ def valid_version(version: str) -> str:
173178 if match is None :
174179 raise argparse .ArgumentTypeError (f"Invalid version '{ version } '." )
175180
176- if StrictVersion (version ) < StrictVersion (EARLIEST_RELEASE [soliditylang_platform ()]):
181+ if Version (version ) < Version (EARLIEST_RELEASE [soliditylang_platform ()]):
177182 raise argparse .ArgumentTypeError (
178183 f"Invalid version - only solc versions above '{ EARLIEST_RELEASE [soliditylang_platform ()]} ' are available"
179184 )
180185
186+ # pylint: disable=consider-using-with
181187 (_ , list_url ) = get_url ()
182188 list_json = urllib .request .urlopen (list_url ).read ()
183189 latest_release = json .loads (list_json )["latestRelease" ]
184- if StrictVersion (version ) > StrictVersion (latest_release ):
190+ # pylint: disable=consider-using-with
191+ if Version (version ) > Version (latest_release ):
185192 raise argparse .ArgumentTypeError (
186193 f"Invalid version '{ latest_release } ' is the latest available version"
187194 )
@@ -197,14 +204,16 @@ def valid_install_arg(arg: str) -> str:
197204
198205def get_installable_versions () -> [str ]:
199206 installable = list (set (get_available_versions ()) - set (installed_versions ()))
200- installable .sort (key = StrictVersion )
207+ installable .sort (key = Version )
201208 return installable
202209
203210
211+ # pylint: disable=consider-using-with
204212def get_available_versions () -> [str ]:
205213 (_ , list_url ) = get_url ()
206214 list_json = urllib .request .urlopen (list_url ).read ()
207215 available_releases = json .loads (list_json )["releases" ]
216+ # pylint: disable=consider-using-with
208217 if soliditylang_platform () == LINUX_AMD64 :
209218 (_ , list_url ) = get_url (version = EARLIEST_RELEASE [LINUX_AMD64 ])
210219 github_json = urllib .request .urlopen (list_url ).read ()
@@ -219,7 +228,7 @@ def soliditylang_platform() -> str:
219228 platform = LINUX_AMD64
220229 elif sys .platform == "darwin" :
221230 platform = MACOSX_AMD64
222- elif sys .platform == "win32" or sys . platform == "cygwin" :
231+ elif sys .platform in [ "win32" , "cygwin" ] :
223232 platform = WINDOWS_AMD64
224233 else :
225234 raise argparse .ArgumentTypeError ("Unsupported platform" )
0 commit comments