Skip to content

pshlex - join various stringifiable objects and quote them for the shell

[Home | GitLab | PyPI | Download | ReadTheDocs]

Overview

This library was written mainly to provide a function that can stringify a list of path-like objects: the join() function is very similar to shlex.join(), but it will accept pathlib.Path objects as well as strings.

The join_any() function started off as an implementation detail, but it may turn out to be useful in its own right; it is also similar to shlex.join(), but it will convert any Python object into its string representation.

Examples

Use the join() function as a type-safe version when dealing with path-like objects:

def run(cmd: list[str | pathlib.Path]) -> None:
"""Run a command."""
    cmdstr: Final = pshlex.join(cmd)
    ...
        sys.exit(f"Could not run `{cmdstr}`: {err}")

Contact

The pshlex library was written by Peter Pentchev. It is developed in a GitLab repository. This documentation is hosted at Ringlet with a copy at ReadTheDocs.