Giter Club home page Giter Club logo

python-coockiecutter-minimal-cli's Introduction

Python coockiecutter minimal cli template

This is an absolute minimal boilerplate cli code as I use it in many of my projects where fast iteration and exploration is the key while maintaining order and versioning commands as well as writing outputs is important. I prefer this way of working to the use of iPython notebooks, especially as soon as it comes to experimenting. Command line arguments with proper help texts are somewhat "self documenting" which can be useful, especially if you wrote the code a while back.

Features:

  • logging namespace
  • set log level on cli
  • boilerplate cli generation

Requirements:

You need cookiecutter installed (for example from here https://github.com/cookiecutter/cookiecutter) Install with conda or pip:

pip install --user cookiecutter
# or
conda install cookiecutter

or when you're on Mac you can use homebrew

brew install cookiecutter

To make the template work you will need the click library:

pip install click

Usage:

Directly from github

cookiecutter -o outdir https://github.com/patientzero/python-cockiecutter-minimal-cli

From the cloned directory:

git clone https://github.com/patientzero/python-cockiecutter-minimal-cli.git
cd python-cockiecutter-minimal-cli
cookiecutter -o outdir ~/projects/python-cockiecutter-minimal-cli

Options && default values:

    "module_name": "command",
    "command_group_name": "cli",
    "cli_name": "my_cli",
    "first_command_name": "helloworld",
    "file_name": "cli.py"
    "username": "username",
    "slurm_batch_script": ""
  • module name: name of the module containing your cli
  • command_group_name: Name of the method on which the @click.group decorator is placed, used for adding more commands
  • cli_name: Internal name for your program. Mainly used for logging.
  • first_command_name: Name of first example/boilerplate method
  • file_name: Name of the file containing your cli definition
  • username: your username on the cluster
  • slurm_batch_script: output name for a slurm batch job script, if none is given, the file will not be created

General use of generated cli:

python -m module_name --option1 someinput --option2 somemoreinput

Example call of first generated method:

cd outdir
python -m command -l INFO helloworld --log-dir /test/logs
# output:
# [2020-03-23 15:39:41,881] INFO cli.py: use pathlib to write to /test/logs

You can make new commands based on the provided example (helloworld). For more options visit the click docs.

python-coockiecutter-minimal-cli's People

Contributors

patientzero avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.