-
Notifications
You must be signed in to change notification settings - Fork 3
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
Feature/batch operation #20
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b4bcaf2
add `batch_upload_to_pypi` to `reserver_obj.py`
AHReccese 6ffef46
add `test_batch_packages_names` testcase
AHReccese 505bf18
`CHANGELOG.md` updated
AHReccese ccf69f2
apply renamings
AHReccese 3d31199
`CHANGELOG.md` updated
AHReccese 7c5b013
update testcases
AHReccese ca9c971
enhance `batch_upload` functionality
AHReccese c916f79
`CHANGELOG.md` updated
AHReccese ce79109
enhance `batch_upload` testcase
AHReccese File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,30 +7,49 @@ | |
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 upload_to_pypi(self, package_name): | ||
|
||
def batch_upload(self, *names): | ||
""" | ||
Upload batch of package names to PyPI. | ||
|
||
:param names: packages' names | ||
:type names: vararg | ||
:return: None | ||
Comment on lines
+33
to
+39
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. Update the doc-string |
||
""" | ||
reserved_successfully = 0 | ||
for name in names: | ||
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): | ||
""" | ||
Upload a template package to pypi or test_pypi. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
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 = PyPIUploader(test_pypi_token, test_pypi= True) | ||
assert uploader.batch_upload("numpy", "scikit-learn") == 0 | ||
|
||
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.