"""This is a skeleton file that can serve as a starting point for a Pythonconsole script. To run this script uncomment the following lines in the``[options.entry_points]`` section in ``setup.cfg``:: console_scripts = fibonacci = uetai.skeleton:runThen run ``pip install .`` (or ``pip install -e .`` for editable mode)which will install the command ``fibonacci`` inside your current environment.Besides console scripts, the header (i.e. until ``_logger``...) of this file canalso be used as template for Python modules.Note: This skeleton file can be safely removed if not needed!References: - https://setuptools.readthedocs.io/en/latest/userguide/entry_point.html - https://pip.pypa.io/en/stable/reference/pip_install"""importargparseimportloggingimportsysfromuetaiimport__version____author__="Nguyen Van Phi"__copyright__="Nguyen Van Phi"__license__="MIT"_logger=logging.getLogger(__name__)# ---- CLI ----# The functions defined in this section are wrappers around the main Python# API allowing them to be called directly from the terminal as a CLI# executable/script.
[docs]defparse_args(args):"""Parse command line parameters Args: args (List[str]): command line parameters as list of strings (for example ``["--help"]``). Returns: :obj:`argparse.Namespace`: command line parameters namespace """parser=argparse.ArgumentParser(description="CLI, serves a lot of functions of library")parser.add_argument("--version",action="version",version="uetai {ver}".format(ver=__version__),)parser.add_argument("-v","--verbose",dest="loglevel",help="set loglevel to INFO",action="store_const",const=logging.INFO,)parser.add_argument("-vv","--very-verbose",dest="loglevel",help="set loglevel to DEBUG",action="store_const",const=logging.DEBUG,)returnparser.parse_args(args)
[docs]defmain(args):"""Wrapper allowing :func:`fib` to be called with string arguments in a CLI fashion Instead of returning the value from :func:`fib`, it prints the result to the ``stdout`` in a nicely formatted message. Args: args (List[str]): command line parameters as list of strings (for example ``["--verbose", "42"]``). """args=parse_args(args)setup_logging(args.loglevel)_logger.info("Demonstrate of using ")_logger.error("something wrong")_logger.info("Script ends here")
[docs]defrun():"""Calls :func:`main` passing the CLI arguments extracted from :obj:`sys.argv` This function can be used as entry point to create console scripts with setuptools. """main(sys.argv[1:])