Skip to content

Commit 52ae1ce

Browse files
author
Nat Chin
authored
Bump setup.py to v1 (#118)
* Bump `setup.py` to v1 * Update setup.py * Fix linting
1 parent aefa1e0 commit 52ae1ce

File tree

5 files changed

+45
-38
lines changed

5 files changed

+45
-38
lines changed

Diff for: .github/workflows/black.yml

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: Lint Code Base
23

34
defaults:
@@ -10,7 +11,7 @@ on:
1011
branches: [master, dev]
1112
schedule:
1213
# run CI every day even if no PRs/merges occur
13-
- cron: '0 12 * * *'
14+
- cron: '0 12 * * *'
1415

1516
jobs:
1617
build:
@@ -21,19 +22,18 @@ jobs:
2122
- name: Checkout Code
2223
uses: actions/checkout@v2
2324

24-
- name: Set up Python 3.6
25-
uses: actions/setup-python@v4
25+
- name: Set up Python 3.8
26+
uses: actions/setup-python@v3
2627
with:
27-
python-version: 3.6
28+
python-version: 3.8
2829

2930
- name: Install dependencies
3031
run: |
31-
pip install .
32-
pip install deepdiff numpy
3332
mkdir -p .github/linters
3433
cp pyproject.toml .github/linters
34+
3535
- name: Black
36-
uses: docker://github/super-linter:v3
36+
uses: github/super-linter/[email protected]
3737
if: always()
3838
env:
3939
# run linter on everything to catch preexisting problems
@@ -43,3 +43,4 @@ jobs:
4343
# Run only black
4444
VALIDATE_PYTHON_BLACK: true
4545
PYTHON_BLACK_CONFIG_FILE: pyproject.toml
46+
FILTER_REGEX_EXCLUDE: .*tests/.*.(json|zip|sol)

Diff for: .github/workflows/pylint.yml

+7-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
branches: [master, dev]
1212
schedule:
1313
# run CI every day even if no PRs/merges occur
14-
- cron: '0 12 * * *'
14+
- cron: '0 12 * * *'
1515

1616
jobs:
1717
build:
@@ -22,21 +22,18 @@ jobs:
2222
- name: Checkout Code
2323
uses: actions/checkout@v2
2424

25-
- name: Set up Python 3.6
26-
uses: actions/setup-python@v4
25+
- name: Set up Python 3.8
26+
uses: actions/setup-python@v3
2727
with:
28-
python-version: 3.6
28+
python-version: 3.8
2929

3030
- name: Install dependencies
3131
run: |
32-
pip install .
33-
pip install deepdiff numpy
34-
3532
mkdir -p .github/linters
3633
cp pyproject.toml .github/linters
3734
3835
- name: Pylint
39-
uses: docker://github/super-linter:v3
36+
uses: github/super-linter/[email protected]
4037
if: always()
4138
env:
4239
# run linter on everything to catch preexisting problems
@@ -46,4 +43,5 @@ jobs:
4643
# Run only pylint
4744
VALIDATE_PYTHON: true
4845
VALIDATE_PYTHON_PYLINT: true
49-
PYTHON_PYLINT_CONFIG_FILE: pyproject.toml
46+
PYTHON_PYLINT_CONFIG_FILE: pyproject.toml
47+
FILTER_REGEX_EXCLUDE: .*tests/.*.(json|zip|sol)

Diff for: setup.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
description="Manage multiple Solidity compiler versions.",
66
url="https://github.com/crytic/solc-select",
77
author="Trail of Bits",
8-
version="1.0.0.b1",
8+
version="1.0.0.0",
99
packages=find_packages(),
1010
python_requires=">=3.6",
1111
license="AGPL-3.0",
12+
# pylint: disable=consider-using-with
1213
long_description=open("README.md", encoding="utf8").read(),
1314
entry_points={
1415
"console_scripts": [
1516
"solc-select = solc_select.__main__:solc_select",
1617
"solc = solc_select.__main__:solc",
1718
]
1819
},
19-
install_requires=[
20-
'pysha3'
21-
]
20+
install_requires=["pysha3", "packaging"],
2221
)

Diff for: solc_select/__main__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
upgrade_architecture,
2121
)
2222

23-
23+
# pylint: disable=too-many-branches
2424
def solc_select() -> None:
2525
parser = argparse.ArgumentParser()
2626
subparsers = parser.add_subparsers(
@@ -33,7 +33,7 @@ def solc_select() -> None:
3333
INSTALL_VERSIONS,
3434
help='specific versions you want to install "0.4.25" or "all"',
3535
nargs="*",
36-
default=list(),
36+
default=[],
3737
type=valid_install_arg,
3838
)
3939
parser_use = subparsers.add_parser("use", help="change the version of global solc compiler")

Diff for: solc_select/solc_select.py

+25-16
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import argparse
22
import hashlib
3-
import sha3
43
import json
54
from zipfile import ZipFile
65
import os
76
import shutil
87
import re
98
import sys
109
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+
)
1321

1422
Path.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

94102
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")
98104

99105

100106
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")
104108

105109

106110
def 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

128132
def 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

155160
def 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

198205
def 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
204212
def 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

Comments
 (0)