-
Notifications
You must be signed in to change notification settings - Fork 1.3k
config: Support ~/.aws/config parsing #5378
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # https://github.com/aws/aws-cli/blob/5aa599949f60b6af554fd5714d7161aa272716f7/awscli/customizations/s3/utils.py | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this whole file is awscli-specific, we could move this stuff to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think keeping here is OK (even though this is a pre-emptive assumption) I believe this utility might come in handy in other places since it does a very general job. The awscli-specific part here is the handling of IEC suffixes, though it doesn't differ much and something we can ignore.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, let's keep it then π |
||
|
|
||
| MULTIPLIERS = { | ||
| "kb": 1024, | ||
| "mb": 1024 ** 2, | ||
| "gb": 1024 ** 3, | ||
| "tb": 1024 ** 4, | ||
| "kib": 1024, | ||
| "mib": 1024 ** 2, | ||
| "gib": 1024 ** 3, | ||
| "tib": 1024 ** 4, | ||
| } | ||
|
|
||
|
|
||
| def human_readable_to_bytes(value): | ||
| value = value.lower() | ||
| suffix = None | ||
| if value.endswith(tuple(MULTIPLIERS.keys())): | ||
| size = 2 | ||
| size += value[-2] == "i" # KiB, MiB etc | ||
| value, suffix = value[:-size], value[-size:] | ||
|
|
||
| multiplier = MULTIPLIERS.get(suffix, 1) | ||
| return int(value) * multiplier | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import pytest | ||
|
|
||
| from dvc.utils.conversions import human_readable_to_bytes | ||
|
|
||
| KB = 1024 | ||
| MB = KB ** 2 | ||
| GB = KB ** 3 | ||
| TB = KB ** 4 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "test_input, expected", | ||
| [ | ||
| ("10", 10), | ||
| ("10 ", 10), | ||
| ("1kb", 1 * KB), | ||
| ("2kb", 2 * KB), | ||
| ("1000mib", 1000 * MB), | ||
| ("20gB", 20 * GB), | ||
| ("10Tib", 10 * TB), | ||
| ], | ||
| ) | ||
| def test_conversions_human_readable_to_bytes(test_input, expected): | ||
| assert human_readable_to_bytes(test_input) == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("invalid_input", ["foo", "10XB", "1000Pb", "fooMiB"]) | ||
| def test_conversions_human_readable_to_bytes_invalid(invalid_input): | ||
| with pytest.raises(ValueError): | ||
| human_readable_to_bytes(invalid_input) |
Uh oh!
There was an error while loading. Please reload this page.