1
1
import argparse
2
2
import hashlib
3
- import sha3
4
3
import json
5
4
from zipfile import ZipFile
6
5
import os
7
6
import shutil
8
7
import re
9
8
import sys
10
9
import 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
+ )
13
21
14
22
Path .mkdir (ARTIFACTS_DIR , parents = True , exist_ok = True )
15
23
@@ -46,7 +54,7 @@ def current_version() -> (str, str):
46
54
else :
47
55
source = SOLC_SELECT_DIR .joinpath ("global-version" )
48
56
if Path .is_file (source ):
49
- with open (source ) as f :
57
+ with open (source , encoding = "utf-8" ) as f :
50
58
version = f .read ()
51
59
else :
52
60
raise argparse .ArgumentTypeError (
@@ -92,15 +100,11 @@ def install_artifacts(versions: [str]) -> bool:
92
100
93
101
94
102
def 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" )
98
104
99
105
100
106
def 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" )
104
108
105
109
106
110
def verify_checksum (version : str ) -> None :
@@ -118,7 +122,7 @@ def verify_checksum(version: str) -> None:
118
122
119
123
local_sha256_file_hash = f"0x{ sha256_factory .hexdigest ()} "
120
124
local_keccak256_file_hash = f"0x{ keccak_factory .hexdigest ()} "
121
-
125
+
122
126
if sha256_hash != local_sha256_file_hash or keccak256_hash != local_keccak256_file_hash :
123
127
raise argparse .ArgumentTypeError (
124
128
f"Error: Checksum mismatch { soliditylang_platform ()} - { version } "
@@ -127,6 +131,7 @@ def verify_checksum(version: str) -> None:
127
131
128
132
def get_soliditylang_checksums (version : str ) -> (str , str ):
129
133
(_ , list_url ) = get_url (version = version )
134
+ # pylint: disable=consider-using-with
130
135
list_json = urllib .request .urlopen (list_url ).read ()
131
136
builds = json .loads (list_json )["builds" ]
132
137
matches = list (filter (lambda b : b ["version" ] == version , builds ))
@@ -154,7 +159,7 @@ def get_url(version: str = "", artifact: str = "") -> (str, str):
154
159
155
160
def switch_global_version (version : str , always_install : bool ) -> None :
156
161
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 :
158
163
f .write (version )
159
164
print ("Switched global version to" , version )
160
165
elif version in get_available_versions ():
@@ -173,15 +178,17 @@ def valid_version(version: str) -> str:
173
178
if match is None :
174
179
raise argparse .ArgumentTypeError (f"Invalid version '{ version } '." )
175
180
176
- if StrictVersion (version ) < StrictVersion (EARLIEST_RELEASE [soliditylang_platform ()]):
181
+ if Version (version ) < Version (EARLIEST_RELEASE [soliditylang_platform ()]):
177
182
raise argparse .ArgumentTypeError (
178
183
f"Invalid version - only solc versions above '{ EARLIEST_RELEASE [soliditylang_platform ()]} ' are available"
179
184
)
180
185
186
+ # pylint: disable=consider-using-with
181
187
(_ , list_url ) = get_url ()
182
188
list_json = urllib .request .urlopen (list_url ).read ()
183
189
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 ):
185
192
raise argparse .ArgumentTypeError (
186
193
f"Invalid version '{ latest_release } ' is the latest available version"
187
194
)
@@ -197,14 +204,16 @@ def valid_install_arg(arg: str) -> str:
197
204
198
205
def get_installable_versions () -> [str ]:
199
206
installable = list (set (get_available_versions ()) - set (installed_versions ()))
200
- installable .sort (key = StrictVersion )
207
+ installable .sort (key = Version )
201
208
return installable
202
209
203
210
211
+ # pylint: disable=consider-using-with
204
212
def get_available_versions () -> [str ]:
205
213
(_ , list_url ) = get_url ()
206
214
list_json = urllib .request .urlopen (list_url ).read ()
207
215
available_releases = json .loads (list_json )["releases" ]
216
+ # pylint: disable=consider-using-with
208
217
if soliditylang_platform () == LINUX_AMD64 :
209
218
(_ , list_url ) = get_url (version = EARLIEST_RELEASE [LINUX_AMD64 ])
210
219
github_json = urllib .request .urlopen (list_url ).read ()
@@ -219,7 +228,7 @@ def soliditylang_platform() -> str:
219
228
platform = LINUX_AMD64
220
229
elif sys .platform == "darwin" :
221
230
platform = MACOSX_AMD64
222
- elif sys .platform == "win32" or sys . platform == "cygwin" :
231
+ elif sys .platform in [ "win32" , "cygwin" ] :
223
232
platform = WINDOWS_AMD64
224
233
else :
225
234
raise argparse .ArgumentTypeError ("Unsupported platform" )
0 commit comments