Skip to content

Malcolm's Path Tools

PyPI PyPI - Python Version PyPI - License Coookiecutter - Malcolm


Documentation: https://malcolm3davis.github.io/path-tools-med

Source Code: https://github.com/malcolm3davis/path-tools-med

PyPI: https://pypi.org/project/path-tools-med/


A few path related functions I wish pathlib supported.

Usage

  • make_versioned_backup(path: Path|str) -> Path
  • Renames the specified path adding a .~#~ style version number that is higher than any existing version number.
  • backup_path(paht: Path|str, backup_extension=".bak") -> Path
  • Renames the specified file adding the backup_extension. If that backup file already exists it renamed with make_versioned_backup.
  • get_highest_backup_version(path: Path|str) -> int
  • Utility function to see what the current highest backup version number exists.

It also provides the PathRerooter class that can be used to update path objects to have a new initial root path.

r = PathRerooter("/old/root/path", "/new/root/path/is/here")
assert r.fix("/old/root/path/some/file.txt") == "/new/root/path/is/here/some/file.txt"

Installation

pip install path-tools-med

Development

  • Clone this repository
  • Requirements:
  • Poetry
  • Python 3.8+
  • Create a virtual environment and install the dependencies
poetry install
  • Activate the virtual environment
poetry shell

Testing

pytest

Documentation

The documentation is automatically generated from the content of the docs directory and from the docstrings of the public signatures of the source code. The documentation is updated and published as a Github Pages page automatically as part each release.

Releasing

Trigger the Draft release workflow (press Run workflow). This will update the changelog & version and create a GitHub release which is in Draft state.

Find the draft release from the GitHub releases and publish it. When a release is published, it'll trigger release workflow which creates PyPI release and deploys updated documentation.

Pre-commit

Pre-commit hooks run all the auto-formatting (ruff format), linters (e.g. ruff and mypy), and other quality checks to make sure the changeset is in good shape before a commit/push happens.

You can install the hooks with (runs for each commit):

pre-commit install

Or if you want them to run only for each push:

pre-commit install -t pre-push

Or if you want e.g. want to run all checks manually for all files:

pre-commit run --all-files

This project was generated using the wolt-python-package-cookiecutter template.