Metadata-Version: 2.1
Name: taskr-cli
Version: 0.3.1
Summary: A language agnostic make-like tool meant for python projects
Home-page: https://gitlab.com/peasleyk/taskr
Author: Kyle Peasley
License: UNKNOWN
Platform: UNKNOWN
Description-Content-Type: text/markdown

# Taskr
[![PyPI version](https://badge.fury.io/py/taskr-cli.svg)](https://badge.fury.io/py/taskr-cli)

A magical, zero dependency, easy to use task runner with an original name. Inspired by [Mage](https://github.com/magefile/mage), a task runner for go. Made for python projects, but usable for any.

All that's needed is a tasks.py file in the same folder you are invoking "taskr" from

## Installing

```bash
pip install taskr-cli
```

Check the version
```bash
taskr --version
```

## Using

Make sure you have a tasks.py file defined in the root of your repo.
You can generate a template, with  `taskr --init`.
`taskr` can be used from any sub directory if `PYENV_DIR` or 'TASKR_DIR' is set to the projects root. There is a utility function "injectPath()" that can do this for you, included in the template.

CLI:

```bash
[master●] » taskr -h
usage: taskr [-h] [-v] [-l] [-i]

A small utility to run tasks

optional arguments:
  -h, --help     show this help message and exit
  -v, --version  Show the version number
  -l, --list     Show defined tasks
  -i, --init     Generate a template task file

```

When listing tasks, taskr will attempt to grab the docblock and show it, or use a single # comment above the task function.
Also note, any functions in `tasks.py` that start with an underscore, are ignored when listing

```bash
[master●] » taskr -l

Tasks:
 all         : Runs all static analysis tools
 build       : Builds the wheel
 clean       : Remove build artifacts, cache, etc.
 flake       : Check flake8
 fmt         : Run black
 mypy        : Checks types
 *reinstall  : Re-installs taskr
 sort        : Sort imports
 test        : Run tests
 upload_prod : Send it for real!
 upload_test : Send it!

* = default
```

To run a task, just pass the name of a function. Output from a task will be displayed

```bash
[master●] » taskr format
All done! ✨ 🍰 ✨
11 files left unchanged.
```


# Configuration Variables

There are a few configuration setting, set in tasks.py itself.

Placing `VENV_REQUIRED = True` in your tasks.py file, taskr will only run if it detects it's running in a virtual environment. You can delete it otherwise

Default tasks are run when `taskr` is run without any arguments. You can set this by setting a variable ```DEFAULT = "some_func"``` to the name of a task in tasks.py.

If you want an environment file to be loaded before every task, set `ENV = path/to/file` at the top of  `tasks.py`

```python
from taskr import runners

DEFAULT = "test"
VENV_REQUIRED = True
ENVS = "dev.env"

# Run tests
def test
  runners.run("python -m pytest tests/")
```

## Helpful functions for running tasks

A few task running methods are provided for system running tasks. Taskr expects task functions to return either  ```True``` (The task was successful) for ```False```it failed. To determine if a task was successful or not, taskr looks at the return code of the called program. 0 is success, anything else fails.

Taskr will auto copy your existing environment variables when running tasks, so running tasks with programs installed in a virual environment (i.e. dev tools though pip) will work.

### run
`run`'s argument can be either a list, or a string. A list is parsed into one command, not multiple

Optionally pass a an environment dictionary to be used at runtime.

```python
from taskr import runners

# Run flake8
def flake_list() -> bool:
    return runners.run(["python", "-m", "flake8", "taskr/*.py"])

# Run tests
def flake() -> bool:
    return runners.run("python -m pytest tests/ -v")

# Build a wheel
def build():
  ENV = {
    "PRODUCTION": "true"
  }
  return runners.run("python setup.py install", ENV)

```

### run_conditional
`run_conditional` is a way to run tasks (functions) in order, as long as the previous task returns a non failure return code (False).
You can throw normal python functions in here to

```python
from taskr import runners
import some_package as sp

# Run black
def fmt():
    return runners.run("python -m black .")

# Check flake8
def flake():
    return runners.run(["python", "-m", "flake8", "taskr/*.py"])

# Run all static tools
def all():
    return runners.run_conditional(flake, fmt, sp.function)
```

### run_output
`run_output`' will run a command and return the output

```python
from taskr import runners

# Get the number of env variables
def _get_count():
    ret = runners.run_output("env | wc -l")
    print(ret.status) # True 
    print(ret.stdout) # "90"
    print(ret.sterr)  # ""
```

You can an environment dict to this function.

## Passing arguments to functions

You can also pass arbitrary arguments to any defined function. For example, passing the environment to starting a server.
This requires the function to have a default argument set.

```python
def start(env: str = "Dev"):
  ENVS = {
    "ENV": env
    "WATCH": "true"
  }
  return taskr.run("python start.py", ENVS)

```

And from the command line
```bash
taskr start dev
# Or
taskr start
# Or
taskr start prod

```

Arguments are passed in order they are typed.

## Utilities

There are a few utility functions included, mostly for python package development.

```python
from taskr import utils

# Removes dist/build folders
utils.cleanBuilds()

# Remove compiled filed and folders
utils.cleanCompiles()

# In a venv or not
utils.inVenv()

# Reads an ENV file into a dict, e.g. env=dev
utils.readEnvFile(filename)

# Bumps setup.py's version number by 0.0.1, or replaces it with argument
utils.bumpVersion(version=None):

# Adds `export TASKR_DIR=CWD' to your VENV activation, so
# you can use taskr from any location in the VENV
utils.addTaskrToEnv()
```

## Developing

This project uses pipenv. Make sure it's installed. Then call
```bash
python -m pipenv shell
pipenv install --dev
taskr test
```

There are numerous tests in ```taskr/tests``` which cover most functionality that's testable


