pymt.utils package

Submodules

pymt.utils.prefix module

pymt.utils.prefix.names_with_prefix(names, prefix)[source]

Find names that begin with a common prefix. In this case, names are a series .-separated words, much like module names.

Returns a list of all names that begin with prefix. The order of matched names is maintained.

>>> names_with_prefix(['foo.bar', 'foobar.baz'], 'foo')
['foo.bar']
>>> names_with_prefix(['foo.bar', 'foo.bar', 'foo.foo'], 'foo')
['foo.bar', 'foo.foo']
pymt.utils.prefix.prefix_is_empty(prefix)[source]

Check if a namespace prefix is empty.

A prefix is empty if it is None, just a “.” or an empty string.

Return True if empty, otherwise False.

pymt.utils.prefix.strip_prefix(name, prefix)[source]

Remove a prefix from a name, including any leading “.”s.

>>> strip_prefix('foo.bar', 'foo')
'bar'
>>> strip_prefix('foo.bar', '')
'foo.bar'

pymt.utils.utils module

pymt.utils.utils.as_cwd(path)[source]
pymt.utils.utils.suppress_stdout()[source]

Module contents

pymt.utils.as_cwd(path)[source]
pymt.utils.err(message: Any | None = None, file: IO | None = None, nl: bool = True, *, err: bool = True, color: bool | None = None, **styles: Any) None

This function combines echo() and style() into one call. As such the following two calls are the same:

click.secho('Hello World!', fg='green')
click.echo(click.style('Hello World!', fg='green'))

All keyword arguments are forwarded to the underlying functions depending on which one they go with.

Non-string types will be converted to str. However, bytes are passed directly to echo() without applying style. If you want to style bytes that represent text, call bytes.decode() first.

Changed in version 8.0: A non-string message is converted to a string. Bytes are passed through without style applied.

New in version 2.0.

pymt.utils.out(message: Any | None = None, file: IO | None = None, nl: bool = True, *, err: bool = True, color: bool | None = None, **styles: Any) None

This function combines echo() and style() into one call. As such the following two calls are the same:

click.secho('Hello World!', fg='green')
click.echo(click.style('Hello World!', fg='green'))

All keyword arguments are forwarded to the underlying functions depending on which one they go with.

Non-string types will be converted to str. However, bytes are passed directly to echo() without applying style. If you want to style bytes that represent text, call bytes.decode() first.

Changed in version 8.0: A non-string message is converted to a string. Bytes are passed through without style applied.

New in version 2.0.