Skip to main content

pycommands

CircleCI Codecov

Handle a list of commands that should be executed easily and with undo support.

How to use

Install

pycommands is available on PyPI

pip install pycommands

Basic usage

Definition of commands

from commands.base import BaseCommand
from commands.exceptions import CommandException
from commands.invoker import Invoker


class Command1(BaseCommand):
    def build(self):
        return "touch content.txt"

    def build_undo(self):
        return "rm content.txt"


class Command2(BaseCommand):
    def build(self):
        return "mv content.txt content-replaced.txt"

    def build_undo(self):
        return "mv content-replaced.txt content.txt"


class InvalidCommand(BaseCommand):
    def build(self):
        raise CommandException()

Simple default execution with success commands

from commands.invoker import Invoker


invoker = Invoker()

invoker.execute([
    Command1(),
    Command2(),
], run_undo=False)

# output
running command: touch content.txt
running command: mv content.txt content-replaced.txt


# If a invoker.undo() is called then all commands undo operation will be done in the LIFO order.

invoker.undo()

# output
running undo command: mv content-replaced.txt content.txt
running undo command: rm content.txt


# If a invoker.execute() is called with run_undo as True, then the undo operation will be done always
# that a command raise CommandException

invoker = Invoker()

invoker.execute([
    Command1(),
    Command2(),
    InvalidCommand(),
], run_undo=True)

# output
running command: touch content.txt
running command: mv content.txt content-replaced.txt
running command: touch content.txt
running command: mv content.txt content-replaced.txt
running undo command: mv content-replaced.txt content.txt
running undo command: rm content.txt

How to contribute

We welcome contributions of many forms, for example:

  • Code (by submitting pull requests)
  • Documentation improvements
  • Bug reports and feature requests

Setting up for local development

We use pipenv to manage dependencies, so make sure you have it installed.

Creating environment

/<project-path>/pipenv install --python=3

Activing environment

/<project-path>/pipenv shell

Install pre-commit hooks:

pre-commit install

Run tests by evoking pytest:

pytest

That's it! You're ready from development

Metadata

Release files for pycommands 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycommands 0.1.0
File Size Uploaded Provenance
pycommands-0.1.0.tar.gz 4.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pycommands 0.1.0
File Interpreter ABI Platform
pycommands-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.8 kB

Release files / pycommands-0.1.0.tar.gz

Download URL pycommands-0.1.0.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
07e6c6e8a02dffb4414470654c5811df1daace75eaf06ff659af9840ff300d61
BLAKE2b-256 checksum
How to use checksums
cc80e0552c5cd413fb37f8c1e7ddfd0bbfcef06a89f24b043b0afc95f5401a58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.4

Release files / pycommands-0.1.0-py3-none-any.whl

Download URL pycommands-0.1.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3822c15a7dea8179e7a273d0d2250f1e64c5b49dd4d8ea6ef4b8a6cc9c553c4c
BLAKE2b-256 checksum
How to use checksums
945b729ec06f3d8284f4c00852cc250d5a687384a64b7b1fb653f88aba6ac618
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.4

Security for pycommands 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page