Package: makepy
**<span style="color:red">
    This is the backport version 0.0.26 of 'makepy' for Python 2.
    Please upgrade to Python 3+ and use the current 'makepy' version 0.0.26.
    </span>**makepy: Handsfree Python Module ProgrammingThis project provides:makepy: A command line tool to simplify Python project setup,
installation, and testing.makepy.mainlog: A module for makingloggingandstructlogsetup less cumbersome and less error-prone.makepy.argparse: A module providing a drop-inArgumentParserfor writing better readableargparsecode.Install viapip3 install --user makepy.mainlog moduleAs the name suggest, usemakepy.mainlogonly in your main module.
Do not setup logging outside of main modules!
The module's main function ismainlog.setup_logging:importloggingfrommakepyimportmainloglog=logging.getLogger('app')defmain(argv=None):level=logging.INFOmainlog.setup_logging(level=level,mode='json')log.info('Hello%s!','makepy',extra={'v':1})main()# {"message": "Hello makepy!", "v": 1}The currently supported logging modes arejsonandconsole(default).
Usingmode='console'or no mode will produce regular stdlib logs like:INFO:app:Hello makepy!Usemainlog.setup_logging(level=level, use_structlog=True)to setupstructloglogging.
Ifstruclogis not installed, stdlibloggingis used as fallback.
The predefined structlog settings will format stdlib logs as follows.[info     ] info msg 1                     [stdlib]
[debug    ] debug msg 2                    [stdlib]
[error    ] error msg 3                    [stdlib]If you use structlog loggers in your modules you also getextrakey-value pairs.[info     ] info msg                       [structlog] a=[1, 2, 3] v=1
[debug    ] debug msg                      [structlog] b=('a', 'b', 'c') v=2
[error    ] error msg                      [structlog] c={'x': 1} v=3Ifcoloramais installed, the logs will be nicely colored (structlog feature).argparse moduleFor writing better command line apps,makepy.argparseprovides a compatibleArgumentParserthat uses the 4-letteroptiandflagmethods, replacing the originaladd_argumentmethod.frommakepyimportargparsedesc='My CLI Tool'p=argparse.ArgumentParser(description=desc)p.flag('--json',help='use json output format')p.flag('--dry_run',help='perform dry run')p.opti('--num','-n',help='number of iterations',metavar='N',type=int,default=1)p.opti('--file','-f',help='input file',required=True)p.opti('command',help='command to run',choices=['upper','lower'])Using shorter names and nice alignment allowsargparsecode to be much more readable.
Yes I know, to allow for such multi-column-based coding, you need to disable some linter rules.
But it's worth it, not just forargparsecode, but for better readable Python code in general.
makepy'sArgumentParseralso provides a few shortcuts to setup other commonly used modules
directly via the following flags:with_debug:   adds--debugflagwith_logging: automatically sets up logging usingmakepy.mainlogafter parsing argswith_input:   adds--inputoption, defaulting to-(aka.stdin)with_protected_spaces: modifies theargparseformatter, to protect white space as defined
in yourhelpstatements. Otherwiseargparsewill strip any newline and repeated spaces,
etc., to create condense help paragraphs. Using this option you can now safely align help text
directly in your code. Seemakep/cli.pyas an example.Here is an example to setup common debug and logging features:p=argparse.ArgumentParser(description=desc).with_logging(use_structlog=True).with_debug()If you do not like one-liners, you can also break lines.p=argparse.ArgumentParser(description=desc)p.with_logging(use_structlog=True)p.with_debug()p.with_input()Using thewith_loggingand optionally usingwith_debugallows you to quickly
setuploggingorstructlogloggers with human-readable console output.
Therefore,with_loggingsupports the samemodeanduse_structlogkey-value args
as used bymainlog.setup_loggingdescribedabove.makepy commandThis project also provides amakepycommand, used to automate project creation, incremental
building, testing viatox, and uploading to PyPi.Here are some commands supported bymakepy:makepy init --trg ~/workspace/newproject # setup new project/package named "newproject"
cd ~/workspace/newproject                # enter new project

makepy backport     # backport project to python2
tox -e py3          # use `tox` to install and test the package in a Python 3 environment
tox                 # install and test in all testenvs defined in `tox.ini`
makepy              # install and test in the default testenv
makepy clean        # cleanup test environments and build files

makepy dist         # build python wheel for current project
makepy dist -P 2    # build python wheel for python2
makepy dists        # build both wheels for python2 and python3
makepy version      # read version string from main __init__.py
makepy bumpversion  # increase patch level in main __init__.py
makepy install      # pip install the wheel in the system (may require sudo)
makepy dev-install  # pip install the current editable source code in the system
makepy uninstall    # uninstall current project/package from all pipsYou can also chain commands:makepy clean bumpversion dists, andmakepywill reorder
them and add all required depending commands, e.g.,makepy install -P 2is equivalent
tomakepy backport dist install -P 2.Themakepycommand depends on and can initialize values in the Python config filestox.iniandsetup.cfg. It can also create a generic py2-py3+
compatiblesetup.py, as found in this project.Runmakepy init --trg PATH_TO_NEW_PROJECTto setup all required files. Use-fto allow
overwriting existing files. Seemakepy --helpfor more options.makepy + makeSome makepy functionality is still only available viamake, using themake/project.mk, [make/vars.mk][make_vars], etc. include files. You can
use these in your project. Just copy them to amakedir in your project andincludethem
in yourMakefile, asdoneby this project. See each mk-file for details and help.GoalsIn general the project aims to provide a few flexible tools and modules that should help with
daily Python programming tasks for developing Python modules, libaries, and command line tools.
It aims to capture best practices and make them reusable, allowing you to write less and more
readable code, without breaking flexibility or compatibility of the enhanced modules and tools.MotivationMost Python programmers knowargparse,loggingorstructlog,toxandpip, and many also usetwine,setuptools, and others. However, when using these tools you will write the
same or very similar boilerplate code again and again.Not wanting to repeat myself, I wanted to extract the most common practices from my projects
and make them available for my next projects and for others to use.HistoryThe utility modules to setuploggingandargparse, were scattered in several private
projects (and reimplemented in corporate projects). Most of themakepycommands lived in a
hugeMakefilethat had to be copied and augmented from project to project, before I finally
started porting features tomakepy. A fewmakefeatures still remain and can be found in
this project'smkfiles, such as themake tagandmake publish.I will keepmakepyupdated, with future learnings and I am happy to welcome pull requests.Have fun!Open Issues/TasksAdd Python 2 support for namespaces.Port doc strings + create readthedocs docs.Port version management to use externalbumpversioncommand.Port integration tests from make.Port docker tests from make.Port wheel publishing from make.Port remainder from make + remove make related code.