add parser file for building

This commit is contained in:
Maximilian Keßler 2021-10-22 14:52:10 +02:00
parent 4c3867e0f4
commit 12a03e7989
2 changed files with 102 additions and 1 deletions

View file

@ -1,5 +1,7 @@
from .build import build from .build import build
from .build_parser import parse_and_build
__all__ = [ __all__ = [
'build' 'build',
'parse_and_build'
] ]

99
build/build_parser.py Normal file
View file

@ -0,0 +1,99 @@
import argparse
import pathlib
from PyTeX.config import FILENAME_TYPE_PREPEND_AUTHOR, FILENAME_TYPE_RAW_NAME
from .build import build
def parse_and_build(arglist: [str]):
parser = argparse.ArgumentParser(description='Incrementally build LatexPackages with PyTeX')
input_group = parser.add_mutually_exclusive_group(required=True)
input_group.add_argument(
'-s', '--source-dir',
metavar='SRC_DIR',
help='Relative or absolute path to source directory of .pysty or .pycls files',
type=pathlib.Path,
nargs='?',
default='./src',
dest='src_dir'
)
parser.add_argument(
'-b', '--build-dir',
metavar='BUILD_DIR',
help='Relativ or absolute path to output directory for processed packages and classes',
type=pathlib.Path,
nargs='?',
default='./build',
dest='build_dir'
)
parser.add_argument(
'-r', '--recursive',
help='Recursively search subdirectories for files. Default: false',
action='store_true',
dest='recursive'
)
input_group.add_argument(
'-i', '--input-file',
metavar='FILE',
help='Filename to be built. Can be in valid .pysty or .pycls format',
type=pathlib.Path,
dest='input_file'
)
parser.add_argument(
'-n', '--name',
help='Name of the package / class to be formatted.',
type=str,
choices=[FILENAME_TYPE_RAW_NAME, FILENAME_TYPE_PREPEND_AUTHOR],
default=FILENAME_TYPE_PREPEND_AUTHOR,
dest='latex_name'
)
parser.add_argument(
'-g', '--git-version',
help='Insert git version information into build. This assumes your input'
'files are located in a git repository. Default: false',
action='store_true',
dest='use_git'
)
parser.add_argument(
'-d', '--allow-dirty',
help='If git flag is set, allow building of a dirty repo. Default: false',
action='store_true',
dest='allow_dirty'
)
parser.add_argument(
'-p',
'--pytex-version',
help='Write PyTeX version information into built LaTeX files',
action='store_true',
dest='include_pytex_version'
)
parser.add_argument(
'-t', '--build-time',
help='Insert build time into built LaTeX files',
action='store_true',
dest='include_timestamp'
)
parser.add_argument(
'-l', '--license',
help='Insert MIT license into package header',
action='store_true',
dest='include_license'
)
parser.add_argument(
'-a', '--author',
help='Set author of packages',
type=str,
dest='author'
)
parser.add_argument(
'-f', '--force',
help='Overwrite unknown existing files without confirmation',
action='store_true',
dest='overwrite_existing_files'
)
args = vars(parser.parse_args(arglist))
for arg in args.keys():
if type(args[arg]) == pathlib.PosixPath:
args[arg] = args[arg].resolve()
build(**args)