Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force conversion unit in format_size #47

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

sebastian-luna-valero
Copy link

Hi,

We are interested in adding an optional flag to format_size() so you can force the conversion unit.

Here is the desired behaviour:

python3 -c "import humanfriendly; print(humanfriendly.format_size(1000 ** 3 * 4))"
4 GB

python3 -c "import humanfriendly; print(humanfriendly.format_size(1000 ** 3 * 4, force_unit='bytes'))"
4000000000 bytes

python3 -c "import humanfriendly; print(humanfriendly.format_size(1000 ** 3 * 4, force_unit='KB'))"
4000000 KB

python3 -c "import humanfriendly; print(humanfriendly.format_size(1000 ** 3 * 4, force_unit='MB'))"
4000 MB

python3 -c "import humanfriendly; print(humanfriendly.format_size(1000 ** 3 * 4, force_unit='GB'))"
4 GB

python3 -c "import humanfriendly; print(humanfriendly.format_size(1000 ** 3 * 4, force_unit='TB'))"
0 TB

Best regards,
Sebastian

@coveralls
Copy link

coveralls commented Sep 3, 2020

Coverage Status

Coverage increased (+0.003%) to 93.417% when pulling 57ba6f7 on sebastian-luna-valero:force-units into 05d02d4 on xolox:master.

@sebastian-luna-valero
Copy link
Author

Hi @xolox

All tests are passing except for coveralls which I don't know how to fix.

Please have a look and let me know your thoughts.

Many thanks,
Sebastian

@sebastian-luna-valero
Copy link
Author

Hi again,

Alright so adding tests for the new code solves the coveralls issue.

Please have a look and let me know your thoughts.

Best regards,
Sebastian

@yodog
Copy link

yodog commented May 11, 2021

any news on this?
its exactly what im looking for

@sebastian-luna-valero
Copy link
Author

Hi,

Probably my changes are a bit too much for this package and that's why it hasn't been merge.

I have just taken the relevant code out and copied it to my own script. @yodog I recommend you to do the same.

If you think it is interesting, I might upload it to my own git repo and share it with you.

Best regards,
Sebastian

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.

3 participants