### Install with pixi Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/set_up_a_project.md Automatically creates the environment and installs dependencies using pixi, ensuring they are up-to-date. ```console $ pixi install ``` -------------------------------- ### Install with uv Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/set_up_a_project.md Installs all packages using uv, ensuring dependencies are up-to-date. ```console $ uv sync ``` -------------------------------- ### Editable Install with pip Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/set_up_a_project.md Creates an editable install with pip, making changes in source files immediately available. ```console $ pip install -e . ``` -------------------------------- ### Display pytask help page Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/installation.md Displays the main help page for pytask, listing all available commands and options. This is used to verify the installation. ```console $ pytask --help ``` -------------------------------- ### pytask CLI Dry Run Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/_static/md/dry-run.md This snippet shows the output of the `pytask --dry-run` command. It details the session start, platform information, root directory, collected tasks, and a summary of the dry run execution, indicating which tasks would have been executed. ```console $ pytask --dry-run ────────────────────────── Start pytask session ───────────────────────── Platform: win32 -- Python 3.12.0, pytask 0.5.3, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓ ┃ Task ┃ Outcome ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━┩ │ C:\Users\pytask-dev\git\my_project\task_dry_run.py::task_dry_run │ w └───────────────────────────────────────────────────┴─────────┘ ───────────────────────────────────────────────────────────────────────── ╭─────────── Summary ──────────────╮ │ 1 Collected task │ │ 1 Would be executed (100.0%) │ ╰──────────────────────────────────╯ ─────────────────────── Succeeded in 0.02 seconds ─────────────────────── ``` -------------------------------- ### Install pytask with uv Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/installation.md Installs pytask using the uv package manager. uv is a modern and fast Python package installer. ```console $ uv add pytask ``` -------------------------------- ### Install with conda/mamba Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/set_up_a_project.md Creates a conda environment from environment.yml and activates it. Supports both conda and mamba. Editable install is handled via environment.yml. ```console $ conda env create -f environment.yml $ conda activate my_project ``` ```console $ mamba env create -f environment.yml $ mamba activate my_project ``` -------------------------------- ### Install pytask with pixi Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/installation.md Installs pytask using the pixi package manager. pixi is a tool for reproducible Python environments. ```console $ pixi add pytask ``` -------------------------------- ### Display command-specific help Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/installation.md Displays help for a specific pytask command. Replace '' with the actual command you need help with. ```console $ pytask --help ``` -------------------------------- ### Install pytask Source: https://github.com/pytask-dev/pytask/blob/main/README.md Instructions for installing pytask using package managers like uv, pixi, pip, conda, or mamba. ```console $ uv add pytask ``` ```console $ pixi add pytask ``` -------------------------------- ### Install pytask and pytask-parallel Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/how_to_guides/migrating_from_scripts_to_pytask.md Installs the pytask library and the pytask-parallel plugin using pip or conda. ```console $ pip install pytask pytask-parallel $ conda -c conda-forge pytask pytask-parallel ``` -------------------------------- ### pytask CLI Session Start and Execution Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/_static/md/migrating-from-scripts-to-pytask.md Demonstrates the typical output when running the pytask command. It shows the session start, environment details (platform, Python version, pytask version), the root directory, collected tasks, their execution status, and a final summary of the session's success. ```console $ pytask ────────────────────────── Start pytask session ───────────────────────── Platform: win32 -- Python 3.12.0, pytask 0.5.3, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ``` -------------------------------- ### Console Example: Installing deepdiff Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/how_to_guides/hashing_inputs_of_tasks.md Provides instructions for installing the `deepdiff` library, which can be used to create hash functions for unhashable Python objects. ```console pip install deepdiff conda install deepdiff ``` -------------------------------- ### pytask Session Start and Task Collection Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/_static/md/collect-nodes.md This snippet shows the typical output when starting a pytask session. It includes information about the operating system, Python version, pytask version, and the root directory of the project. It also lists the collected tasks, their file locations, dependencies, and products. ```console $ pytask ────────────────────────── Start pytask session ───────────────────────── Platform: win32 -- Python 3.12.0, pytask 0.5.3, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. Collected tasks: └── 🐍 └── 📝 ├── 📄 └── 📄 ───────────────────────────────────────────────────────────────────────── ``` -------------------------------- ### pytask CLI Session Start Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/_static/md/persist-persisted.md Demonstrates the initial output when starting a pytask session. It shows the operating system, Python version, pytask version, pluggy version, and the project's root directory. It also indicates the number of tasks collected. ```console $ pytask ────────────────────────── Start pytask session ───────────────────────── Platform: win32 -- Python 3.12.0, pytask 0.5.3, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓ ┃ Task ┃ Outcome ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━┩ │ task_module.py::task_make_input_bold │ p │ └────────────────────────────────────────────────┴─────────┘ ───────────────────────────────────────────────────────────────────────── ╭─────────── Summary ────────────╮ │ 1 Collected tasks │ │ 1 Persisted (100.0%) │ ╰────────────────────────────────╯ ──────────────────────── Succeeded in 0.0 seconds ─────────────────────── ``` -------------------------------- ### Install pytask with pip Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/installation.md Installs pytask using the traditional pip package manager. This is a common method for installing Python packages. ```console $ pip install pytask ``` -------------------------------- ### pytask CLI Session Start and Execution Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/_static/md/persist-executed.md This snippet demonstrates the typical output when running the pytask command. It shows the session start, platform information, project root, collected tasks, their execution status (succeeded in this case), and a summary of the session. ```console $ pytask ────────────────────────── Start pytask session ───────────────────────── Platform: win32 -- Python 3.12.0, pytask 0.5.3, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ``` -------------------------------- ### pytask CLI Session Start Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/_static/md/collect.md Demonstrates the initial output when starting a pytask session. It displays the operating system, Python version, pytask version, pluggy version, project root directory, and the number of tasks collected along with their details. ```console $ pytask ────────────────────────── Start pytask session ───────────────────────── Platform: win32 -- Python 3.12.0, pytask 0.5.3, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. Collected tasks: └── 🐍 └── 📝 ───────────────────────────────────────────────────────────────────────── ``` -------------------------------- ### Basic pytask Configuration Example Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/reference_guides/configuration.md Demonstrates the basic structure for configuring pytask within the pyproject.toml file, specifically setting the editor_url_scheme. ```toml [tool.pytask.ini_options] editor_url_scheme = "vscode" ``` -------------------------------- ### pytask Documentation Navigation Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/index.md This snippet outlines the main sections of the pytask documentation, including tutorials, how-to guides, explanations, and reference guides. It also lists additional topics and provides a link to the GitHub repository. ```APIDOC Project: /pytask-dev/pytask Documentation Sections: - Tutorials: For getting started with pytask and managing your first project. - How-to Guides: For specific and advanced tasks and best practices. - Explanations: For key topics and concepts underlying the package. - Reference Guides: For implementation details and developer entry-points. Additional Topics: - plugin_list - type_hints - developers_guide - glossary - changes External Link: - On Github: https://github.com/pytask-dev/pytask ``` -------------------------------- ### pytask Custom Marks Example Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/reference_guides/api.md Example demonstrating how to create and apply custom marks using the pytask.mark factory as decorators. ```python @pytask.mark.timeout(10, "slow", method="thread") def task_function(): ... @pytask.mark.timeout(10, "slow", method="thread") @pytask.mark.slow def task_function(): ... ``` -------------------------------- ### Install pytask-r Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/how_to_guides/migrating_from_scripts_to_pytask.md Installs the pytask-r plugin for integrating R scripts with pytask using pip or conda. ```console $ pip install pytask-r $ conda install -c conda-forge pytask-r ``` -------------------------------- ### Project Configuration with conda/mamba Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/set_up_a_project.md Configuration for a project using 'conda' or 'mamba'. It includes an environment.yml for dependencies and an editable install, and a pyproject.toml for project metadata and pytask configuration. ```yaml name: my_project channels: - conda-forge dependencies: - python>=3.9 - pytask - pip - pip: - -e . ``` ```toml [project] name = "my_project" version = "0.1.0" requires-python = ">=3.9" [build-system] requires = ["hatchling"] build-backend = "hatchling" [tool.pytask.ini_options] paths = ["src/my_project"] ``` -------------------------------- ### Run Pytask Session Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/_static/md/try-first.md This snippet shows the output of a pytask session, including task collection, execution, and a summary of the results. It demonstrates how pytask displays task outcomes and overall success rate. ```Console $ pytask -s ────────────────────────── Start pytask session ───────────────────────── Platform: win32 -- Python 3.12.0, pytask 0.5.3, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 2 task. I'm first I'm second ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓ ┃ Task ┃ Outcome ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━┩ │ task_example.py::task_first │ . │ │ task_example.py::task_second │ . │ └───────────────────────────────┴─────────┘ ───────────────────────────────────────────────────────────────────────── ╭─────────── Summary ────────────╮ │ 2 Collected tasks │ │ 2 Succeeded (100.0%) │ ╰────────────────────────────────╯ ─────────────────────── Succeeded in 0.11 seconds ────────────────────── ``` -------------------------------- ### Example pytask Task Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/collecting_tasks.md This Python code defines a simple pytask task with a dependency and a product, demonstrating how tasks are structured. ```python from pytask import Product, Task def task_example(product: Product = Product("example.txt")): with open(product, "w") as f: f.write("This is an example task.") ``` -------------------------------- ### pytask Product Annotation Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/reference_guides/api.md Example of using the pytask.Product annotation to mark arguments of tasks as products. ```python from pathlib import Path from pytask import Product from typing import Annotated def task_example(path: Annotated[Path, Product]) -> None: path.write_text("Hello, World!") ``` -------------------------------- ### Command-Specific Help Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/invoking_pytask.md Shows how to get help for a specific pytask command. ```console $ pytask -h/--help ``` -------------------------------- ### pytask Documentation Structure Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/reference_guides/index.md Thistoctree directive outlines the structure of the pytask reference documentation, indicating the main sections available for users to explore. ```rst ```{toctree} --- maxdepth: 1 --- command_line_interface configuration hookspecs api ``` ``` -------------------------------- ### Repeating Tasks with `produces` Example Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/repeating_tasks_with_different_inputs.md Demonstrates repeating tasks where the `produces` argument is dynamically generated or managed. ```python from pathlib import Path from typing import Annotated from pytask import Product, task ID_TO_KWARGS = { "first": {"i": 0, "produces": "out_0.txt"}, "second": {"i": 1, "produces": "out_1.txt"}, "third": {"i": 2, "produces": "out_2.txt"}, } for id_, kwargs in ID_TO_KWARGS.items(): @task(id=id_, kwargs=kwargs) def task_create_random_data(i: int, produces: Annotated[Path, Product]) -> None: """Create a random file. Parameters ---------- i : int A parameter that is different for each task. produces : Path The path to the product of the task. """ with open(produces, "w") as f: f.write(f"This is file {i}.") ``` -------------------------------- ### Define a pytask task Source: https://github.com/pytask-dev/pytask/blob/main/README.md Example of defining a basic pytask task function that creates a file with content. It demonstrates the use of `pytask.Product` annotation for specifying output files. ```python # Content of task_hello.py. from pathlib import Path from pytask import Product from typing import Annotated def task_hello_earth(path: Annotated[Path, Product] = Path("hello_earth.txt")): path.write_text("Hello, earth!") ``` -------------------------------- ### Example Task Module Structure Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/how_to_guides/bp_structure_of_task_files.md Demonstrates the recommended structure for a pytask task module, with the task function as the public interface and private helper functions for internal logic. This structure promotes readability and maintainability. ```python import pytask def task_example_function(depends_on): """This is the main task function. It handles IO operations and calls private helper functions. Args: depends_on: A dependency for this task. Returns: The result of the task. """ # IO operations like loading data data = _load_data(depends_on) # Call private helper function result = _process_data(data) # IO operations like saving results _save_result(result) return result def _load_data(file_path): """Private helper function to load data.""" # Implementation for loading data pass def _process_data(data): """Private helper function to process data.""" # Implementation for processing data pass def _save_result(result): """Private helper function to save the result.""" # Implementation for saving the result pass ``` -------------------------------- ### Project Configuration with pixi Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/set_up_a_project.md Configuration for a project using the 'pixi' package manager. It includes project details, channels, platforms, dependencies, and pytask configuration. ```toml [project] name = "my_project" version = "0.1.0" requires-python = ">=3.9" channels = ["conda-forge"] platforms = ["linux-64", "osx-64", "osx-arm64", "win-64"] [build-system] requires = ["hatchling"] build-backend = "hatchling.build" [dependencies] pytask = "*" python = ">=3.9" [tool.pytask.ini_options] paths = ["src/my_project"] ``` -------------------------------- ### Install pytask with conda Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/installation.md Installs pytask using the conda package manager from the conda-forge channel. This is suitable for users who manage their environments with conda. ```console $ conda install -c conda-forge pytask ``` -------------------------------- ### Project Configuration with uv Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/set_up_a_project.md Configuration for a project using the 'uv' package manager. It specifies project metadata, build system, and pytask-specific options like the task discovery path. ```toml [project] name = "my_project" version = "0.1.0" requires-python = ">=3.9" dependencies = ["pytask"] [build-system] requires = ["uv_build"] build-backend = "uv_build" [tool.pytask.ini_options] paths = ["src/my_project"] ``` -------------------------------- ### Project Configuration with pip and requirements.txt Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/set_up_a_project.md Configuration for a project using 'pip'. It includes a pyproject.toml for project metadata and build system, and a requirements.txt file for dependencies. ```toml [project] name = "my_project" version = "0.1.0" requires-python = ">=3.9" dependencies = ["pytask"] [build-system] requires = ["hatchling"] build-backend = "hatchling.build" [tool.pytask.ini_options] paths = ["src/my_project"] ``` ```text pytask ``` -------------------------------- ### Define Source and Build Paths in config.py Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/set_up_a_project.md This Python snippet demonstrates how to define the source ('SRC') and build ('BLD') directories using pathlib. These paths are crucial for pytask to locate project files and outputs. ```python from pathlib import Path SRC = Path(__file__).parent.resolve() BLD = SRC.joinpath("..", "..", "bld").resolve() ``` -------------------------------- ### Install pygraphviz with Conda Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/visualizing_the_dag.md Installs the pygraphviz library using the conda package manager from the conda-forge channel. ```console conda install -c conda-forge pygraphviz ``` -------------------------------- ### pytask CLI Help and Commands Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/_static/md/help-page.md Displays the main help message for the pytask CLI, listing all available commands and their brief descriptions. This includes commands for building, cleaning, collecting tasks, visualizing the DAG, showing markers, and profiling resource consumption. ```console $ pytask --help
pytask v0.5.3
Usage: pytask [OPTIONS] [COMMAND] [PATHS] Manage your tasks with pytask. ╭─ Commands ────────────────────────────────────────────────────────────╮ build * Collect tasks, execute them and report the results. clean Clean the provided paths by removing files unknown to pytask. collect Collect tasks and report information about them. dag Create a visualization of the directed acyclic graph. markers Show all registered markers. profile Show information about resource consumption ╰───────────────────────────────────────────────────────────────────────╯ ╭─ Options ─────────────────────────────────────────────────────────────╮ --version Show the version and exit. -h --help Show this message and exit. ╰───────────────────────────────────────────────────────────────────────╯

https://pytask-dev.readthedocs.io

``` -------------------------------- ### Persisting Task Example Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/making_tasks_persist.md Demonstrates how to create a task that persists by applying the `@pytask.mark.persist` decorator. This example shows the initial execution when the product is missing and subsequent skips when the task is marked to persist. ```python import pytask def task_persist_example(product): """ A simple task that creates a product. """ with open(product, "w") as f: f.write("This task persists.") @pytask.mark.persist def task_persist_example_decorated(product): """ A task decorated with @pytask.mark.persist. """ with open(product, "w") as f: f.write("This task is decorated and persists.") ``` -------------------------------- ### Start pytask Session Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/_static/md/try-last.md Initiates a pytask session, displaying platform details, Python and pytask versions, the project root, and the number of collected tasks. It then lists each task and its execution outcome. ```console $ pytask -s ────────────────────────── Start pytask session ──────────────────────── Platform: win32 -- Python 3.12.0, pytask 0.5.3, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 2 task. I'm second I'm first ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓ ┃ Task ┃ Outcome ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━┩ │ task_example.py::task_first │ . │ │ task_example.py::task_second │ . │ └───────────────────────────────┴─────────┘ ───────────────────────────────────────────────────────────────────────── ╭─────────── Summary ────────────╮ │ 2 Collected tasks │ │ 2 Succeeded (100.0%) │ ╰────────────────────────────────╯ ─────────────────────── Succeeded in 0.11 seconds ─────────────────────── ``` -------------------------------- ### Run pytask with Trace Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/_static/md/trace.md Demonstrates how to run pytask with the --trace flag to see detailed session information, including platform, Python version, pytask version, and collected tasks. It also shows an example of entering the PDB debugger during task execution. ```console $ pytask --trace ──────────────────────────── Start pytask session ──────────────────────────── Platform: win32 -- Python 3.12.0, pytask 0.5.3, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. >>>>>>>>>>>>>>>>>> PDB runcall (IO-capturing turned off) >>>>>>>>>>>>>>>>>> > ...\git\my_project\task_create_random_data.py(13)task_create_random_data() -> rng = np.random.default_rng(0) (Pdb) ``` -------------------------------- ### Basic pytask Invocation and Help Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/invoking_pytask.md Demonstrates the fundamental ways to invoke pytask and access its help information. ```console $ pytask $ pytask --version $ pytask -h | --help ``` -------------------------------- ### Configure Database URL Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/reference_guides/configuration.md Illustrates how to specify a custom database URL for pytask, including an example for an SQLite database. ```toml database_url = "sqlite:///.pytask/pytask.sqlite3" ``` -------------------------------- ### Run pytask with Verbose Output Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/_static/md/persist-skipped.md Demonstrates the output of the pytask CLI when executed with the '--verbose 2' flag. This includes session start, environment details, task collection, execution outcomes, and a summary. ```console $ pytask --verbose 2 ────────────────────────── Start pytask session ───────────────────────── Platform: win32 -- Python 3.12.0, pytask 0.5.3, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓ ┃ Task ┃ Outcome ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━┩ │ task_module.py::task_make_input_bold │ s │ └────────────────────────────────────────────────┴─────────┘ ───────────────────────────────────────────────────────────────────────── ╭──────────────── Summary ─────────────────╮ │ 1 Collected tasks │ │ 1 Skipped because unchanged (100.0%) │ ╰──────────────────────────────────────────╯ ──────────────────────── Succeeded in 0.0 seconds ─────────────────────── ``` -------------------------------- ### Task Using Nested Data Catalogs Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/how_to_guides/the_data_catalog.md An example of a pytask task that utilizes nested DataCatalogs to manage and return fitted models. ```python from pathlib import Path from pytask import task from typing import Annotated from my_project.config import DATA_NAMES from my_project.config import MODEL_NAMES from my_project.config import nested_data_catalogs for model_name in MODEL_NAMES: for data_name in DATA_NAMES: @task def fit_model( path: Path = Path("...", data_name), ) -> Annotated[ Any, nested_data_catalogs[model_name][data_name]["fitted_model"] ]: data = ... fitted_model = ... return fitted_model ``` -------------------------------- ### Defining Dependencies and Products in pytask Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/how_to_guides/migrating_from_scripts_to_pytask.md Shows how to specify task dependencies and products using function arguments with default values. Products are annotated with `Annotated[Path, Product]`. Dictionaries can be used for multiple dependencies or products. ```python from pathlib import Path from typing import Annotated from pytask import Product def task_process_data( depends_on: Path = "data.csv", product: Annotated[Path, Product] = "processed_data.csv", ): # Process data pass def task_multiple_dependencies_products( depends_on: dict[str, Path] = { "data1": "data1.csv", "data2": "data2.csv", }, products: dict[str, Annotated[Path, Product]] = { "result1": "result1.csv", "result2": "result2.csv", }, ): # Process multiple files pass ``` -------------------------------- ### Use Custom Debugger Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/debugging.md Allows the use of a custom debugger by specifying its importable path. This example switches to IPython's debugger implementation. ```console pytask --pdbcls=IPython.terminal.debugger:TerminalPdb ``` -------------------------------- ### Define Multiple Dependencies and Products (Python 3.10+) Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/defining_dependencies_products.md Demonstrates defining multiple dependencies and products for a pytask task using Python 3.10+ syntax. It shows how to group inputs and outputs using dictionaries. ```python from pytask import task from pytask import File @task def task_group_dependencies_and_products_py310_plus(): return dict(a=File("a.txt"), b=File("b.txt")) @task def task_group_dependencies_and_products_py310_plus_2(a, b): pass ``` -------------------------------- ### Pytask execution with warning capture Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/_static/md/warning.md This snippet shows the output of a pytask execution. It includes the platform information, the number of collected tasks, the outcome of the task, a summary of the execution, and a captured warning with a link to the documentation. ```Text $ pytask ────────────────────────── Start pytask session ───────────────────────── Platform: win32 -- Python 3.12.0, pytask 0.5.3, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓ ┃ Task ┃ Outcome ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━┩ │ task_warning.py::task_warning │ . │ └───────────────────────────────────────────────────┴─────────┘ ───────────────────────────────────────────────────────────────────────── ╭─────────── Summary ────────────╮ │ 1 Collected tasks │ │ 1 Succeeded (100.0%) │ ╰────────────────────────────────╯ ─────────────────────── Succeeded in 0.24 seconds ────────────────────── ╭─────────────────────────────── Warnings ──────────────────────────────╮ │ task_warning.py::task_warning │ │ ...\my_project\task_warning.py:8: SettingWithCopyWarning: │ │ A value is trying to be set on a copy of a slice from a DataFrame.│ │ Try using .loc = value instead │ │ │ │ See the caveats in the documentation: │ │ https://pandas.pydata.org/pandas-docs/stable/user_guide/ │ │ indexing.html#returning-a-view-versus-a-copy │ │ df[df["a"] < 5]["b"] = 1 │ │ │ │ ♥ https://pytask-dev.rtfd.io/en/stable/how_to_guides/capture_warnings.html │ ╰───────────────────────────────────────────────────────────────────────╯ ``` -------------------------------- ### Nested Data Catalogs Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/how_to_guides/the_data_catalog.md Provides an example of creating nested DataCatalogs to manage data for different models and datasets, avoiding name collisions. ```python from pytask import DataCatalog MODEL_NAMES = ("ols", "logistic_regression") DATA_NAMES = ("data_1", "data_2") nested_data_catalogs = { model_name: { data_name: DataCatalog(name=f"{model_name}-{data_name}") for data_name in DATA_NAMES } for model_name in MODEL_NAMES } ``` -------------------------------- ### Relative Path Definition with Python 3.10+ Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/defining_dependencies_products.md Demonstrates defining relative dependencies and products using Python 3.10+ syntax. ```python from pytask import Product def task_example(product: Product = Product("output.txt")): pass ``` -------------------------------- ### Example Task Definition Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/how_to_guides/bp_complex_task_repetitions.md Demonstrates a basic task function that can be repeated across different dimensions, such as datasets or model specifications. ```python from pytask import Product, Task, depends_on, produces def task_example(data: Product, model: Product) -> Product: return Product("output.json") ``` -------------------------------- ### Trace Task Execution Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/debugging.md Enables tracing at the start of every task. This helps in understanding the execution flow and identifying where issues might arise. ```console pytask build --trace ``` -------------------------------- ### Define Multiple Dependencies and Products (Python 3.9) Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/defining_dependencies_products.md Demonstrates defining multiple dependencies and products for a pytask task using Python 3.9 syntax. It shows how to group inputs and outputs using dictionaries. ```python from pytask import task from pytask import File @task def task_group_dependencies_and_products_py38(): return dict(a=File("a.txt"), b=File("b.txt")) @task def task_group_dependencies_and_products_py38_2(a, b): pass ``` -------------------------------- ### Setuptools Entry-Point Configuration Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/how_to_guides/extending_pytask.md Details the configuration required in `pyproject.toml` to define a pytask plugin using setuptools entry-points. This includes specifying the package name, directory structure, and the plugin's entry-point name and module. ```toml [project] name = "pytask-plugin" [tool.setuptools.package-dir] "" = "src" [tool.setuptools.packages.find] where = ["src"] namespaces = false [project.entry-points.pytask] pytask_plugin = "pytask_plugin.plugin" ``` ```toml [build-system] requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"] [tool.setuptools_scm] write_to = "src/pytask_plugin/_version.py" ``` -------------------------------- ### Depend on a Task by Substring Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/defining_dependencies_products.md Example of defining a task dependency by passing a substring of the task function name to the `after` argument of the `@task` decorator. ```python @task(after="random_data") def task_plot_data(): ... ``` -------------------------------- ### Skip Task Example Source: https://github.com/pytask-dev/pytask/blob/main/docs/source/tutorials/skipping_tasks.md Demonstrates how to use the @pytask.mark.skip decorator to prevent a task from being executed. This is useful for temporarily disabling time-intensive tasks during development. ```python import pytask from pathlib import Path @pytask.mark.skip def task_that_takes_too_long(path: Path = Path("time_intensive_product.pkl")): """A task that is skipped during execution.""" pass ```