From 40423a81973f359faa4256e45baff3b97be51461 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sun, 18 Dec 2022 21:18:47 -0800 Subject: [PATCH 1/4] Sort versions chronologically --- solc_select/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solc_select/__main__.py b/solc_select/__main__.py index d4496c7..c566a7a 100644 --- a/solc_select/__main__.py +++ b/solc_select/__main__.py @@ -52,7 +52,7 @@ def solc_select() -> None: versions = args.get(INSTALL_VERSIONS) if not versions: print("Available versions to install:") - for version in get_installable_versions(): + for version in sorted(get_installable_versions(), key=lambda v: [int(s) for s in v.split(".")]): print(version) else: install_artifacts(args.get(INSTALL_VERSIONS)) @@ -64,7 +64,7 @@ def solc_select() -> None: res = current_version() if res: (current_ver, source) = res - for version in reversed(sorted(installed_versions())): + for version in sorted(installed_versions(), key=lambda v: [int(s) for s in v.split(".")]): if res and version == current_ver: print(f"{version} (current, set by {source})") else: From 428c1a8d8144a4f244576f897fb6f64e58f0b7e6 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sun, 18 Dec 2022 21:23:54 -0800 Subject: [PATCH 2/4] Fix linting issues --- solc_select/__main__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/solc_select/__main__.py b/solc_select/__main__.py index c566a7a..2dd7ed8 100644 --- a/solc_select/__main__.py +++ b/solc_select/__main__.py @@ -52,7 +52,9 @@ def solc_select() -> None: versions = args.get(INSTALL_VERSIONS) if not versions: print("Available versions to install:") - for version in sorted(get_installable_versions(), key=lambda v: [int(s) for s in v.split(".")]): + for version in sorted( + get_installable_versions(), key=lambda v: [int(s) for s in v.split(".")] + ): print(version) else: install_artifacts(args.get(INSTALL_VERSIONS)) From 6ce0bf53345683ac9294c9987b20cc7cc3b76d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Mon, 30 Dec 2024 15:50:18 +0100 Subject: [PATCH 3/4] Extract sorting logic to its own function --- solc_select/__main__.py | 7 +++---- solc_select/utils.py | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/solc_select/__main__.py b/solc_select/__main__.py index cb98812..e6b9ebe 100644 --- a/solc_select/__main__.py +++ b/solc_select/__main__.py @@ -20,6 +20,7 @@ halt_old_architecture, upgrade_architecture, ) +from .utils import sort_versions # pylint: disable=too-many-branches @@ -54,9 +55,7 @@ def solc_select() -> None: versions = args.get(INSTALL_VERSIONS) if not versions: print("Available versions to install:") - for version in sorted( - get_installable_versions(), key=lambda v: [int(s) for s in v.split(".")] - ): + for version in sort_versions(get_installable_versions()): print(version) else: install_artifacts(args.get(INSTALL_VERSIONS)) @@ -70,7 +69,7 @@ def solc_select() -> None: res = current_version() if res: (current_ver, source) = res - for version in sorted(versions_installed, key=lambda v: [int(s) for s in v.split(".")]): + for version in sort_versions(versions_installed): if res and version == current_ver: print(f"{version} (current, set by {source})") else: diff --git a/solc_select/utils.py b/solc_select/utils.py index f6312bf..db8ceea 100644 --- a/solc_select/utils.py +++ b/solc_select/utils.py @@ -1,6 +1,7 @@ import platform import subprocess import sys +from typing import List def mac_can_run_intel_binaries() -> bool: @@ -13,3 +14,8 @@ def mac_can_run_intel_binaries() -> bool: # Intel Mac return True + + +def sort_versions(versions: List[str]) -> List[str]: + """Sorts a list of versions following the component order (major/minor/patch)""" + return sorted(versions, key=lambda v: [int(s) for s in v.split(".")]) From bc587e8bf0a896bc3275194266fd9ad35293e9e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Tue, 31 Dec 2024 16:08:28 +0100 Subject: [PATCH 4/4] Remove redundant sort, unify criteria `get_installable_versions()` is already sorted using `Version` --- solc_select/__main__.py | 2 +- solc_select/utils.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/solc_select/__main__.py b/solc_select/__main__.py index e6b9ebe..6193015 100644 --- a/solc_select/__main__.py +++ b/solc_select/__main__.py @@ -55,7 +55,7 @@ def solc_select() -> None: versions = args.get(INSTALL_VERSIONS) if not versions: print("Available versions to install:") - for version in sort_versions(get_installable_versions()): + for version in get_installable_versions(): print(version) else: install_artifacts(args.get(INSTALL_VERSIONS)) diff --git a/solc_select/utils.py b/solc_select/utils.py index db8ceea..98b7305 100644 --- a/solc_select/utils.py +++ b/solc_select/utils.py @@ -3,6 +3,8 @@ import sys from typing import List +from packaging.version import Version + def mac_can_run_intel_binaries() -> bool: """Check if the Mac is Intel or M1 with available Rosetta. Will throw an exception if run on non-macOS.""" @@ -18,4 +20,4 @@ def mac_can_run_intel_binaries() -> bool: def sort_versions(versions: List[str]) -> List[str]: """Sorts a list of versions following the component order (major/minor/patch)""" - return sorted(versions, key=lambda v: [int(s) for s in v.split(".")]) + return sorted(versions, key=Version)