From d51d02f88f73315bc535ee7c23def3077229f56b Mon Sep 17 00:00:00 2001 From: Vikram Jayanthi Date: Mon, 8 Jun 2020 14:29:18 -0700 Subject: [PATCH] Linting, formatting, typing --- tests/test_upload.py | 1 - twine/commands/upload.py | 2 +- twine/utils.py | 12 +++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/test_upload.py b/tests/test_upload.py index ba1e0922..34770597 100644 --- a/tests/test_upload.py +++ b/tests/test_upload.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import os import pretend import pytest diff --git a/twine/commands/upload.py b/twine/commands/upload.py index 25445748..c782bc1f 100644 --- a/twine/commands/upload.py +++ b/twine/commands/upload.py @@ -62,7 +62,7 @@ def upload(upload_settings: settings.Settings, dists: List[str]) -> None: print(f"Uploading distributions to {repository_url}") if upload_settings.verbose: for dist_to_upload in uploads: - #If the file size is <.1 MB we display in KB + # If the file size is <.1 MB we display in KB file_size, size_unit = utils.get_file_size(dist_to_upload) print(f" {dist_to_upload} ({file_size} {size_unit})") print("\n") diff --git a/twine/utils.py b/twine/utils.py index 302be0bc..20ad3d54 100644 --- a/twine/utils.py +++ b/twine/utils.py @@ -23,6 +23,7 @@ from typing import Dict from typing import Optional from typing import Sequence +from typing import Tuple from typing import Union from urllib.parse import urlparse from urllib.parse import urlunparse @@ -31,6 +32,7 @@ import rfc3986 from twine import exceptions + # Shim for input to allow testing. input_func = input @@ -158,14 +160,14 @@ def normalize_repository_url(url: str) -> str: return urlunparse(parsed) -def get_file_size(filepath : str) -> (float, str): - """Calculates and returns the file size and unit""" - #If the file size is <.1 MB we display in KB +def get_file_size(filepath: str) -> Tuple[float, str]: + """Return the file size and unit of size following PyPI's file size format.""" + # If the file size is <.1 MB we display in KB size_unit = "MB" - file_size = round(os.path.getsize(filepath)/(1024 * 1024), 1) + file_size = round(os.path.getsize(filepath) / (1024 * 1024), 1) if not file_size: size_unit = "KB" - file_size = round(os.path.getsize(filepath)/(1024), 1) + file_size = round(os.path.getsize(filepath) / (1024), 1) return file_size, size_unit