From 190b11a70f608b448f4d963e766d047c27be6043 Mon Sep 17 00:00:00 2001 From: relikd Date: Wed, 21 Feb 2024 00:09:54 +0100 Subject: [PATCH 1/3] feat: remove tabulate dependency --- remotezip.py | 19 ++++++++++++++++--- setup.py | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/remotezip.py b/remotezip.py index a0a994c..b36a75d 100755 --- a/remotezip.py +++ b/remotezip.py @@ -5,7 +5,6 @@ from itertools import tee import requests -from tabulate import tabulate __all__ = ['RemoteIOError', 'RemoteZip'] @@ -259,12 +258,26 @@ def _list_files(url, support_suffix_range, filenames): with RemoteZip(url, headers={'User-Agent': 'remotezip'}, support_suffix_range=support_suffix_range) as zip: if len(filenames) == 0: filenames = zip.namelist() - data = [('Length', 'DateTime', 'Name')] + data = [] for fname in filenames: zinfo = zip.getinfo(fname) dt = datetime(*zinfo.date_time) data.append((zinfo.file_size, dt.strftime('%Y-%m-%d %H:%M:%S'), zinfo.filename)) - print(tabulate(data, headers='firstrow')) + printTable(data, ('Length', 'DateTime', 'Name'), '><<') + + +def printTable(data, header, align): + # get max col width & prepare formatting string + col_w = [len(col) for col in header] + for row in data: + col_w = [max(w, len(str(x))) for w, x in zip(col_w, row)] + fmt = ' '.join(f'{{:{a}{w}}}' for w, a in zip(col_w, align + '<' * 99)) + # print table + print(fmt.format(*header).rstrip()) + print(fmt.format(*['-' * w for w in col_w])) + for row in data: + print(fmt.format(*row).rstrip()) + print() def _extract_files(url, support_suffix_range, filenames, path): diff --git a/setup.py b/setup.py index 9cf96ac..55287a6 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ description='Access zip file content hosted remotely without downloading the full file.', long_description=description, long_description_content_type="text/markdown", - install_requires=["requests", "tabulate"], + install_requires=["requests"], extras_require={ "test": ["requests_mock"], }, From d4828a4465506342e5bf5eb89f16a7bfbce618f1 Mon Sep 17 00:00:00 2001 From: relikd Date: Wed, 21 Feb 2024 00:22:43 +0100 Subject: [PATCH 2/3] ref: make def private --- remotezip.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/remotezip.py b/remotezip.py index b36a75d..8001051 100755 --- a/remotezip.py +++ b/remotezip.py @@ -263,10 +263,10 @@ def _list_files(url, support_suffix_range, filenames): zinfo = zip.getinfo(fname) dt = datetime(*zinfo.date_time) data.append((zinfo.file_size, dt.strftime('%Y-%m-%d %H:%M:%S'), zinfo.filename)) - printTable(data, ('Length', 'DateTime', 'Name'), '><<') + _printTable(data, ('Length', 'DateTime', 'Name'), '><<') -def printTable(data, header, align): +def _printTable(data, header, align): # get max col width & prepare formatting string col_w = [len(col) for col in header] for row in data: From 7e8604005c601b05415231aed7fc2856c3879eb5 Mon Sep 17 00:00:00 2001 From: relikd Date: Mon, 26 Feb 2024 16:10:33 +0100 Subject: [PATCH 3/3] ref: replace f-string with format --- remotezip.py | 3 ++- setup.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/remotezip.py b/remotezip.py index 8001051..a45f69a 100755 --- a/remotezip.py +++ b/remotezip.py @@ -271,7 +271,8 @@ def _printTable(data, header, align): col_w = [len(col) for col in header] for row in data: col_w = [max(w, len(str(x))) for w, x in zip(col_w, row)] - fmt = ' '.join(f'{{:{a}{w}}}' for w, a in zip(col_w, align + '<' * 99)) + fmt = ' '.join('{{:{}{}}}'.format(a, w) + for w, a in zip(col_w, align + '<' * 99)) # print table print(fmt.format(*header).rstrip()) print(fmt.format(*['-' * w for w in col_w])) diff --git a/setup.py b/setup.py index 55287a6..65c94d4 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='remotezip', - version='0.12.2', + version='0.12.3', author='Giuseppe Tribulato', author_email='gtsystem@gmail.com', py_modules=['remotezip'],