Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make select_pragma_version public [APE-1530] #162

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
hooks:
- id: check-yaml
- repo: https://github.com/psf/black
rev: 23.10.1
rev: 23.11.0
hooks:
- id: black
name: fmt
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"hypothesis>=6.2.0,<7.0", # Strategy-based fuzzer
],
"lint": [
"black>=23.10.1,<24", # auto-formatter and linter
"black>=23.11.0,<24", # auto-formatter and linter
"mypy>=1.6.1,<2", # Static type analyzer
"types-setuptools", # Needed due to mypy typeshed
"types-requests", # Needed due to mypy typeshed
Expand Down
17 changes: 14 additions & 3 deletions solcx/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,18 @@ def set_solc_version(
LOGGER.info(f"Using solc version {version}")


def _select_pragma_version(pragma_string: str, version_list: List[Version]) -> Optional[Version]:
def select_pragma_version(pragma_string: str, version_list: List[Version]) -> Optional[Version]:
"""
Get a matching version from the given pragma string and a version list.

Args:
pragma_string (str): A pragma str.
version_list (List[Version]): A list of valid versions.

Returns:
Optional[Version]: A selected version from the given list.
"""

comparator_set_range = pragma_string.replace(" ", "").split("||")
comparator_regex = re.compile(r"(([<>]?=?|\^)\d+\.\d+\.\d+)")
version = None
Expand Down Expand Up @@ -276,7 +287,7 @@ def set_solc_version_pragma(
Version: The new active `solc` version.
"""
installed_versions = get_installed_solc_versions()
if not (version := _select_pragma_version(pragma_string, installed_versions)):
if not (version := select_pragma_version(pragma_string, installed_versions)):
raise SolcNotInstalled(
f"No compatible solc version installed."
f" Use solcx.install_solc_version_pragma('{pragma_string}') to install."
Expand Down Expand Up @@ -316,7 +327,7 @@ def install_solc_pragma(
"""

installed_versions = get_installable_solc_versions()
if version := _select_pragma_version(pragma_string, installed_versions):
if version := select_pragma_version(pragma_string, installed_versions):
install_solc(version, show_progress=show_progress, solcx_binary_path=solcx_binary_path)
else:
raise UnsupportedVersionError(
Expand Down
Empty file added solcx/py.typed
Empty file.
5 changes: 0 additions & 5 deletions solcx/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
VERSION_REGEX = r"(\d+\.\d+\.\d+)(?:-nightly.\d+.\d+.\d+|)(\+commit.\w+)"


def _get_solc_version(solc_binary: Union[Path, str], with_commit_hash: bool = False) -> Version:
# TODO: Remove around 1.2.0. Was private, kept to prevent accidentally breaking downstream.
return get_solc_version(solc_binary, with_commit_hash=with_commit_hash)


def get_version_str_from_solc_binary(solc_binary: Union[Path, str]) -> str:
stdout_data = subprocess.check_output([str(solc_binary), "--version"], encoding="utf8")
if not (match := next(re.finditer(VERSION_REGEX, stdout_data), None)):
Expand Down