|
| 1 | +import argparse |
| 2 | + |
| 3 | +from hatchling.cli.build import build_command |
| 4 | + |
| 5 | + |
| 6 | +def hatchling() -> int: |
| 7 | + parser = argparse.ArgumentParser(prog="hatch-build", allow_abbrev=False) |
| 8 | + subparsers = parser.add_subparsers() |
| 9 | + |
| 10 | + defaults = {"metavar": ""} |
| 11 | + build_command(subparsers, defaults) |
| 12 | + |
| 13 | + # Replace parser with just the build one |
| 14 | + parser = subparsers.choices["build"] |
| 15 | + parser.prog = "hatch-build" |
| 16 | + |
| 17 | + # Parse known arguments |
| 18 | + kwargs, extras = parser.parse_known_args() |
| 19 | + |
| 20 | + # Extras can exist to be detected in custom hooks and plugins, |
| 21 | + # but they must be after a '--' separator |
| 22 | + if extras and extras[0] != "--": |
| 23 | + parser.print_help() |
| 24 | + return 1 |
| 25 | + |
| 26 | + # Wrap the parsed arguments in a dictionary |
| 27 | + kwargs = vars(kwargs) |
| 28 | + |
| 29 | + try: |
| 30 | + command = kwargs.pop("func") |
| 31 | + except KeyError: |
| 32 | + parser.print_help() |
| 33 | + else: |
| 34 | + command(**kwargs) |
| 35 | + |
| 36 | + return 0 |
| 37 | + |
| 38 | + # parser = subparsers.add_parser('build') |
| 39 | + # parser.add_argument( |
| 40 | + # '-d', '--directory', dest='directory', help='The directory in which to build artifacts', **defaults |
| 41 | + # ) |
| 42 | + # parser.add_argument( |
| 43 | + # '-t', |
| 44 | + # '--target', |
| 45 | + # dest='targets', |
| 46 | + # action='append', |
| 47 | + # help='Comma-separated list of targets to build, overriding project defaults', |
| 48 | + # **defaults, |
| 49 | + # ) |
| 50 | + # parser.add_argument('--hooks-only', dest='hooks_only', action='store_true', default=None) |
| 51 | + # parser.add_argument('--no-hooks', dest='no_hooks', action='store_true', default=None) |
| 52 | + # parser.add_argument('-c', '--clean', dest='clean', action='store_true', default=None) |
| 53 | + # parser.add_argument('--clean-hooks-after', dest='clean_hooks_after', action='store_true', default=None) |
| 54 | + # parser.add_argument('--clean-only', dest='clean_only', action='store_true') |
| 55 | + # parser.add_argument('--app', dest='called_by_app', action='store_true', help=argparse.SUPPRESS) |
| 56 | + # parser.set_defaults(func=build_impl) |
0 commit comments