def _find_vyper_version(file: str) -> str: global _installed_vyper_versions if _installed_vyper_versions is None: _installed_vyper_versions = vvm.get_installed_vyper_versions() _installed_vyper_versions.append(_VYPER_VERSION) pragma_specs = _get_vyper_pragma_spec(file) version = pragma_specs.select(_installed_vyper_versions) if not version: global _available_vyper_versions if _available_vyper_versions is None: _available_vyper_versions = vvm.get_installable_vyper_versions() version = pragma_specs.select(_available_vyper_versions) if not version: raise InvalidVyperException( f"Invalid vyper version pragma: {pragma_specs}") lock = vvm.install.get_process_lock(f"locked${version}") with lock: try: _get_executable(version) except vvm.exceptions.VyperNotInstalled: vvm.install_vyper(version) if version not in _installed_vyper_versions: _installed_vyper_versions.append(version) return version
def _get_vyper_version_list() -> Tuple[List, List]: global AVAILABLE_VYPER_VERSIONS installed_versions = vvm.get_installed_vyper_versions() if AVAILABLE_VYPER_VERSIONS is None: try: AVAILABLE_VYPER_VERSIONS = vvm.get_installable_vyper_versions() except ConnectionError: if not installed_versions: raise ConnectionError( "Vyper not installed and cannot connect to GitHub") AVAILABLE_VYPER_VERSIONS = installed_versions return AVAILABLE_VYPER_VERSIONS, installed_versions
def pytest_collection(session): global VERSIONS if session.config.getoption("--vyper-versions"): VERSIONS = [ Version(i) for i in session.config.getoption("--vyper-versions").split(",") ] elif session.config.getoption("--no-install"): VERSIONS = vvm.get_installed_vyper_versions() else: try: VERSIONS = vvm.get_installable_vyper_versions() except ConnectionError: raise pytest.UsageError( "ConnectionError while attempting to get vyper versions.\n" "Use the --no-install flag to only run tests against already installed versions." ) for version in VERSIONS: vvm.install_vyper(version)
def find_vyper_versions( contract_sources: Dict[str, str], install_needed: bool = False, install_latest: bool = False, silent: bool = True, ) -> Dict: """ Analyzes contract pragmas and determines which vyper version(s) to use. Args: contract_sources: a dictionary in the form of {'path': "source code"} install_needed: if True, will install when no installed version matches the contract pragma install_latest: if True, will install when a newer version is available than the installed one silent: set to False to enable verbose reporting Returns: dictionary of {'version': ['path', 'path', ..]} """ available_versions, installed_versions = _get_vyper_version_list() pragma_specs: Dict = {} to_install = set() new_versions = set() for path, source in contract_sources.items(): pragma_specs[path] = sources.get_vyper_pragma_spec(source, path) version = pragma_specs[path].select(installed_versions) if not version and not (install_needed or install_latest): raise IncompatibleVyperVersion( f"No installed vyper version matching '{pragma_specs[path]}' in '{path}'" ) # if no installed version of vyper matches the pragma, find the latest available version latest = pragma_specs[path].select(available_versions) if not version and not latest: raise IncompatibleVyperVersion( f"No installable vyper version matching '{pragma_specs[path]}' in '{path}'" ) if not version or (install_latest and latest > version): to_install.add(latest) elif latest and latest > version: new_versions.add(str(version)) # install new versions if needed if to_install: install_vyper(*to_install) installed_versions = vvm.get_installed_vyper_versions() elif new_versions and not silent: print( f"New compatible vyper version{'s' if len(new_versions) > 1 else ''}" f" available: {', '.join(new_versions)}" ) # organize source paths by latest available vyper version compiler_versions: Dict = {} for path, spec in pragma_specs.items(): version = spec.select(installed_versions) compiler_versions.setdefault(str(version), []).append(path) return compiler_versions
def installed_versions(self) -> List[Version]: # doing this so it prefers package version - try debugging here package_version = self.package_version package_version = [package_version] if package_version else [] # currently package version is [] this should be ok return package_version + vvm.get_installed_vyper_versions()