humanize
humanize copied to clipboard
Add 'humanize' command-line interface
This PR adds 'humanize' command-line interface, which enables users to run humanize directly on the terminal.
Example of use:
$ humanize naturalsize 8589934592
8.6 GB
$ humanize naturalsize --binary 8589934592
8.0 GiB
$ echo 8589934592 | python -m humanize naturalsize --format "%.3f"
8.590 GB
$
$ humanize --version
humanize 0.1.dev845
$
$ humanize --help
usage: humanize [-h] [-v] FUNCTION ...
Python humanize utilities
positional arguments:
FUNCTION
apnumber Converts an integer to Associated Press style.
clamp Returns number with the specified format, clamped between floor and ceil.
fractional Convert to fractional number.
intcomma Converts an integer to a string containing commas every three digits.
intword Converts a large integer to a friendly text representation.
metric Return a value with a metric SI unit-prefix appended.
naturalsize Format a number of bytes like a human readable filesize (e.g. 10 kB).
ordinal Converts an integer to its ordinal as a string.
scientific Return number in string scientific notation z.wq x 10ⁿ.
options:
-h, --help show this help message and exit
-v, --version show program's version number and exit
$
$ humanize naturalsize --help
usage: humanize naturalsize [-h] [--locale LOCALE] [--binary] [--gnu] [--format FORMAT] [values ...]
positional arguments:
values Values to humanize. If not found, humanizes inputs from stdin.
options:
-h, --help show this help message and exit
--locale LOCALE Language name, e.g. `en_GB`.
--binary If `True`, uses binary suffixes (KiB, MiB) with base 2**10 instead of 10**3. (default: `False`)
--gnu If `True`, the binary argument is ignored and GNU-style (`ls -sh` style) prefixes are used (K, M) with the 2**10 definition. (default: `False`)
--format FORMAT Custom formatter. (default: `%.1f`)
Closes #184
Changes proposed in this pull request:
- CLI for
humanize.filesizeandhumanize.number. humanize.clipackage, which relies on argparse to keep the package dependencies free.humanize.__main__module forpython -m humanize.- Tests.
Note: humanize.time is excluded from the scope because it's too hard to process arbitrary date & time inputs.
Thank you for the PR! Just a quick note to say it's not forgotten, and I'll have a look soon but it might be after PyCon US.
I'm closing this PR to clean up my PR list. Please feel free to reopen PR and/or ping me anytime.