Skip to content

Commit

Permalink
fix : minor issues fixed in reserver_obj.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
sadrasabouri committed Apr 22, 2024
1 parent 49b7f76 commit b16cbc6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions reserver/reserver_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from subprocess import check_output, CalledProcessError
from re import sub


class PyPIUploader:
"""
The Reserver PyPIUploader class reserves a package name by uploading a template repo to pypi account.
Expand All @@ -29,14 +30,13 @@ def __init__(self, api_token, test_pypi=False):
self.password = api_token
self.test_pypi = test_pypi


def batch_upload(self, *names):
"""
Upload batch of package names to PyPI.
:param names: packages' names
:type names: vararg
:return: None
:return: Number of successfully reserved packages
"""
reserved_successfully = 0
for name in names:
Expand All @@ -48,19 +48,18 @@ def batch_upload(self, *names):
reserved_successfully += 1
return reserved_successfully


def upload(self, package_name):
"""
Upload a template package to pypi or test_pypi.
:param package_name: package name
:type package_name: str
:return: None
:return: True if the package is successfully reserved, False otherwise
"""
if does_package_exist(package_name, self.test_pypi):
print("This package already exists in PyPI.")
return False
return False

generate_template_setup_py(package_name)

environ["TWINE_USERNAME"] = self.username
Expand Down Expand Up @@ -103,7 +102,7 @@ def upload(self, package_name):
error = "Invalid or non-existent authentication information(PyPI API Key)."
if "400" in error and "too similar to an existing project" in error:
error = "Given package name is too similar to an existing project in PyPI."
break
break

# todo remove env variable
if "TWINE_USERNAME" in environ:
Expand All @@ -119,7 +118,7 @@ def upload(self, package_name):

if publish_failed:
print(f"Publish to PyPI failed because of: ", error)
return False
return False
else:
print("Congratulations! You have successfully reserved the PyPI package: ", package_name)
return True
return True

0 comments on commit b16cbc6

Please sign in to comment.