Fmt.
This commit is contained in:
parent
196c0fc9a5
commit
9937bee71d
1 changed files with 42 additions and 16 deletions
|
@ -19,7 +19,12 @@ def tempf(global_config, name):
|
|||
root = Path(global_config["cram"]["root"])
|
||||
assert root.exists() and root.is_dir()
|
||||
|
||||
cache_dir = global_config.get("cram", {}).get("task", {}).get("default", {}).get("cache_dir")
|
||||
cache_dir = (
|
||||
global_config.get("cram", {})
|
||||
.get("task", {})
|
||||
.get("default", {})
|
||||
.get("cache_dir")
|
||||
)
|
||||
cache_root = cache_dir and Path(expandvars(cache_dir)) or root / ".cache"
|
||||
|
||||
return cache_root / name[0:2] / name
|
||||
|
@ -38,7 +43,9 @@ class PackageV1(Package):
|
|||
return self._config
|
||||
|
||||
def test(self):
|
||||
return (self.root / self.SPECIAL_FILES[0]).exists() and self.config().get("cram", {}).get("version") == 1
|
||||
return (self.root / self.SPECIAL_FILES[0]).exists() and self.config().get(
|
||||
"cram", {}
|
||||
).get("version") == 1
|
||||
|
||||
def requires(self):
|
||||
"""Get the dependencies of this package."""
|
||||
|
@ -49,11 +56,15 @@ class PackageV1(Package):
|
|||
elif isinstance(it, dict):
|
||||
return it["name"]
|
||||
|
||||
return [
|
||||
_name(it) for it in self.config().get("package", {}).get("require", [])
|
||||
]
|
||||
return [_name(it) for it in self.config().get("package", {}).get("require", [])]
|
||||
|
||||
def do_sh_or_script(self, content: Optional[Union[List[str], str]], fs: Vfs, dest: Path, cwd: Path = "/tmp"):
|
||||
def do_sh_or_script(
|
||||
self,
|
||||
content: Optional[Union[List[str], str]],
|
||||
fs: Vfs,
|
||||
dest: Path,
|
||||
cwd: Path = "/tmp",
|
||||
):
|
||||
if content is None:
|
||||
pass
|
||||
|
||||
|
@ -66,7 +77,7 @@ class PackageV1(Package):
|
|||
content["run"],
|
||||
fs,
|
||||
dest,
|
||||
{"cwd": self.root}.get(content.get("root"), "/tmp")
|
||||
{"cwd": self.root}.get(content.get("root"), "/tmp"),
|
||||
)
|
||||
|
||||
elif isinstance(content, str):
|
||||
|
@ -93,19 +104,24 @@ class PackageV1(Package):
|
|||
with open(installf, "r") as fp:
|
||||
self.do_sh_or_script(fp.read(), fs, dest)
|
||||
|
||||
|
||||
def do_build(self, fs: Vfs, dest: Path):
|
||||
self.do_sh_or_script(self.config().get("package", {}).get("build"), fs, dest)
|
||||
|
||||
def pre_install(self, fs: Vfs, dest: Path):
|
||||
self.do_sh_or_script(self.config().get("package", {}).get("pre_install"), fs, dest)
|
||||
self.do_sh_or_script(
|
||||
self.config().get("package", {}).get("pre_install"), fs, dest
|
||||
)
|
||||
|
||||
def do_install(self, fs: Vfs, dest: Path):
|
||||
if not self.do_sh_or_script(self.config().get("package", {}).get("install"), fs, dest):
|
||||
if not self.do_sh_or_script(
|
||||
self.config().get("package", {}).get("install"), fs, dest
|
||||
):
|
||||
stow(fs, self.root, dest, self.SPECIAL_FILES)
|
||||
|
||||
def post_install(self, fs: Vfs, dest: Path):
|
||||
self.do_sh_or_script(self.config().get("package", {}).get("post_install"), fs, dest)
|
||||
self.do_sh_or_script(
|
||||
self.config().get("package", {}).get("post_install"), fs, dest
|
||||
)
|
||||
|
||||
def json(self):
|
||||
return self.config()
|
||||
|
@ -124,16 +140,24 @@ class LightPackageV1(PackageV1):
|
|||
return self._config
|
||||
|
||||
def test(self):
|
||||
return self.root.exists() \
|
||||
and self.root.is_file() \
|
||||
and self.root.name.endswith(".toml") \
|
||||
return (
|
||||
self.root.exists()
|
||||
and self.root.is_file()
|
||||
and self.root.name.endswith(".toml")
|
||||
and self.config().get("cram", {}).get("version") == 1
|
||||
)
|
||||
|
||||
|
||||
class ProfileV1(PackageV1):
|
||||
"""Unline packages, profiles don't support recursive stow of contents."""
|
||||
|
||||
_LEGACY_SPECIAL_FILES = ["BUILD", "PRE_INSTALL", "INSTALL", "POST_INSTALL", "REQUIRES"]
|
||||
_LEGACY_SPECIAL_FILES = [
|
||||
"BUILD",
|
||||
"PRE_INSTALL",
|
||||
"INSTALL",
|
||||
"POST_INSTALL",
|
||||
"REQUIRES",
|
||||
]
|
||||
SPECIAL_FILES = []
|
||||
_config = None
|
||||
|
||||
|
@ -141,7 +165,9 @@ class ProfileV1(PackageV1):
|
|||
return {}
|
||||
|
||||
def test(self):
|
||||
return self.root.is_dir() and not any((self.root / f).exists() for f in self._LEGACY_SPECIAL_FILES)
|
||||
return self.root.is_dir() and not any(
|
||||
(self.root / f).exists() for f in self._LEGACY_SPECIAL_FILES
|
||||
)
|
||||
|
||||
def do_install(self, fs: Vfs, dest: Path):
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue