forked from datajoint-company/dj-cookiecutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(retrocookie): reflect updates to source template from generated…
… project 'science-institute_brain-lab'
- Loading branch information
Joseph Burling
committed
Apr 22, 2022
1 parent
a1c0f47
commit aecdc6a
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
...-workflow/{{cookiecutter.github_repo}}/src/{{cookiecutter.__pkg_import_name}}/__main__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
"""Module-level command-line interface | ||
This serves as an example command-line interface for the main package module. | ||
Example: | ||
Usage as a console entrypoint: | ||
{{cookiecutter.__pkg_import_name}} --help | ||
{{cookiecutter.__pkg_import_name}} --version | ||
Usage as a script: | ||
python -m {{cookiecutter.__pkg_import_name}} | ||
Usage from python: | ||
from {{cookiecutter.__pkg_import_name}} import main; main(...) | ||
""" | ||
|
||
import argparse | ||
import sys | ||
from typing import Any, Sequence | ||
|
||
from {{cookiecutter.__pkg_import_name}} import version | ||
|
||
|
||
def parse_args(args: Sequence[str]) -> argparse.Namespace: | ||
"""_Parse command line parameters_ | ||
Args: | ||
args (list[str]): | ||
Command line parameters as list of strings. | ||
(example `["--help"]`) | ||
Returns: | ||
A Namespace of command line parameters. | ||
""" | ||
|
||
class ArgumentDefaultsRawDescriptionHelpFormatter( | ||
argparse.ArgumentDefaultsHelpFormatter, | ||
argparse.RawDescriptionHelpFormatter, | ||
argparse.MetavarTypeHelpFormatter, | ||
): | ||
"""Combination of different formatters""" | ||
|
||
pass | ||
|
||
parser = argparse.ArgumentParser( | ||
prog="{{cookiecutter.__pkg_import_name}}", | ||
epilog=__doc__, | ||
formatter_class=ArgumentDefaultsRawDescriptionHelpFormatter, | ||
) | ||
|
||
parser.add_argument( | ||
"--version", | ||
action="version", | ||
version=f"%(prog)s v{version}", | ||
) | ||
|
||
parsed_args = parser.parse_args(args) | ||
|
||
return parsed_args | ||
|
||
|
||
def main(**kwargs: Any) -> None: | ||
"""_Operate on cli args_.""" | ||
print("main module operations here.") | ||
|
||
|
||
def cli() -> None: | ||
"""_Calls [`__main__.main`][{{cookiecutter.__pkg_import_name}}.__main__.main], passing the cli | ||
arguments extracted from `sys.argv`_. | ||
This function can be used as entry point to create console scripts on package | ||
install. | ||
""" | ||
|
||
args = parse_args(sys.argv[1:]) | ||
main(**vars(args)) | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters