Skip to main content

Convenience methods for file/process operations

Project description

Convenience methods for file/process operations

Version on pypi Travis CI codecov Python versions tested (link to github project)

Overview

runez is a small convenience library for common operations I found myself rewriting multiple times.

It comes in handy for programs that need to run other programs, or copy/move files etc.

The name was initially meant as “run ez” (“run easy”), the fact that it sounds like “runes” gives it a bit of a mystery/magic side that’s also relatively appropriate (it does indeed concentrate a bit of invocation magic, as you can save quite a few lines of repetitive code by using it)

Features

  • Support for dryrun mode (show what would be done, but don’t do it)

  • Perform most typical logging setups in one call to runez.log.setup()

  • Log operations systematically (at debug level mostly), examples:

    Running: foo ...
    Copy foo -> bar
    Would move foo -> bar    (for dryrun)
  • CaptureOutput context manager -> grab output/logging from any code section

  • Take care of most edge cases, with nice errors

  • Functions can be called without checking for return code etc (abort by default, with nice error)

  • They can also be called with fatal=False, in which case the return value will indicate whether call succeeded or not

  • 100% test coverage

Example

Run a program:

import runez

# Aborts if "foo" doesn't exist
output = runez.run("ls", "foo")

# Output can also be ignored
runez.run("ls", "foo")

# Don't capture output, just run the command and let output "pass through"
runez.run("ls", "foo", stdout=None, stderr=None)

# Don't abort, return False on failure (or actual output when successful)
output = runez.run("ls", "foo", fatal=False)

File operations:

import runez

runez.touch("foo")
runez.copy("foo", "bar")
runez.move("foo", "baz")
runez.delete("foo")

runez.write("foo", "bar\nbaz\n")
first = runez.first_line("foo")
lines = runez.get_lines("foo")

full_path = runez.resolved_path("foo/bar")
folder = runez.parent_folder(full_path)
runez.ensure_folder(folder)
with runez.Anchored(folder):
    assert runez.short(full_path) == "bar"

Installation

As usual, available on pypi: pip install runez

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

runez-1.6.12.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

runez-1.6.12-py2.py3-none-any.whl (37.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file runez-1.6.12.tar.gz.

File metadata

  • Download URL: runez-1.6.12.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for runez-1.6.12.tar.gz
Algorithm Hash digest
SHA256 5c71b97909ce4c6d5e18450de3f19525a89dfafdc631ebaf6e954bbcdb57503a
MD5 1b71b97caee6c65f017126a9248130fe
BLAKE2b-256 1d3ba6cda5d51e64131f5e1993cd3eb59aacb7a8932e92a9c1dba1d45bc94c67

See more details on using hashes here.

Provenance

File details

Details for the file runez-1.6.12-py2.py3-none-any.whl.

File metadata

  • Download URL: runez-1.6.12-py2.py3-none-any.whl
  • Upload date:
  • Size: 37.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for runez-1.6.12-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5ea38fb0a62ae3ca16b43ba0698c74e2d995b855d57e36a6cd2d52f6c93d5718
MD5 563f9838737a0b00d33581d18cd648ba
BLAKE2b-256 eacaa242cb8f0041f3614b0f605c45f87e0d7ea5945ef424a43ff76f94e3d9a6

See more details on using hashes here.

Provenance

Supported by

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