Skip to main content

A collection of functions working with `pathlib.Path`

Project description

pathext

pathext is a collection of functions working with pathlib.Path. They're often wrappers for standard library functionality with some extensions.

Executable lookup

pathext.which()

Wrapper for shutil.which() which returns the result as an absolute Path (or None if it fails to find the executable). It also has a couple extra features, see below.

Arguments (all of them except name are optional):

  • name: str - Executable name to look up.
  • path: None | str | Sequence[Path] - Directory list to look up name in. If set to None, or set to a string, then it is passed to shutil.which() as-is. If set to a list, concatenates the list items using os.pathsep, and passes the result to shutil.which(). Defaults to None. See shutil.which()'s documentation on exact behaviour of this argument.
  • cwd: Optional[Path] - If specified, then changes the current working directory to cwd for the duration of the shutil.which() call. Note that since it is changing global state (the current working directory), it is inherently not thread-safe.

pathext.checked_which()

Same as pathext.which(), except it raises ValueError instead of returning None if it cannot find the executable.

Manipulating PATH strings

pathext.split_path_list()

Split PATH string based on os.pathsep and convert each component to pathlib.Path.

Empty components will be removed, i.e. leading, trailing or duplicated separators will not cause issues.

In contrast to str.split(), if the string is empty, the function will return an empty list.

pathext.join_path_list()

Create PATH string (os.pathsep-separated string) from list of paths. The list is allowed to contain Path objects, strings and even None. Empty strings and Nones will be removed before joining the list.

pathext.deduplicate_path_list()

Create PATH string (os.pathsep-separated string) from list of paths. The list is allowed to contain Path objects, strings and even None. Empty strings and Nones will be removed before joining the list.

Generic utilities

pathext.to_path()

Simple function that converts a str to a Path (just like Path's constructor), but also handles None by returning None. It can be used to convert the return value of functions that return str | None to Path | None.

Project details


Download files

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

Source Distribution

pathext-1.3.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pathext-1.3-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file pathext-1.3.tar.gz.

File metadata

  • Download URL: pathext-1.3.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for pathext-1.3.tar.gz
Algorithm Hash digest
SHA256 ec1f18f3ad44aa7ac308dbe0b1f7fa7c1e5a1d61656c27c4226b3d491a529027
MD5 5531f33cddc8ff4ca367acd50e79014b
BLAKE2b-256 25fa4c5c9f47d2b1b0c57ce3f6af9bb065ee165a527664a0b2adbee0fdbbf383

See more details on using hashes here.

File details

Details for the file pathext-1.3-py3-none-any.whl.

File metadata

  • Download URL: pathext-1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for pathext-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a68f8673ec95e148987a3d955b44aae16caa73021f5ed6f3e6defb4d63358ff0
MD5 a428e5c172b61a4a2cbe96a4bb640d26
BLAKE2b-256 534d45c78be27e0f42801e4284070af1ebc69d73cbf921ec8b82f36c17630d6a

See more details on using hashes here.

Supported by

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