|
1 | | -import proman |
| 1 | +import argparse |
| 2 | + |
| 3 | +from loggerman import logger |
| 4 | + |
| 5 | +from proman import script |
2 | 6 | from proman.report import initialize_logger |
3 | 7 |
|
4 | | -initialize_logger(title_number=[1]) |
5 | | -proman.run() |
| 8 | + |
| 9 | +def cli(): |
| 10 | + def get_endpoint(endpoint_name: str): |
| 11 | + def get_recursive(parts, current_object): |
| 12 | + if len(parts) == 1: |
| 13 | + return getattr(current_object, parts[0]) |
| 14 | + else: |
| 15 | + return get_recursive(parts[1:], getattr(current_object, parts[0])) |
| 16 | + |
| 17 | + parts = endpoint_name.split(".") |
| 18 | + return get_recursive(parts, script) |
| 19 | + |
| 20 | + initialize_logger() |
| 21 | + # begin auto-generated parser |
| 22 | + parser = argparse.ArgumentParser(description="Project Manager CLI") |
| 23 | + parser.add_argument("--repo", type=str, help="Local path to the repository root directory.", default="./") |
| 24 | + # Sub-parsers for parser |
| 25 | + subparsers_main = parser.add_subparsers(dest="command", required=True) |
| 26 | + subparser_cca = subparsers_main.add_parser("cca", help="Run Continuous Configuration Automation on the repository.") |
| 27 | + subparser_cca.add_argument("-t", "--token", type=str, help="GitHub token for accessing the repository.") |
| 28 | + subparser_cca.add_argument("-b", "--branch-version", help="Branch-name to version mappings (e.g., -b main=0.0.0 dev=1.0.0a1) to use instead of git tags.", type=str, nargs="*", metavar="BRNACH=VERSION") |
| 29 | + subparser_cca.add_argument("-c", "--control-center", help="Path to the control center directory containing configuration files.", type=str) |
| 30 | + subparser_cca.add_argument("-d", "--dry-run", help="Perform a dry run without making any changes.", action="store_true") |
| 31 | + subparser_cca.add_argument("-n", "--no-validate", help="Skip validation of the metadata.json file.", dest="validate", action="store_false") |
| 32 | + subparser_cca.set_defaults(endpoint="cca.run_cli") |
| 33 | + subparser_lint = subparsers_main.add_parser("lint", help="Run pre-commit hooks on the repository.") |
| 34 | + subparser_lint.add_argument("-x", "--action", help="Lint mode.", type=str, choices=['report', 'run', 'validate'], default="run") |
| 35 | + subparser_lint.add_argument("-c", "--config", help="Path to the pre-commit configuration file.", type=str, default=".devcontainer/config/pre-commit.yaml") |
| 36 | + subparser_lint.add_argument("-r2", "--to-ref", help="Run on files changed until the given git ref. This must be accompanied by --from-ref.") |
| 37 | + subparser_lint_mutually_exclusive_hook = subparser_lint.add_mutually_exclusive_group() |
| 38 | + subparser_lint_mutually_exclusive_hook.add_argument("-i", "--hook-id", help="Specific hook ID to run. This will only run the specified hook.", type=str) |
| 39 | + subparser_lint_mutually_exclusive_hook.add_argument("-s", "--hook-stage", help="Specific hook stage to run. This will only run hooks in the specified stage.", type=str) |
| 40 | + subparser_lint_mutually_exclusive_file = subparser_lint.add_mutually_exclusive_group() |
| 41 | + subparser_lint_mutually_exclusive_file.add_argument("-a", "--all-files", help="Run on all files in the repository.", action="store_true") |
| 42 | + subparser_lint_mutually_exclusive_file.add_argument("-f", "--files", help="Run on specific files.", nargs="+") |
| 43 | + subparser_lint_mutually_exclusive_file.add_argument("-r1", "--from-ref", help="Run on files changed since the given git ref. This must be accompanied by --to-ref.") |
| 44 | + subparser_lint.set_defaults(endpoint="lint.run_cli") |
| 45 | + subparser_version = subparsers_main.add_parser("version", help="Print the current version of the project.") |
| 46 | + subparser_version.set_defaults(endpoint="version.run_cli") |
| 47 | + subparser_build = subparsers_main.add_parser("build", help="Build project components.") |
| 48 | + # Sub-parsers for subparser_build |
| 49 | + subparsers_build = subparser_build.add_subparsers(dest="build", required=True) |
| 50 | + subparser_conda = subparsers_build.add_parser("conda", help="Build a conda package in the project.") |
| 51 | + subparser_conda.add_argument("-p", "--pkg", help="Package ID, i.e., the `pypkg_` key suffix in configuration files.", default="main") |
| 52 | + subparser_conda.add_argument("-o", "--output", help="Path to the local conda channel directory.", type=str, default=".local/temp/conda-channel") |
| 53 | + subparser_conda.add_argument("-r", "--recipe", help="Type of recipe to build.", type=str, choices=['local', 'global'], default="local") |
| 54 | + subparser_conda.add_argument("--args", help="Additional arguments to pass to the conda build command.", nargs=argparse.REMAINDER) |
| 55 | + subparser_conda.set_defaults(endpoint="build.conda.run_cli") |
| 56 | + subparser_python = subparsers_build.add_parser("python", help="Build a Python package in the project.") |
| 57 | + subparser_python.add_argument("-p", "--pkg", help="Package ID, i.e., the `pypkg_` key suffix in configuration files.", default="main") |
| 58 | + subparser_python.add_argument("-o", "--output", help="Path to the local PyPI channel directory.", type=str, default=".local/temp/wheelhouse") |
| 59 | + subparser_python.add_argument("--args", help="Additional arguments to pass to the Python build command.", nargs=argparse.REMAINDER) |
| 60 | + subparser_python.set_defaults(endpoint="build.python.run_cli") |
| 61 | + subparser_render = subparsers_main.add_parser("render", help="Render documents in the project.") |
| 62 | + # Sub-parsers for subparser_render |
| 63 | + subparsers_render = subparser_render.add_subparsers(dest="render", required=True) |
| 64 | + subparser_pypi = subparsers_render.add_parser("pypi", help="Render package README file for PyPI.") |
| 65 | + subparser_pypi.add_argument("-p", "--pkg", help="Package ID, i.e., the `pypkg_` key suffix in configuration files.", default="main") |
| 66 | + subparser_pypi.add_argument("-o", "--output", help="Output directory to write the rendered HTML file.", type=str, default=".local/temp/readme-pypi") |
| 67 | + subparser_pypi.set_defaults(endpoint="render.pypi.run_cli") |
| 68 | + # Process inputs |
| 69 | + args = parser.parse_args() |
| 70 | + import json |
| 71 | + from pathlib import Path |
| 72 | + setattr( |
| 73 | + args, |
| 74 | + "metadata", |
| 75 | + json.loads((Path(args.repo).resolve() / ".github/.repodynamics/metadata.json").read_text()) |
| 76 | + ) |
| 77 | + if args.command == "cca": |
| 78 | + if args.branch_version: |
| 79 | + try: |
| 80 | + args.branch_version = dict(pair.split("=", 1) for pair in args.branch_version) |
| 81 | + except ValueError: |
| 82 | + parser.error( |
| 83 | + "--branch-version must be in the format BRANCH=VERSION (e.g., -b main=1.0.0 dev=2.0.0)." |
| 84 | + ) |
| 85 | + if args.command == "lint": |
| 86 | + if (args.from_ref and not args.to_ref) or (args.to_ref and not args.from_ref): |
| 87 | + parser.error("Both --from-ref and --to-ref must be provided together.") |
| 88 | + # end auto-generated parser |
| 89 | + logger.debug("Input Arguments", args) |
| 90 | + endpoint = get_endpoint(args.endpoint) |
| 91 | + endpoint(args) |
| 92 | + return |
| 93 | + |
| 94 | + |
| 95 | +if __name__ == "__main__": |
| 96 | + cli() |
0 commit comments