Easy Python functions making making functional Python functions easier.
Project description
hunterMakesPy
Utilities for converting mixed input to integers, calculating CPU limits, handling None values, importing code dynamically, and manipulating nested data.
What This Package Does
-
Convert strings, floats, binary data to validated integers — Accepts messy input like
["1", 2.0, b"3"]and returns[1, 2, 3]or fails with descriptive errors. -
Calculate CPU/concurrency limits from flexible specifications — Pass
0.75for 75% of CPUs,Truefor 1 CPU,4for exactly 4 CPUs, or-2to reserve 2 CPUs. -
Eliminate type checker warnings about None — Convert
Type | Nonereturns toTypeby validating at runtime that values are not None. -
Import Python code from dot-notation paths or file paths — Load functions or classes from
"scipy.signal.windows"or"path/to/file.py"without manual module loading. -
Create nested directories without error handling — Write to
"deep/nested/path/file.txt"and parent directories are created automatically, existing directories are silently skipped. -
Format and write Python source code automatically — Removes unused imports, sorts import statements, applies consistent formatting before writing files.
-
Extract all strings from arbitrarily nested data — Recursively traverse dictionaries, lists, tuples, sets and collect every string value into a flat list.
-
Merge multiple dictionaries with list values — Combine
{"a": [1, 2]}and{"a": [3], "b": [4]}into{"a": [1, 2, 3], "b": [4]}with optional deduplication and sorting. -
Compress NumPy arrays to compact string representations — Encode repetitive patterns and sequences using run-length encoding and Python range syntax that evaluates back to the original data.
-
Replace ambiguous numeric literals with semantic names — Use
decreasinginstead of-1,inclusivefor boundary adjustments,zeroIndexedfor index conversions, making intent explicit.
Examples
import hunterMakesPy as humpy
# Integer validation from mixed sources
ports = humpy.intInnit(["8080", 443, "22"], "server_ports")
# Flexible CPU limit calculation
workers = humpy.defineConcurrencyLimit(limit=0.75) # 6 CPUs on 8-core machine
# None-checking without type errors
config = humpy.raiseIfNone(getConfig(), "Missing configuration")
# Dynamic imports
windowFunc = humpy.importLogicalPath2Identifier("scipy.signal.windows", "hann")
# Safe file writing
humpy.writeStringToHere("content", "nested/dirs/file.txt") # Creates dirs
# String extraction from nested data
strings = humpy.stringItUp({"users": ["alice"], "config": {"host": "localhost"}})
# Returns: ["users", "alice", "config", "host", "localhost"]
# Dictionary merging
merged = humpy.updateExtendPolishDictionaryLists(
{"servers": ["chicago"]},
{"servers": ["tokyo", "chicago"]},
destroyDuplicates=True
)
# Returns: {"servers": ["chicago", "tokyo"]}
Testing Your Own Code
Import test suites to validate custom functions that match the expected signatures:
from hunterMakesPy.tests.test_parseParameters import PytestFor_intInnit
@pytest.mark.parametrize("test_name,test_func", PytestFor_intInnit(myFunction))
def test_my_integer_validator(test_name, test_func):
test_func()
My recovery
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file huntermakespy-0.4.7.tar.gz.
File metadata
- Download URL: huntermakespy-0.4.7.tar.gz
- Upload date:
- Size: 811.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc6ef0f5565d55e4da62cefebc445f9cab0d3aa2645dd53c07d4e18e3460ebd8
|
|
| MD5 |
47816385476bac7634e77419f2495e81
|
|
| BLAKE2b-256 |
55c6f4b55797c0f891d9a0b81b89761d8c7fea9a6062afce747bc9dd86772b8c
|