pyutils-extended 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyutils-extended-0.1.0/PKG-INFO +24 -0
- pyutils-extended-0.1.0/README.md +15 -0
- pyutils-extended-0.1.0/pyutils_extended/__init__.py +3 -0
- pyutils-extended-0.1.0/pyutils_extended/setup.py +13 -0
- pyutils-extended-0.1.0/pyutils_extended/tests/__init__.py +0 -0
- pyutils-extended-0.1.0/pyutils_extended/tests/test_utils.py +21 -0
- pyutils-extended-0.1.0/pyutils_extended/utils.py +38 -0
- pyutils-extended-0.1.0/pyutils_extended.egg-info/PKG-INFO +24 -0
- pyutils-extended-0.1.0/pyutils_extended.egg-info/SOURCES.txt +11 -0
- pyutils-extended-0.1.0/pyutils_extended.egg-info/dependency_links.txt +1 -0
- pyutils-extended-0.1.0/pyutils_extended.egg-info/top_level.txt +1 -0
- pyutils-extended-0.1.0/setup.cfg +4 -0
- pyutils-extended-0.1.0/setup.py +13 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pyutils-extended
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A small collection of handy utility functions.
|
|
5
|
+
Author: Revenue Worker
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# pyutils-extended
|
|
11
|
+
|
|
12
|
+
A small collection of handy utility functions.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install pyutils-extended
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from pyutils_extended import slugify, pluralize, humanize_bytes
|
|
24
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="pyutils-extended",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
packages=find_packages(),
|
|
7
|
+
description="A small collection of handy utility functions.",
|
|
8
|
+
long_description=open("README.md").read(),
|
|
9
|
+
long_description_content_type="text/markdown",
|
|
10
|
+
author="Revenue Worker",
|
|
11
|
+
license="MIT",
|
|
12
|
+
python_requires=">=3.8",
|
|
13
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Unit tests for pyutils_extended.utils."""
|
|
2
|
+
from pyutils_extended.utils import slugify, pluralize, humanize_bytes
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_slugify():
|
|
6
|
+
assert slugify("Hello World!") == "hello-world"
|
|
7
|
+
assert slugify("Multiple Spaces") == "multiple-spaces"
|
|
8
|
+
assert slugify("Special!@#$%^&*()") == "special"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_pluralize():
|
|
12
|
+
assert pluralize("apple", 1) == "apple"
|
|
13
|
+
assert pluralize("apple", 5) == "apples"
|
|
14
|
+
assert pluralize("bus", 2) == "buses"
|
|
15
|
+
assert pluralize("day", 3) == "days"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_humanize_bytes():
|
|
19
|
+
assert humanize_bytes(1000) == "1.0 KiB"
|
|
20
|
+
assert humanize_bytes(1500) == "1.5 KiB"
|
|
21
|
+
assert humanize_bytes(0) == "0.0 B"
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""String helpers, pluralization, and size formatting."""
|
|
2
|
+
import re
|
|
3
|
+
import math
|
|
4
|
+
|
|
5
|
+
def slugify(text: str) -> str:
|
|
6
|
+
"""Convert arbitrary text to a URL-safe slug."""
|
|
7
|
+
text = text.lower().strip()
|
|
8
|
+
text = re.sub(r'[^a-z0-9]+', '-', text)
|
|
9
|
+
return re.sub(r'-+', '-', text).strip('-')
|
|
10
|
+
|
|
11
|
+
def pluralize(word: str, count: int) -> str:
|
|
12
|
+
"""Return plural form. Singular form is used only when count == 1."""
|
|
13
|
+
if count == 1:
|
|
14
|
+
return word
|
|
15
|
+
# Simple English pluralization
|
|
16
|
+
if word.endswith(('s', 'x', 'z', 'sh', 'ch')):
|
|
17
|
+
return word + 'es'
|
|
18
|
+
# y preceded by consonant → -ies (fly→flies)
|
|
19
|
+
# y preceded by vowel → -s (day→days, key→keys)
|
|
20
|
+
if word.endswith('y') and len(word) > 1:
|
|
21
|
+
if word[-2] not in 'aeiou':
|
|
22
|
+
return word[:-1] + 'ies'
|
|
23
|
+
return word + 's'
|
|
24
|
+
|
|
25
|
+
def humanize_bytes(size: int, binary: bool = False) -> str:
|
|
26
|
+
"""Format bytes as human-readable string.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
size: Number of bytes.
|
|
30
|
+
binary: If True, use 1024 base (KiB/MiB); else 1000.
|
|
31
|
+
"""
|
|
32
|
+
base = 1024 if binary else 1000
|
|
33
|
+
units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
|
|
34
|
+
for unit in units:
|
|
35
|
+
if abs(size) < base:
|
|
36
|
+
return f"{size:.1f} {unit}"
|
|
37
|
+
size /= base
|
|
38
|
+
return f"{size:.1f} PiB"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pyutils-extended
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A small collection of handy utility functions.
|
|
5
|
+
Author: Revenue Worker
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# pyutils-extended
|
|
11
|
+
|
|
12
|
+
A small collection of handy utility functions.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install pyutils-extended
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from pyutils_extended import slugify, pluralize, humanize_bytes
|
|
24
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
pyutils_extended/__init__.py
|
|
4
|
+
pyutils_extended/setup.py
|
|
5
|
+
pyutils_extended/utils.py
|
|
6
|
+
pyutils_extended.egg-info/PKG-INFO
|
|
7
|
+
pyutils_extended.egg-info/SOURCES.txt
|
|
8
|
+
pyutils_extended.egg-info/dependency_links.txt
|
|
9
|
+
pyutils_extended.egg-info/top_level.txt
|
|
10
|
+
pyutils_extended/tests/__init__.py
|
|
11
|
+
pyutils_extended/tests/test_utils.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pyutils_extended
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="pyutils-extended",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
packages=find_packages(),
|
|
7
|
+
description="A small collection of handy utility functions.",
|
|
8
|
+
long_description=open("README.md").read(),
|
|
9
|
+
long_description_content_type="text/markdown",
|
|
10
|
+
author="Revenue Worker",
|
|
11
|
+
license="MIT",
|
|
12
|
+
python_requires=">=3.8",
|
|
13
|
+
)
|