Skip to main content

In its highest aspirations, pytask tries to be pytest as a build system.

Project description

PyPI PyPI - Python Version https://anaconda.org/pytask/pytask/badges/version.svg https://anaconda.org/pytask/pytask/badges/platforms.svg PyPI - License https://readthedocs.org/projects/pytask-dev/badge/?version=latest https://github.com/pytask-dev/pytask/workflows/Continuous%20Integration%20Workflow/badge.svg?branch=main https://codecov.io/gh/pytask-dev/pytask/branch/main/graph/badge.svg pre-commit.ci status https://img.shields.io/badge/code%20style-black-000000.svg

In its highest aspirations, pytask tries to be pytest as a build system. It’s main purpose is to facilitate reproducible research by automating workflows in research projects. Its features include:

  • Automatic discovery of tasks.

  • Lazy evaluation. If a task, its dependencies, and its products have not changed, do not execute it.

  • Debug mode. Jump into the debugger if a task fails, get feedback quickly, and be more productive.

  • Select tasks via expressions. Run only a subset of tasks with expressions and marker expressions known from pytest.

  • Easily extensible with plugins. pytask’s architecture is based on pluggy, a plugin management framework, so that you can adjust pytask to your needs. Plugins are, for example, available for parallelization, LaTeX, R, and Stata. Read here how you can use plugins.

Why do I need a build system?

Read the section in the documentation if you do not know or are not convinced that you need a build system.

Installation

pytask is available on PyPI and on Anaconda.org. Install the package with

$ pip install pytask

# or

$ conda config --add channels conda-forge --add channels pytask
$ conda install pytask

Usage

A task is a function which is detected if the module and the function name are prefixed with task_. Here is an example.

# Content of task_hello.py.

import pytask


@pytask.mark.produces("hello_earth.txt")
def task_hello_earth(produces):
    produces.write_text("Hello, earth!")

Here are some details:

  • Dependencies and products of a task are tracked via markers. For dependencies use @pytask.mark.depends_on and for products use @pytask.mark.produces. Use strings and pathlib.Path to specify the location. Pass multiple dependencies or products as a list.

  • With produces (and depends_on) as function arguments, you get access to the dependencies and products inside the function via pathlib.Path objects. Here, produces holds the path to "hello_earth.txt".

To execute the task, type the following command on the command-line

$ pytask
========================= Start pytask session =========================
Platform: linux -- Python 3.x.y, pytask 0.x.y, pluggy 0.x.y
Root: xxx
Collected 1 task(s).

.
====================== 1 succeeded in 1 second(s) ======================

Demo

The demo walks you through the following steps.

  1. Write an executable script which produces a text file like you would normally do without pytask.

  2. Rewrite the script to a pytask task.

  3. Execute the task.

  4. Add a task which produces a second text file and another task which merges both text files.

  5. Execute all three tasks.

https://github.com/pytask-dev/misc/raw/main/gif/workflow.gif

Documentation

The documentation can be found under https://pytask-dev.readthedocs.io/en/latest with tutorials and guides for best practices.

Changes

Consult the release notes to find out about what is new.

License

pytask is distributed under the terms of the MIT license.

The license also includes a copyright and permission notice from pytest since some modules, classes, and functions are copied from pytest. Not to mention how pytest has inspired the development pytask in general. Without the amazing work of Holger Krekel and pytest’s many contributors, this project would not have been possible. Thank you!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytask-0.0.12.tar.gz (70.3 kB view details)

Uploaded Source

Built Distribution

pytask-0.0.12-py3-none-any.whl (63.0 kB view details)

Uploaded Python 3

File details

Details for the file pytask-0.0.12.tar.gz.

File metadata

  • Download URL: pytask-0.0.12.tar.gz
  • Upload date:
  • Size: 70.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for pytask-0.0.12.tar.gz
Algorithm Hash digest
SHA256 bf5cd9f63128136373cc8623f5677b933b084b459dc83f73aed3861e7ecfae0c
MD5 7d67d2c0c3b5af52d190f3bfef60bc5d
BLAKE2b-256 9724b8ba65a3d09063455a73879dc95d1b04195ca366b7c33c2546e8a0a13758

See more details on using hashes here.

File details

Details for the file pytask-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: pytask-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 63.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for pytask-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 847a0e795c896ae0d3c2e8b9556559baffade57b0691847176abd1f746044c40
MD5 0531fedf00bf39e3fa1a71b5f63df473
BLAKE2b-256 24998bf4f386eff92671fcb4080ba7d4a9b9bad1fa559abfad3725d23789c59d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page