Skip to content

Add command line support for naturalsize - #505

Open
htaheri17 wants to merge 2 commits into
python-humanize:mainfrom
htaheri17:feature/naturalsize-cli
Open

htaheri17 wants to merge 2 commits into
python-humanize:mainfrom
htaheri17:feature/naturalsize-cli

Conversation

@htaheri17

Copy link
Copy Markdown

Related issue: #184

This PR adds a way to format file sizes directly from the terminal using Humanize. Previously, running python -m humanize naturalsize 8589934592 produced an error because the package had no command-line entry point. With this change, it prints 8.6 GB.

The CLI supports both humanize naturalsize and python -m humanize naturalsize, along with binary units, GNU formatting, custom number formats, and piped input. Invalid input produces a helpful error message instead of a traceback.

The implementation uses the existing naturalsize function for formatting. I also added CLI tests and updated the README and filesize documentation with examples.

I tested the changes locally on macOS. The test suite finished with 757 passed and 132 skipped. I also checked both command forms manually and confirmed the expected decimal and binary output.

The full aggregate lint check was blocked in the implementation environment by an npm certificate error while installing Prettier.

htaheri17 and others added 2 commits November 3, 2026 22:19
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.53571% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.29%. Comparing base (d16e635) to head (f7d06a1).

Files with missing lines Patch % Lines
src/humanize/__main__.py 0.00% 3 Missing ⚠️
src/humanize/cli.py 95.65% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #505      +/-   ##
==========================================
- Coverage   99.70%   99.29%   -0.42%     
==========================================
  Files          12       15       +3     
  Lines        1024     1136     +112     
==========================================
+ Hits         1021     1128     +107     
- Misses          3        8       +5     
Flag Coverage Δ
macos-latest 97.09% <95.53%> (-0.18%) ⬇️
ubuntu-latest 97.09% <95.53%> (-0.18%) ⬇️
windows-latest 92.34% <95.53%> (+0.34%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant