Esempio n. 1
0
    def _init_solc_binary(version: str) -> str:
        """
        Only proper versions are supported. No nightlies, commits etc (such as available in remix).
        :param version: Version of the solc binary required
        :return: The solc binary of the corresponding version
        """

        if not version:
            return os.environ.get("SOLC") or "solc"

        # tried converting input to semver, seemed not necessary so just slicing for now
        main_version = solc.main.get_solc_version_string()
        main_version_number = re.match(r"\d+.\d+.\d+", main_version)
        if main_version is None:
            raise CriticalError(
                "Could not extract solc version from string {}".format(
                    main_version))
        if version == main_version_number:
            log.info("Given version matches installed version")
            solc_binary = os.environ.get("SOLC") or "solc"
        else:
            solc_binary = util.solc_exists(version)
            if solc_binary and solc_binary != util.solc_exists(
                    "default_ubuntu_version"):
                log.info("Given version is already installed")
            else:
                if version.startswith("0.4"):
                    try:
                        solc.install_solc("v" + version)
                    except solc.exceptions.SolcError:
                        raise CriticalError(
                            "There was an error when trying to install the specified solc version"
                        )
                elif sys.version_info[1] >= 6:
                    # solcx supports python 3.6+
                    try:
                        solcx.install_solc("v" + version)
                    except solcx.exceptions.SolcError:
                        raise CriticalError(
                            "There was an error when trying to install the specified solc version"
                        )
                else:
                    raise CriticalError(
                        "Py-Solc doesn't support 0.5.*. You can switch to python 3.6 which uses solcx."
                    )

                solc_binary = util.solc_exists(version)
                if not solc_binary:
                    raise solc.exceptions.SolcError()

            log.info("Setting the compiler to %s", solc_binary)

        return solc_binary
Esempio n. 2
0
    def _init_solc_binary(version):
        # Figure out solc binary and version
        # Only proper versions are supported. No nightlies, commits etc (such as available in remix)

        if not version:
            return os.environ.get("SOLC") or "solc"

        # tried converting input to semver, seemed not necessary so just slicing for now
        main_version = solc.main.get_solc_version_string()
        main_version_number = re.match(r"\d+.\d+.\d+", main_version)
        if main_version is None:
            raise CriticalError(
                "Could not extract solc version from string {}".format(
                    main_version))
        if version == main_version_number:
            logging.info("Given version matches installed version")
            solc_binary = os.environ.get("SOLC") or "solc"
        else:
            solc_binary = util.solc_exists(version)
            if solc_binary:
                logging.info("Given version is already installed")
            else:
                try:
                    solc.install_solc("v" + version)
                except SolcError:
                    raise CriticalError(
                        "There was an error when trying to install the specified solc version"
                    )

            logging.info("Setting the compiler to %s", solc_binary)

        return solc_binary