diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index b0de82f..b805c4d 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -1,3 +1,4 @@ +--- name: Lint Code Base defaults: @@ -10,7 +11,7 @@ on: branches: [master, dev] schedule: # run CI every day even if no PRs/merges occur - - cron: '0 12 * * *' + - cron: '0 12 * * *' jobs: build: @@ -21,19 +22,18 @@ jobs: - name: Checkout Code uses: actions/checkout@v2 - - name: Set up Python 3.6 - uses: actions/setup-python@v4 + - name: Set up Python 3.8 + uses: actions/setup-python@v3 with: - python-version: 3.6 + python-version: 3.8 - name: Install dependencies run: | - pip install . - pip install deepdiff numpy mkdir -p .github/linters cp pyproject.toml .github/linters + - name: Black - uses: docker://github/super-linter:v3 + uses: github/super-linter/slim@v4.9.2 if: always() env: # run linter on everything to catch preexisting problems @@ -43,3 +43,4 @@ jobs: # Run only black VALIDATE_PYTHON_BLACK: true PYTHON_BLACK_CONFIG_FILE: pyproject.toml + FILTER_REGEX_EXCLUDE: .*tests/.*.(json|zip|sol) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index dc3a32d..04334a2 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -11,7 +11,7 @@ on: branches: [master, dev] schedule: # run CI every day even if no PRs/merges occur - - cron: '0 12 * * *' + - cron: '0 12 * * *' jobs: build: @@ -22,21 +22,18 @@ jobs: - name: Checkout Code uses: actions/checkout@v2 - - name: Set up Python 3.6 - uses: actions/setup-python@v4 + - name: Set up Python 3.8 + uses: actions/setup-python@v3 with: - python-version: 3.6 + python-version: 3.8 - name: Install dependencies run: | - pip install . - pip install deepdiff numpy - mkdir -p .github/linters cp pyproject.toml .github/linters - name: Pylint - uses: docker://github/super-linter:v3 + uses: github/super-linter/slim@v4.9.2 if: always() env: # run linter on everything to catch preexisting problems @@ -46,4 +43,5 @@ jobs: # Run only pylint VALIDATE_PYTHON: true VALIDATE_PYTHON_PYLINT: true - PYTHON_PYLINT_CONFIG_FILE: pyproject.toml \ No newline at end of file + PYTHON_PYLINT_CONFIG_FILE: pyproject.toml + FILTER_REGEX_EXCLUDE: .*tests/.*.(json|zip|sol) diff --git a/setup.py b/setup.py index 23c485d..b13bf19 100644 --- a/setup.py +++ b/setup.py @@ -5,10 +5,11 @@ description="Manage multiple Solidity compiler versions.", url="https://github.com/crytic/solc-select", author="Trail of Bits", - version="1.0.0.b1", + version="1.0.0.0", packages=find_packages(), python_requires=">=3.6", license="AGPL-3.0", + # pylint: disable=consider-using-with long_description=open("README.md", encoding="utf8").read(), entry_points={ "console_scripts": [ @@ -16,7 +17,5 @@ "solc = solc_select.__main__:solc", ] }, - install_requires=[ - 'pysha3' - ] + install_requires=["pysha3", "packaging"], ) diff --git a/solc_select/__main__.py b/solc_select/__main__.py index cc0bd80..c589917 100644 --- a/solc_select/__main__.py +++ b/solc_select/__main__.py @@ -20,7 +20,7 @@ upgrade_architecture, ) - +# pylint: disable=too-many-branches def solc_select() -> None: parser = argparse.ArgumentParser() subparsers = parser.add_subparsers( @@ -33,7 +33,7 @@ def solc_select() -> None: INSTALL_VERSIONS, help='specific versions you want to install "0.4.25" or "all"', nargs="*", - default=list(), + default=[], type=valid_install_arg, ) parser_use = subparsers.add_parser("use", help="change the version of global solc compiler") diff --git a/solc_select/solc_select.py b/solc_select/solc_select.py index 4cb0eb9..936e64e 100644 --- a/solc_select/solc_select.py +++ b/solc_select/solc_select.py @@ -1,6 +1,5 @@ import argparse import hashlib -import sha3 import json from zipfile import ZipFile import os @@ -8,8 +7,17 @@ import re import sys import urllib.request -from distutils.version import StrictVersion -from .constants import * +from pathlib import Path +from packaging.version import Version +import sha3 +from .constants import ( + LINUX_AMD64, + MACOSX_AMD64, + WINDOWS_AMD64, + EARLIEST_RELEASE, + SOLC_SELECT_DIR, + ARTIFACTS_DIR, +) Path.mkdir(ARTIFACTS_DIR, parents=True, exist_ok=True) @@ -46,7 +54,7 @@ def current_version() -> (str, str): else: source = SOLC_SELECT_DIR.joinpath("global-version") if Path.is_file(source): - with open(source) as f: + with open(source, encoding="utf-8") as f: version = f.read() else: raise argparse.ArgumentTypeError( @@ -92,15 +100,11 @@ def install_artifacts(versions: [str]) -> bool: def is_older_linux(version: str) -> bool: - return soliditylang_platform() == LINUX_AMD64 and StrictVersion(version) <= StrictVersion( - "0.4.10" - ) + return soliditylang_platform() == LINUX_AMD64 and Version(version) <= Version("0.4.10") def is_older_windows(version: str) -> bool: - return soliditylang_platform() == WINDOWS_AMD64 and StrictVersion(version) <= StrictVersion( - "0.7.1" - ) + return soliditylang_platform() == WINDOWS_AMD64 and Version(version) <= Version("0.7.1") def verify_checksum(version: str) -> None: @@ -118,7 +122,7 @@ def verify_checksum(version: str) -> None: local_sha256_file_hash = f"0x{sha256_factory.hexdigest()}" local_keccak256_file_hash = f"0x{keccak_factory.hexdigest()}" - + if sha256_hash != local_sha256_file_hash or keccak256_hash != local_keccak256_file_hash: raise argparse.ArgumentTypeError( f"Error: Checksum mismatch {soliditylang_platform()} - {version}" @@ -127,6 +131,7 @@ def verify_checksum(version: str) -> None: def get_soliditylang_checksums(version: str) -> (str, str): (_, list_url) = get_url(version=version) + # pylint: disable=consider-using-with list_json = urllib.request.urlopen(list_url).read() builds = json.loads(list_json)["builds"] matches = list(filter(lambda b: b["version"] == version, builds)) @@ -154,7 +159,7 @@ def get_url(version: str = "", artifact: str = "") -> (str, str): def switch_global_version(version: str, always_install: bool) -> None: if version in installed_versions(): - with open(f"{SOLC_SELECT_DIR}/global-version", "w") as f: + with open(f"{SOLC_SELECT_DIR}/global-version", "w", encoding="utf-8") as f: f.write(version) print("Switched global version to", version) elif version in get_available_versions(): @@ -173,15 +178,17 @@ def valid_version(version: str) -> str: if match is None: raise argparse.ArgumentTypeError(f"Invalid version '{version}'.") - if StrictVersion(version) < StrictVersion(EARLIEST_RELEASE[soliditylang_platform()]): + if Version(version) < Version(EARLIEST_RELEASE[soliditylang_platform()]): raise argparse.ArgumentTypeError( f"Invalid version - only solc versions above '{EARLIEST_RELEASE[soliditylang_platform()]}' are available" ) + # pylint: disable=consider-using-with (_, list_url) = get_url() list_json = urllib.request.urlopen(list_url).read() latest_release = json.loads(list_json)["latestRelease"] - if StrictVersion(version) > StrictVersion(latest_release): + # pylint: disable=consider-using-with + if Version(version) > Version(latest_release): raise argparse.ArgumentTypeError( f"Invalid version '{latest_release}' is the latest available version" ) @@ -197,14 +204,16 @@ def valid_install_arg(arg: str) -> str: def get_installable_versions() -> [str]: installable = list(set(get_available_versions()) - set(installed_versions())) - installable.sort(key=StrictVersion) + installable.sort(key=Version) return installable +# pylint: disable=consider-using-with def get_available_versions() -> [str]: (_, list_url) = get_url() list_json = urllib.request.urlopen(list_url).read() available_releases = json.loads(list_json)["releases"] + # pylint: disable=consider-using-with if soliditylang_platform() == LINUX_AMD64: (_, list_url) = get_url(version=EARLIEST_RELEASE[LINUX_AMD64]) github_json = urllib.request.urlopen(list_url).read() @@ -219,7 +228,7 @@ def soliditylang_platform() -> str: platform = LINUX_AMD64 elif sys.platform == "darwin": platform = MACOSX_AMD64 - elif sys.platform == "win32" or sys.platform == "cygwin": + elif sys.platform in ["win32", "cygwin"]: platform = WINDOWS_AMD64 else: raise argparse.ArgumentTypeError("Unsupported platform")