cacheprovider: type annotations
This commit is contained in:
parent
a2f021b6f3
commit
087b047426
|
@ -80,7 +80,7 @@ class Cache:
|
||||||
rm_rf(d)
|
rm_rf(d)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cache_dir_from_config(config: Config):
|
def cache_dir_from_config(config: Config) -> Path:
|
||||||
return resolve_from_str(config.getini("cache_dir"), config.rootdir)
|
return resolve_from_str(config.getini("cache_dir"), config.rootdir)
|
||||||
|
|
||||||
def warn(self, fmt: str, **args: object) -> None:
|
def warn(self, fmt: str, **args: object) -> None:
|
||||||
|
@ -113,7 +113,7 @@ class Cache:
|
||||||
def _getvaluepath(self, key: str) -> Path:
|
def _getvaluepath(self, key: str) -> Path:
|
||||||
return self._cachedir.joinpath(self._CACHE_PREFIX_VALUES, Path(key))
|
return self._cachedir.joinpath(self._CACHE_PREFIX_VALUES, Path(key))
|
||||||
|
|
||||||
def get(self, key, default):
|
def get(self, key: str, default):
|
||||||
""" return cached value for the given key. If no value
|
""" return cached value for the given key. If no value
|
||||||
was yet cached or the value cannot be read, the specified
|
was yet cached or the value cannot be read, the specified
|
||||||
default is returned.
|
default is returned.
|
||||||
|
@ -131,7 +131,7 @@ class Cache:
|
||||||
except (ValueError, OSError):
|
except (ValueError, OSError):
|
||||||
return default
|
return default
|
||||||
|
|
||||||
def set(self, key, value) -> None:
|
def set(self, key: str, value: object) -> None:
|
||||||
""" save value for the given key.
|
""" save value for the given key.
|
||||||
|
|
||||||
:param key: must be a ``/`` separated value. Usually the first
|
:param key: must be a ``/`` separated value. Usually the first
|
||||||
|
@ -522,7 +522,7 @@ def cacheshow(config: Config, session: Session) -> int:
|
||||||
vdir = basedir / Cache._CACHE_PREFIX_VALUES
|
vdir = basedir / Cache._CACHE_PREFIX_VALUES
|
||||||
tw.sep("-", "cache values for %r" % glob)
|
tw.sep("-", "cache values for %r" % glob)
|
||||||
for valpath in sorted(x for x in vdir.rglob(glob) if x.is_file()):
|
for valpath in sorted(x for x in vdir.rglob(glob) if x.is_file()):
|
||||||
key = valpath.relative_to(vdir)
|
key = str(valpath.relative_to(vdir))
|
||||||
val = config.cache.get(key, dummy)
|
val = config.cache.get(key, dummy)
|
||||||
if val is dummy:
|
if val is dummy:
|
||||||
tw.line("%s contains unreadable content, will be ignored" % key)
|
tw.line("%s contains unreadable content, will be ignored" % key)
|
||||||
|
@ -539,6 +539,6 @@ def cacheshow(config: Config, session: Session) -> int:
|
||||||
# if p.check(dir=1):
|
# if p.check(dir=1):
|
||||||
# print("%s/" % p.relto(basedir))
|
# print("%s/" % p.relto(basedir))
|
||||||
if p.is_file():
|
if p.is_file():
|
||||||
key = p.relative_to(basedir)
|
key = str(p.relative_to(basedir))
|
||||||
tw.line("{} is a file of length {:d}".format(key, p.stat().st_size))
|
tw.line("{} is a file of length {:d}".format(key, p.stat().st_size))
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -363,15 +363,15 @@ def make_numbered_dir_with_cleanup(
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def resolve_from_str(input: str, root):
|
def resolve_from_str(input: str, root: py.path.local) -> Path:
|
||||||
assert not isinstance(input, Path), "would break on py2"
|
assert not isinstance(input, Path), "would break on py2"
|
||||||
root = Path(root)
|
rootpath = Path(root)
|
||||||
input = expanduser(input)
|
input = expanduser(input)
|
||||||
input = expandvars(input)
|
input = expandvars(input)
|
||||||
if isabs(input):
|
if isabs(input):
|
||||||
return Path(input)
|
return Path(input)
|
||||||
else:
|
else:
|
||||||
return root.joinpath(input)
|
return rootpath.joinpath(input)
|
||||||
|
|
||||||
|
|
||||||
def fnmatch_ex(pattern: str, path) -> bool:
|
def fnmatch_ex(pattern: str, path) -> bool:
|
||||||
|
|
Loading…
Reference in New Issue