diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 787981708..b6754873d 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -4,7 +4,7 @@ The following points apply when adding a new repository to repos.json - [ ] By including this repository in NUR I give permission to license the content under the MIT license. -Clarifiction where license should apply: +Clarification where license should apply: The license above does not apply to the packages built by the Nix Packages collection, merely to the package descriptions (i.e., Nix expressions, build scripts, etc.). It also might not apply to patches diff --git a/nur/__init__.py b/nur/__init__.py index 5830ad34f..fab7ca290 100644 --- a/nur/__init__.py +++ b/nur/__init__.py @@ -1,19 +1,29 @@ import argparse +import logging import sys from typing import List +from .combine import combine_command from .format_manifest import format_manifest_command from .index import index_command -from .update import update_command from .path import ROOT +from .update import update_command -from .combine import combine_command +LOG_LEVELS = dict( + debug=logging.DEBUG, + info=logging.INFO, + error=logging.ERROR, + critical=logging.CRITICAL, +) def parse_arguments(argv: List[str]) -> argparse.Namespace: parser = argparse.ArgumentParser( prog=argv[0], description="nur management commands" ) + parser.add_argument( + "--log-level", type=str, default="debug", choices=list(LOG_LEVELS.keys()) + ) subparsers = parser.add_subparsers(description="subcommands") @@ -48,4 +58,6 @@ def parse_arguments(argv: List[str]) -> argparse.Namespace: def main() -> None: args = parse_arguments(sys.argv) + logging.basicConfig(level=LOG_LEVELS[args.log_level]) + args.func(args) diff --git a/nur/error.py b/nur/error.py index 9f5c36132..fa2665cce 100644 --- a/nur/error.py +++ b/nur/error.py @@ -1,2 +1,6 @@ class NurError(Exception): pass + + +class EvalError(NurError): + pass diff --git a/nur/update.py b/nur/update.py index 9db66639a..b4d0281cb 100644 --- a/nur/update.py +++ b/nur/update.py @@ -5,7 +5,7 @@ import tempfile from argparse import Namespace from pathlib import Path -from .error import NurError +from .error import EvalError from .manifest import Repo, load_manifest, update_lock_file from .path import EVALREPO_PATH, LOCK_PATH, MANIFEST_PATH, nixpkgs_path from .prefetch import prefetch @@ -55,9 +55,9 @@ import {EVALREPO_PATH} {{ try: res = proc.wait(5) except subprocess.TimeoutExpired: - raise NurError(f"evaluation for {repo.name} timed out of after 5 seconds") + raise EvalError(f"evaluation for {repo.name} timed out of after 5 seconds") if res != 0: - raise NurError(f"{repo.name} does not evaluate:\n$ {' '.join(cmd)}") + raise EvalError(f"{repo.name} does not evaluate:\n$ {' '.join(cmd)}") def update(repo: Repo) -> Repo: @@ -71,15 +71,21 @@ def update(repo: Repo) -> Repo: def update_command(args: Namespace) -> None: + logging.basicConfig(level=logging.INFO) + manifest = load_manifest(MANIFEST_PATH, LOCK_PATH) for repo in manifest.repos: try: update(repo) - except Exception: + except EvalError as e: if repo.locked_version is None: # likely a repository added in a pull request, make it fatal then raise + # Do not print stack traces + logger.error(f"repository {repo.name} failed to evaluate: {e}") + except Exception: + # for non-evaluation errors we want the stack trace logger.exception(f"Failed to updated repository {repo.name}") update_lock_file(manifest.repos, LOCK_PATH)