Skip to main content

No project description provided

Project description

misc_tooling

A collection of simple, reusable Python utilities for file and string manipulation. This package provides convenient wrappers around common filesystem operations and a Java-like StringBuilder for efficient string construction and editing.

Features

File Tools (file_tools.py)

  • File existence check: Quickly check if a file exists.
  • Get full path: Resolve relative paths to absolute paths.
  • Read file: Read file contents safely, with error handling.
  • Write file: Write data to files, with directory creation if needed.
  • Delete file/folder: Remove files or folders, with success indication.
  • Make file/folder: Create files or folders, including parent directories.

String Builder (string_builder.py)

  • Efficient string construction: Append, replace, drop, and render strings incrementally.
  • Drop/replace by value or index: Remove or replace strings by value or position.
  • Scrub all instances: Remove all occurrences of a substring.
  • Consistent formatting: Handles spaces and punctuation for clean output.

Installation

Clone the repository and install dependencies (if any):

# Clone the repo
$ git clone <your-repo-url>
$ cd misc_tooling

# (Optional) Set up a virtual environment
$ python -m venv venv
$ source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install with Poetry (recommended)
$ poetry install

Usage

File Tools Example

from src.misc_tooling.file_tools import (
    file_exists, get_full_path, read_file, write_file, write_file_all,
    delete_file, delete_folder, make_file, make_folder
)

# Check if a file exists
print(file_exists('test.txt'))

# Get absolute path
print(get_full_path('test.txt'))

# Read and write files
write_file('test.txt', 'Hello, world!')
print(read_file('test.txt'))

# Create all parent folders and write
write_file_all('folder/subfolder/test.txt', 'Data')

# Delete file and folder
delete_file('test.txt')
delete_folder('folder/subfolder')

# Make file/folder
make_file('newfile.txt')
make_folder('newfolder')

StringBuilder Example

from src.misc_tooling.string_builder import StringBuilder

sb = StringBuilder("Hello", "world")
sb.push("from", "Python")
print(sb.render())  # Output: Hello world from Python

sb.replace("world", "there")
print(sb.render())  # Output: Hello there from Python

sb.drop_string("Hello")
print(sb.render())  # Output: there from Python

sb.replace_at_index(1, "everyone")
print(sb.render())  # Output: there everyone Python

sb.reset()
print(sb.render())  # Output: (empty string)

API Reference

File Tools

  • file_exists(file_path) -> bool: Returns whether the file exists.
  • get_full_path(file_path: str) -> str: Returns the absolute path.
  • read_file(file_path: str) -> str: Reads file contents as a string.
  • write_file(file_path, file_data) -> bool: Writes data to a file.
  • write_file_all(file_path, file_data): Creates parent directories and writes data.
  • delete_file(file_path) -> bool: Deletes a file.
  • delete_folder(folder_path) -> bool: Deletes a folder.
  • make_folder(folder_path) -> bool: Creates a folder.
  • make_file(file_path: str) -> bool: Creates an empty file.

StringBuilder

  • StringBuilder(*inputs): Initialize with any number of strings.
  • push(*inputs): Add strings to the builder.
  • render() -> str: Get the built string.
  • reset(): Clear the builder.
  • drop_string(dropped): Remove a string from memory.
  • scrub_string(value): Remove all instances of a string.
  • replace(value_replaced, replacement): Replace all matching strings.
  • replace_at_index(index, value): Replace string at a specific index.

Testing

Unit tests are provided in the tests/ directory. Run them with:

$ poetry run pytest

License

MIT License

Contributing

Pull requests and suggestions are welcome! Please open an issue or submit a PR.

Contact

For questions or feedback, open an issue on GitHub.

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

misc_tooling-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

misc_tooling-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file misc_tooling-0.1.0.tar.gz.

File metadata

  • Download URL: misc_tooling-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.0 Windows/11

File hashes

Hashes for misc_tooling-0.1.0.tar.gz
Algorithm Hash digest
SHA256 25c16091152ce252c1ac8be78b2692108e21579725b642e32b9b0dc974565ec8
MD5 3ea0261eabe850c02b4d1c8012758f98
BLAKE2b-256 d984b0e9e30a538e9f16be5c63b8e986133a6eb74692e347c0f71357f4d1e250

See more details on using hashes here.

File details

Details for the file misc_tooling-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: misc_tooling-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.0 Windows/11

File hashes

Hashes for misc_tooling-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf987348fd7051379c7d5ce419f3d0e679c766f6a8eb7743601ac94814d83302
MD5 17cd6c295361366d62615fee59a6f1e1
BLAKE2b-256 87fc7138c12e7d94e3215165eb0c7a9902d25ff9bec2dd6711d11bb6b040bc63

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