Created
June 4, 2020 13:16
-
-
Save fbparis/77c6e5a9748530df2e5964c658272320 to your computer and use it in GitHub Desktop.
Base python3 template :)
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
#!/usr/local/bin/python3 | |
# -*- coding: utf-8 -*- | |
""" | |
""" | |
__title__ = __file__.rsplit('.', 1)[0].title() | |
__author__ = '[email protected]' | |
__license__ = 'IV' | |
version_info = (0, 0, 1) | |
__version__ = '.'.join(map(str, version_info)) | |
import sys | |
MIN_PYTHON = (3, 7, 1) | |
assert sys.version_info >= MIN_PYTHON, f"requires Python {'.'.join([str(n) for n in MIN_PYTHON])} or newer" | |
import logging | |
import time | |
from itertools import chain | |
logging.basicConfig( | |
level=logging.WARNING, | |
format='%(asctime)s %(name)s %(levelname)s %(message)s' | |
) | |
logger = logging.getLogger(f'{__file__}.{__name__}') | |
def timeit(func): | |
def timed(*args, **kwargs): | |
ts = time.time() | |
r = func(*args, **kwargs) | |
te = time.time() | |
logger.debug(f"{func.__name__}({', '.join(chain(map(repr, args), (f'{k}={repr(v)}' for k, v in kwargs.items())))}) took {te - ts:.6f}s") | |
return r | |
return timed | |
@timeit | |
def main(args=None): | |
""" | |
""" | |
pass | |
if __name__ == '__main__': | |
import argparse | |
parser=argparse.ArgumentParser(prog=__title__ or __file__, description=__doc__, epilog='', formatter_class=argparse.ArgumentDefaultsHelpFormatter) | |
group = parser.add_mutually_exclusive_group() | |
group.add_argument('-v', '--verbose', action='store_true', help='verbose output (debug mode)') | |
group.add_argument('-q', '--quiet', action='store_true', help='minimal output (warning and errors only)') | |
parser.add_argument('--version', action='version', version=f'%(prog)s {__version__}') | |
args = parser.parse_args() | |
if args.verbose: | |
logger.setLevel(logging.DEBUG) | |
elif not args.quiet: | |
logger.setLevel(logging.INFO) | |
main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment