ApeWorX / py-solc-x

Python wrapper and version management tool for the solc Solidity compiler.
https://solcx.readthedocs.io/
MIT License
138 stars 48 forks source link

Make py-solc-x select the lowest matching solc version #149

Open gsalzer opened 2 years ago

gsalzer commented 2 years ago

Overview

Currently, solc.install.install_solc_pragma(pragma_string) installs the newest available Solidity version that matches the given pragma. In some situations, it is preferable to use the lowest matching version instead. First, it is natural for programmers to put that solc version into the pragma that they are actually using, prefixing it with a ^. So selecting the lowest version will ensure that an authentic version is selected. There are cases where a later version of solc introduced breaking changes (while still in the same 0.x.* series), by changing a warning to an error. Second, some programmers mistakenly prefix the version by >= instead of ^, such that py-solc-x most certainly will select the wrong version.

Specification

Add a flag favor_earlier_version, default False, to methods like install_solc_pragma and hand it down to routines like get_installable_solc_versions (to sort versions in increasing order) and to _select_pragma_version (to influence the comparison of version and selected. This modification is backwards compatible.