Concise layer on top of subprocess, similar to sh project
Project description
lagoon
Concise layer on top of subprocess, similar to sh project
Support
If you see an error along the lines of:
ImportError: cannot import name 'zyx' from 'lagoon'
This means the app requires command zyx
to be available, and you don't have it on your system.
The solution is to install zyx
in the usual way, e.g. via your package manager.
API
dkrcache
NORMAL
Accept normal outcomes.
ABRUPT
Accept abrupt outcomes.
ALWAYS
Accept all outcomes.
NEVER
Do not accept any outcome.
ExpensiveTask Objects
class ExpensiveTask()
Arbitrary task accelerated by Docker cache.
__init__
def __init__(context, discriminator, task)
Create a task keyed by context directory and discriminator string.
run
def run(force=NEVER, cache=NORMAL)
Run the task, where force
can be used to ignore a cached outcome, and cache
can be used to deny caching an outcome.
dkrcache.util
ContextStream Objects
class ContextStream()
Fully customisable docker build context.
open
@classmethod
@contextmanager
def open(cls, dockerstdin)
Attach to the given stdin of docker build, which should have been given -
as context.
put
def put(name, path)
Add the given path as the given archive name.
putstream
def putstream(name, stream)
Add the given stream as the given archive name.
mkdir
def mkdir(name)
Create a directory in the context.
iidfile
@contextmanager
def iidfile()
Context manager yielding an object with args
to pass to docker build, and a read
function to get the image ID.
lagoon
Text mode instances of Program for every executable, with dash translated to underscore e.g. from lagoon import pkg_config
for pkg-config
.
lagoon.binary
Like lagoon module but Program objects are in binary mode.
lagoon.program
Program Objects
class Program()
Normally import an instance from lagoon
or lagoon.binary
module instead of instantiating manually.
text
@classmethod
def text(cls, path)
Return text mode Program for the executable at the given path.
binary
@classmethod
def binary(cls, path)
Return binary mode Program for executable at given path.
__getattr__
def __getattr__(name)
Add argument, where underscore means dash.
__getitem__
def __getitem__(key)
Apply a style, e.g. partial
to suppress execution or print
to send stdout to console.
__call__
def __call__(*args, **kwargs)
Run program in foreground with additional args. Accepts many subprocess kwargs. Use partial
style to suppress execution, e.g. before running in background. Otherwise return CompletedProcess, or one of its fields if the rest are redirected, or None if all fields redirected.
__enter__
def __enter__()
Start program in background yielding the Popen object, or one of its fields if the rest are redirected.
NOEOL Objects
@singleton
class NOEOL()
Style to strip trailing newlines from stdout, in the same way as shell does.
ONELINE
def ONELINE(text)
Style to assert exactly one line of output, using splitlines
.
lagoon.url
lagoon.util
unmangle
def unmangle(name)
Undo name mangling.
atomic
@contextmanager
def atomic(path)
Context manager yielding a temporary Path for atomic write to the given path. Parent directories are created automatically. Also suitable for making a symlink atomically. Leaves the given path unchanged if an exception happens.
threadlocalproperty Objects
class threadlocalproperty()
Like property
but each thread has its own per-object values.
__init__
def __init__(defaultfactory)
The defaultfactory
should return the initial value per object (per thread).
onerror
@contextmanager
def onerror(f)
Context manager that runs the given function if an exception happens, like finally
excluding the happy path.
mapcm
@contextmanager
def mapcm(f, obj)
Invoke obj
as a context manager, apply f
to its yielded value, and yield that. For example apply Path
to the string yielded by TemporaryDirectory()
.
stripansi
def stripansi(text)
Remove ANSI control sequences from the given text, to make it black and white.
HarnessCase Objects
class HarnessCase(TestCase)
Enter context managers in setUp and exit them in tearDown.
harness
def harness()
Must yield exactly once.
screen
GNU Screen interface, smoothing over its many gotchas.
stuffablescreen
def stuffablescreen(doublequotekey)
Return text mode Program for screen, with the given environment variable set to double quote.
Stuff Objects
class Stuff()
__init__
def __init__(session, window, doublequotekey)
Target the given screen session and window, using the given environment variable for double quote.
__call__
def __call__(text)
Send the given text so that it is received literally.
eof
def eof()
Send EOF, may have no effect if not at the start of a line.
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
Built Distribution
File details
Details for the file lagoon-46.tar.gz
.
File metadata
- Download URL: lagoon-46.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a79cb892365d97c282e45fc6bfa82b9f454d47dbb2447efbc2c277a26853f248 |
|
MD5 | 191bfaccb2572c75d206757b8715812d |
|
BLAKE2b-256 | b2fa3194859a974da473828fd5f07138471f67dfe6803f02c639f95188724524 |
File details
Details for the file lagoon-46-py3-none-any.whl
.
File metadata
- Download URL: lagoon-46-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fab23ceced0d7c9f07436f747e6c5bf5013224ea89b8e82ececd8ba2fba833e1 |
|
MD5 | 30bffbb7ee91426c316463d1531c3172 |
|
BLAKE2b-256 | 2f7f77b280f043bf430e8414ae6dd6c3e0bdbcc86fcad16bf3da27ba554456e5 |