From b4bcaf2d856883a8024824599e3122a38d31147e Mon Sep 17 00:00:00 2001 From: AHReccese Date: Sun, 14 Apr 2024 18:22:19 +0330 Subject: [PATCH 1/9] add `batch_upload_to_pypi` to `reserver_obj.py` --- reserver/reserver_obj.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/reserver/reserver_obj.py b/reserver/reserver_obj.py index b8d52b8..85d6cdf 100644 --- a/reserver/reserver_obj.py +++ b/reserver/reserver_obj.py @@ -29,7 +29,19 @@ def __init__(self, api_token, test_pypi=False): self.password = api_token self.test_pypi = test_pypi - + + def batch_upload_to_pypi(self, *names): + """ + Upload batch of package names to PyPI. + + :param names: packages' names + :type names: vararg + :return: None + """ + for name in names: + self.upload_to_pypi(name) + + def upload_to_pypi(self, package_name): """ Upload a template package to pypi or test_pypi. From 6ffef464e3b65c18342eaa4d1ab7ec22ec0ed00a Mon Sep 17 00:00:00 2001 From: AHReccese Date: Sun, 14 Apr 2024 18:22:38 +0330 Subject: [PATCH 2/9] add `test_batch_packages_names` testcase --- tests/test_reserver.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_reserver.py b/tests/test_reserver.py index ee02f75..f2c2e75 100644 --- a/tests/test_reserver.py +++ b/tests/test_reserver.py @@ -8,6 +8,12 @@ def test_package_exists(): uploader = Uploader(test_pypi_token, test_pypi= True) assert uploader.upload_to_pypi("numpy") == False +def test_batch_packages_names(): + # test batch of package names + uploader = Uploader(test_pypi_token, test_pypi= True) + uploader.batch_upload_to_pypi("numpy", "scikit-learn") + assert True == True + def test_valid_package_invalid_credentials(): # test not reserved name -> wrong credentials wrong_pypi_token = "pypi-wrong-api-token" From 505bf185d932955e4bf945f5d07611a34ddabaec Mon Sep 17 00:00:00 2001 From: AHReccese Date: Sun, 14 Apr 2024 18:44:13 +0330 Subject: [PATCH 3/9] `CHANGELOG.md` updated --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee53aba..82a0a2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Added +- Batch of package names reservation +- testcase for batch package name reservation in `test_reserver.py` ### Changed - `README.md` modified ## [0.1] - 2024-02-07 From ccf69f209a753e28e26d2aa7333a9aa288aefef6 Mon Sep 17 00:00:00 2001 From: AHReccese Date: Mon, 15 Apr 2024 22:17:41 +0330 Subject: [PATCH 4/9] apply renamings --- reserver/__init__.py | 2 +- reserver/reserver_obj.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/reserver/__init__.py b/reserver/__init__.py index 2e2ac3c..2e01bba 100644 --- a/reserver/__init__.py +++ b/reserver/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """Reserver modules.""" from .reserver_param import RESERVER_VERSION -from .reserver_obj import Uploader +from .reserver_obj import PyPIUploader __version__ = RESERVER_VERSION diff --git a/reserver/reserver_obj.py b/reserver/reserver_obj.py index 85d6cdf..ddc089c 100644 --- a/reserver/reserver_obj.py +++ b/reserver/reserver_obj.py @@ -7,30 +7,30 @@ from subprocess import check_output, CalledProcessError from re import sub -class Uploader: +class PyPIUploader: """ - The Reserver Uploader class reserves a package name by uploading a template repo to pypi account. + The Reserver PyPIUploader class reserves a package name by uploading a template repo to pypi account. - >>> uploader = Uploader(API_TOKEN, is_test_pypi_account = True) # API_TOKEN refers to pypi(or test pypi)'s account api. + >>> uploader = PyPIUploader(API_TOKEN, is_test_pypi_account = True) # API_TOKEN refers to pypi(or test pypi)'s account api. >>> uploader.upload_to_pypi(PACKAGE_NAME) # uploads package to the given test pypi account. """ def __init__(self, api_token, test_pypi=False): """ - Initialize the Reserver Uploader instance. + Initialize the Reserver PyPIUploader instance. :param api_token: pypi account's api token :type api_token: str :param test_pypi: indicates the given api_token is for a test.pypi account or not. :type test_pypi: bool - :return: an instance of the Reserver Uploader + :return: an instance of the Reserver PyPIUploader """ self.username = "__token__" self.password = api_token self.test_pypi = test_pypi - def batch_upload_to_pypi(self, *names): + def batch_upload(self, *names): """ Upload batch of package names to PyPI. @@ -39,10 +39,10 @@ def batch_upload_to_pypi(self, *names): :return: None """ for name in names: - self.upload_to_pypi(name) + self.upload(name) - def upload_to_pypi(self, package_name): + def upload(self, package_name): """ Upload a template package to pypi or test_pypi. From 3d311995853f97695adf0385c9e0310f0f73bb06 Mon Sep 17 00:00:00 2001 From: AHReccese Date: Mon, 15 Apr 2024 22:17:47 +0330 Subject: [PATCH 5/9] `CHANGELOG.md` updated --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82a0a2f..6d80947 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Added -- Batch of package names reservation -- testcase for batch package name reservation in `test_reserver.py` +- `batch_upload` method added to `PyPIUploader` ### Changed - `README.md` modified ## [0.1] - 2024-02-07 From 7c5b013f9d9707208cbd7fcdc42647db5085ab99 Mon Sep 17 00:00:00 2001 From: AHReccese Date: Mon, 15 Apr 2024 22:21:48 +0330 Subject: [PATCH 6/9] update testcases --- tests/test_reserver.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_reserver.py b/tests/test_reserver.py index f2c2e75..e00452b 100644 --- a/tests/test_reserver.py +++ b/tests/test_reserver.py @@ -1,27 +1,27 @@ -from reserver import Uploader +from reserver import PyPIUploader from reserver.reserver_func import get_random_name import os test_pypi_token = os.environ.get("TEST_PYPI_PASSWORD") def test_package_exists(): # test reserved name - uploader = Uploader(test_pypi_token, test_pypi= True) - assert uploader.upload_to_pypi("numpy") == False + uploader = PyPIUploader(test_pypi_token, test_pypi= True) + assert uploader.upload("numpy") == False def test_batch_packages_names(): # test batch of package names - uploader = Uploader(test_pypi_token, test_pypi= True) - uploader.batch_upload_to_pypi("numpy", "scikit-learn") + uploader = PyPIUploader(test_pypi_token, test_pypi= True) + uploader.batch_upload("numpy", "scikit-learn") assert True == True def test_valid_package_invalid_credentials(): # test not reserved name -> wrong credentials wrong_pypi_token = "pypi-wrong-api-token" - uploader = Uploader(wrong_pypi_token, test_pypi= True) - assert uploader.upload_to_pypi(get_random_name()) == False + uploader = PyPIUploader(wrong_pypi_token, test_pypi= True) + assert uploader.upload(get_random_name()) == False def test_valid_package_valid_credentials(): # test not reserved name -> correct credentials - # uploader = Uploader(test_pypi_token, test_pypi= True) + # uploader = PyPIUploader(test_pypi_token, test_pypi= True) # uploader.upload_to_pypi(get_random_name()) assert True == True \ No newline at end of file From ca9c971c395e1e52cf09218ab785af419ccf7757 Mon Sep 17 00:00:00 2001 From: AHReccese Date: Tue, 16 Apr 2024 15:14:08 +0330 Subject: [PATCH 7/9] enhance `batch_upload` functionality --- reserver/reserver_obj.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/reserver/reserver_obj.py b/reserver/reserver_obj.py index ddc089c..d12dec8 100644 --- a/reserver/reserver_obj.py +++ b/reserver/reserver_obj.py @@ -38,8 +38,15 @@ def batch_upload(self, *names): :type names: vararg :return: None """ + reserved_successfully = 0 for name in names: - self.upload(name) + if isinstance(name, list): + reserved_successfully += self.batch_upload(*name) + else: + is_reserved = self.upload(name) + if is_reserved: + reserved_successfully += 1 + return reserved_successfully def upload(self, package_name): From c916f798e707bb78b8990f99a52d8a98144b1016 Mon Sep 17 00:00:00 2001 From: AHReccese Date: Tue, 16 Apr 2024 15:14:18 +0330 Subject: [PATCH 8/9] `CHANGELOG.md` updated --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d80947..0d247ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - `batch_upload` method added to `PyPIUploader` ### Changed +- `Uploader` changed to `PyPIUploader` - `README.md` modified ## [0.1] - 2024-02-07 ### Added From ce7910945c84d81329ab3c7024407ff1701e6430 Mon Sep 17 00:00:00 2001 From: AHReccese Date: Tue, 16 Apr 2024 15:14:41 +0330 Subject: [PATCH 9/9] enhance `batch_upload` testcase --- tests/test_reserver.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_reserver.py b/tests/test_reserver.py index e00452b..ca0a789 100644 --- a/tests/test_reserver.py +++ b/tests/test_reserver.py @@ -11,8 +11,7 @@ def test_package_exists(): def test_batch_packages_names(): # test batch of package names uploader = PyPIUploader(test_pypi_token, test_pypi= True) - uploader.batch_upload("numpy", "scikit-learn") - assert True == True + assert uploader.batch_upload("numpy", "scikit-learn") == 0 def test_valid_package_invalid_credentials(): # test not reserved name -> wrong credentials