Files
SoraKatadzuma b7b99783c8 Added testing
Preparing profiles and dependencies, but added testing to separate them from regular targets and avoid the need for a 'testing' profile which could negatively impact configuration size and readability.
2026-06-26 03:45:38 +00:00

102 lines
2.5 KiB
Python

import yaml
from argparse import ArgumentParser
from argparse import Namespace
from pathlib import Path
from semantic_version import Version
# Load application configurations.
cfgdir = Path.home() / ".config" / "chinook" / "remotes.yaml"
remotes = yaml.full_load(cfgdir) if Path.exists(cfgdir) else []
def _build(args: Namespace) -> None:
from chinook import management
from chinook import pipeline
from chinook._config import Config
from chinook._logger import logger
try:
projpath = Path(args.project)
cfgpath = projpath / "chinookconfig"
appcfg = Config.create_default_or_load(cfgpath)
projcfg = management.load(projpath)
result = pipeline.build(appcfg, projcfg, logger)
logger.info(f"[100%] Built {projcfg.cid}")
return result
except Exception as err:
logger.exception(str(err))
logger.critical("Failed to build project")
def _test(args: Namespace) -> None:
from chinook import management
from chinook import pipeline
from chinook._config import Config
from chinook._logger import logger
try:
projpath = Path(args.project)
cfgpath = projpath / "chinookconfig"
appcfg = Config.create_default_or_load(cfgpath)
projcfg = management.load(projpath)
result = pipeline.test(appcfg, projcfg, logger)
passed = 0
count = 0
for item in result:
if item.action == "Testing":
count += 1
if item.retcode == 0:
passed += 1
logger.info(f"Tested {projcfg.cid} [{passed}/{count}]")
except Exception as err:
logger.exception(str(err))
logger.critical("Failed to test project")
def main() -> None:
print("\n".join([
"┏┓┓ • ┓ ",
"┃ ┣┓┓┏┓┏┓┏┓┃┏",
"┗┛┛┗┗┛┗┗┛┗┛┛┗ v" + str(Version(major=0,minor=1,patch=0))
]))
# Parent parser to all subcommands.
parser = ArgumentParser(
prog = "chinook",
description = "Opinionated build tool for C/C++!"
)
commands = parser.add_subparsers(required=True)
buildcmd = commands.add_parser("build",help="Builds your Chinook project")
buildcmd.set_defaults(func=_build)
buildcmd.add_argument(
"project",
nargs="?",
default=".",
type=str,
help="The path to the project to build.",
metavar="PROJECT"
)
testcmd = commands.add_parser("test",help="Tests your Chinook project")
testcmd.set_defaults(func=_test)
testcmd.add_argument(
"project",
nargs="?",
default=".",
type=str,
help="The path to the project to test.",
metavar="PROJECT"
)
arguments = parser.parse_args()
arguments.func(arguments)
# Auto execute.
if __name__ == "__main__": main()