Package: taskr-cli
TaskrA magical, zero dependency, easy to use task runner with an original name. Inspired byMage, a make-like tool for go. Made for python projects, but usable for any.All that's needed is a tasks.py file.A few highlights:Basically make(1) without a build systemZero dependenciesAuto load environment variable filesEasily pass arguments to tasks from the command lineAuto generated cli documentationUsable in any subdirectory of your projectBuilt in functions to easily run system commands inside virtual environmentsBuilt in helper functions for python developmentInstallingpipinstalltaskr-cliCheck the versiontaskr--versionGenerate a default tasks filetaskr--initUsingMake sure you have a tasks.py file defined in the root of your repo.taskrcan be used from any sub directory ifPYENV_DIRor 'TASKR_DIR' is set to the projects root. There is a utility function "injectPath()" that can do this for you, included in the template. See other utility functions at the bottom of the readme.CLI:[master●]»taskr-h
usage:taskr[-h][-d][-i][-l][-p][-v]Acliutilitytorungenerictasks

options:-h,--helpshowthishelpmessageandexit-i,--initgenerateatemplatetaskfile-l,--listshowdefinedtasks-v,--versionshowtheversionnumberWhen listing tasks, taskr will attempt to grab either the docblock or a single # comment above the function name and show it for cli documentation. Taskr will prefer the single # comment over the docblock to display if both exist.Also note, any functions intasks.pythat start with an underscore are ignored when listing. Bellow's an example print out of taskr with a validtask.pyfile.[master●]»taskr-l

Tasks:build:Buildsawheelfilecheck:Runallstaticanalysistoolsclean:Removebuildartifacts,cache,etc.fmt:Runblackmypy:Checktypes*reinstall:Re-installstaskrruff:Runruffsort:Sortimportstest:Runtestsupload:UploadprojecttoPYPI

*=defaultTo run a task, just pass the name of a function aftertaskr. Output from a task will be displayed[master●]»taskrformat
Alldone!✨🍰✨11filesleftunchanged.Configuration VariablesThere are a few configuration setting, set in tasks.py itself. They are all uppercase and generally should be at the top of the fileVENV_REQUIRED = Truein your tasks.py file, taskr will only run if it detects it's running in a virtual environment. You can delete it otherwiseDEFAULT = "some_func"marks the task as default. Default tasks are run whentaskris run without any argumentsENV = path/to/file.envwill load that environment file before every taskfromtaskrimportrunnersDEFAULT="test"VENV_REQUIRED=TrueENVS="dev.env"# Run tests, and passed dev.env vars when running 'taskr' in the clideftestrunners.run("python -m pytest tests/")Helpful functions for running tasksA few task running methods are provided for system running tasks. Taskr expects task functions to return eitherTrue(The task was successful) forFalseit failed. To determine if a subprocess/system call 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.You can also run any code you want as well under a task, these are just helpful wrappers around subprocess that work nicely with taskr.runrun's argument can be either a list, or a string. A list is parsed into one command, not multipleOptionally pass a an environment dictionary to be used at runtime.fromtaskrimportrunners# Run flake8defflake_list()->bool:returnrunners.run(["python","-m","flake8","taskr/*.py"])# Run testsdefflake()->bool:returnrunners.run("python -m pytest tests/ -v")# Build a wheeldefbuild():ENV={"PRODUCTION":"true"}returnrunners.run("python setup.py install",ENV)run_conditionalrun_conditionalis 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. As of the current release, you cannot pass arguments to functions passed torun_conditional.fromtaskrimportrunnersimportsome_packageassp# Run blackdeffmt():returnrunners.run("python -m black .")# Check flake8defruff():returnrunners.run("python -m ruff")# Run all static toolsdefall():returnrunners.run_conditional(flake,fmt,sp.function)run_outputrun_output' will run a command and return the outputfromtaskrimportrunners# Get the number of env variablesdefget_count():ret=runners.run_output("env | wc -l")print(ret.status)# Trueprint(ret.stdout)# "90"print(ret.sterr)# ""You can an environment dict to this function.Passing arguments to functionsYou 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.defstart(env:str="Dev"):ENVS={"ENV":env"WATCH":"true"}returntaskr.run("python start.py",ENVS)And from the command linetaskrstartdev# Ortaskrstart# OrtaskrstartprodYou can also use key word arguments so pass only selected arguments. This requires all previous arguments to have a default value.defstart(env:str="dev",timeout:int=180):ENVS={"ENV":env"WATCH":"true""TIMEOUT":timeout}returntaskr.run("python start.py",ENVS)Only passing timeout in this example, and keeping env to be the defaultdevtaskrstarttimeout=60UtilitiesThere are a few utility functions included, mostly for python package development. These are not the main focus of the package and more will probably not be added, rather spun out into a different packagefromtaskrimportutils# Removes dist/build foldersutils.cleanBuilds()# Remove compiled files and folders (.pyc, __pycache__)utils.cleanCompiles()# In a venv or notutils.inVenv()# In a container (docker, podman) or notutils.inContainer()# Transforms an ENV file into a dictutils.readEnvFile(filename=None)# Bumps setup.py's version number by 0.0.1, or replaces it with argumentutils.bumpVersion(version=None,variable="version",filename="setup.py"):# Adds `export TASKR_DIR=CWD' to your VENV activation, so# you can use taskr from any location in the VENV (e.g. sub directories)# Probably don't use thisutils.addTaskrToEnv()DevelopingThis project uses pipenv. Make sure it's installed. Then callpython-mpipenvshell
pipenvinstall--dev
taskrcheck
taskrtestThere are numerous tests intaskr/testswhich cover most functionality that's testable, as well as examples