Shaking out bugs from v0.2.1

This commit is contained in:
Reid 'arrdem' McKenzie 2022-09-14 00:08:13 -06:00
parent ad6bc4e99b
commit 5cd63f247b

View file

@ -7,6 +7,7 @@ import pickle
from typing import List, Optional, Union from typing import List, Optional, Union
import re import re
import platform import platform
from pprint import pformat
from collections import defaultdict from collections import defaultdict
from . import ( from . import (
@ -126,7 +127,7 @@ def load_packages(root: Path, roots) -> dict:
packages = {} packages = {}
for r in roots.get("package", []): for r in roots.get("package", []):
r = root / r r = root / expandvars(r)
log.debug(f"Trying to load packages from {r}...") log.debug(f"Trying to load packages from {r}...")
for p in r.glob("*"): for p in r.glob("*"):
name = str(p.relative_to(root)) name = str(p.relative_to(root))
@ -134,7 +135,7 @@ def load_packages(root: Path, roots) -> dict:
for r in roots.get("profile", []): for r in roots.get("profile", []):
# Add profiles, hosts which contain subpackages. # Add profiles, hosts which contain subpackages.
r = root / r r = root / expandvars(r)
log.debug(f"Trying to load profiles from {r}...") log.debug(f"Trying to load profiles from {r}...")
for mp_root in r.glob("*"): for mp_root in r.glob("*"):
# First find all subpackages # First find all subpackages
@ -172,13 +173,11 @@ def build_fs(
packages = load_packages(root, roots) packages = load_packages(root, roots)
if packages: if not packages:
for p in packages:
log.debug(f"Loaded package {p}")
else:
log.warning("Loaded no packages!") log.warning("Loaded no packages!")
requirements = list(prelude) requirements = list(prelude)
dirty = list()
for r in requirements: for r in requirements:
try: try:
for d in packages[r].requires(): for d in packages[r].requires():
@ -186,11 +185,14 @@ def build_fs(
requirements.append(d) requirements.append(d)
except KeyError as e: except KeyError as e:
missing_require_handler(r, e) missing_require_handler(r, e)
dirty.append(r)
for r in dirty:
requirements.remove(r) requirements.remove(r)
log.info(f"Mapped requirements {prelude} to {requirements}")
# Compute the topsort graph # Compute the topsort graph
requirements_graph = {r: packages[r].requires() for r in requirements} requirements_graph = {r: packages[r].requires() for r in requirements}
log.debug(pformat(requirements_graph))
fs = Vfs() fs = Vfs()
# Abstractly execute the current packages # Abstractly execute the current packages
@ -198,6 +200,7 @@ def build_fs(
r = packages[r] r = packages[r]
r.install(fs, dest) r.install(fs, dest)
log.info(f"Computed an initial plan of {len(fs._log)} steps")
return fs return fs
@ -221,6 +224,7 @@ def simplify(old_fs: Vfs, new_fs: Vfs, /, exec_idempotent=True) -> Vfs:
old_fs = old_fs.clone() old_fs = old_fs.clone()
new_fs = new_fs.clone() new_fs = new_fs.clone()
initial_new_steps = len(new_fs._log)
# Scrub anything in the new log that's in the old log # Scrub anything in the new log that's in the old log
for txn in list(old_fs._log): for txn in list(old_fs._log):
@ -243,6 +247,7 @@ def simplify(old_fs: Vfs, new_fs: Vfs, /, exec_idempotent=True) -> Vfs:
deduped.append(op) deduped.append(op)
new_fs._log = deduped new_fs._log = deduped
log.info(f"Optimized out {initial_new_steps - len(new_fs._log)} steps")
return new_fs return new_fs
@ -304,10 +309,19 @@ def configure(ctx, param, filename: Optional[Path]):
exit(1) exit(1)
def count_to_level(count: int):
if count == 0:
return logging.WARN
elif count == 1:
return logging.INFO
elif count > 1:
return logging.DEBUG
@click.group(invoke_without_command=True) @click.group(invoke_without_command=True)
@click.option( @click.option(
"--config", "--config",
type=click.Path(dir_okay=False), type=Path,
default=upsearch("cram.toml"), default=upsearch("cram.toml"),
callback=configure, callback=configure,
is_eager=True, is_eager=True,
@ -315,6 +329,12 @@ def configure(ctx, param, filename: Optional[Path]):
help="Read option defaults from the specified TOML file", help="Read option defaults from the specified TOML file",
show_default=True, show_default=True,
) )
@click.option(
"-v",
"--verbose",
count=True,
callback=lambda ctx, param, count: count_to_level(count),
)
@click.version_option( @click.version_option(
version=__version__, version=__version__,
message=f"""Cram {__version__} message=f"""Cram {__version__}
@ -335,8 +355,11 @@ About
Published under the terms of the {__license__} license. Published under the terms of the {__license__} license.
""", """,
) )
def cli(): def cli(verbose):
pass logging.basicConfig(
level=verbose,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
def arg_statefile(*args, **kwargs): def arg_statefile(*args, **kwargs):
@ -575,9 +598,9 @@ exec_idempotent = true
# Where to load requirements from, and the requirement type # Where to load requirements from, and the requirement type
# Types: package, profile # Types: package, profile
require_root = [ require_root = [
["package", "${PWD}/packages.d"], ["package", "packages.d"],
["profile", "${PWD}/profiles.d"], ["profile", "profiles.d"],
["profile", "${PWD}/hosts.d"], ["profile", "hosts.d"],
] ]
# Choice([error, warn, ignore]) # Choice([error, warn, ignore])
missing_require = "error" missing_require = "error"
@ -596,10 +619,5 @@ require = [
(confdir / d).mkdir(parents=True, exist_ok=True) (confdir / d).mkdir(parents=True, exist_ok=True)
if __name__ == "__main__" or 1: if __name__ == "__main__":
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
cli() cli()