Skip to content

Commit

Permalink
Merge pull request #2 from vyperlang/feat-version-cache
Browse files Browse the repository at this point in the history
Cache version data
  • Loading branch information
iamdefinitelyahuman authored Oct 7, 2020
2 parents eec1454 + 4ecd7e2 commit 7a71979
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions vvm/wrapper.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import subprocess
from pathlib import Path
from typing import Any, List, Tuple, Union
from typing import Any, Dict, List, Tuple, Union

from semantic_version import Version

from vvm import install
from vvm.exceptions import UnknownOption, UnknownValue, VyperError
from vvm.utils.convert import to_vyper_version

_version_cache: Dict[str, Version] = {}


def _get_vyper_version(vyper_binary: Union[Path, str]) -> Version:
# private wrapper function to get `vyper` version
stdout_data = subprocess.check_output([vyper_binary, "--version"], encoding="utf8")
version_str = stdout_data.split("+")[0]
return to_vyper_version(version_str)
cache_key = str(vyper_binary)

if cache_key not in _version_cache:
# cache the version info, because vyper binaries can be slow to load
stdout_data = subprocess.check_output([vyper_binary, "--version"], encoding="utf8")
version_str = stdout_data.split("+")[0]
_version_cache[cache_key] = to_vyper_version(version_str)

return _version_cache[cache_key]


def _to_string(key: str, value: Any) -> str:
Expand Down

0 comments on commit 7a71979

Please sign in to comment.