Skip to content
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 9 commits into from
Apr 19, 2024
Merged

Feature/batch operation #20

merged 9 commits into from
Apr 19, 2024

Conversation

AHReccese
Copy link
Member

Reference Issues/PRs

#19

What does this implement/fix? Explain your changes.

add ability to batch package name reservation

Any other comments?

@AHReccese AHReccese added this to the Reserver v0.2 milestone Apr 14, 2024
@AHReccese AHReccese requested a review from sadrasabouri April 14, 2024 15:15
@AHReccese AHReccese self-assigned this Apr 14, 2024
Copy link
Member

@sadrasabouri sadrasabouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Amirhossein for being ahead of everything.
I left minor comments on your pull request.
Also, I think it might be better to rename Uploader to PypiUploader if the class is scoped only for pypi. Then we can shorten the method's name.

  • upload_to_pypi -> upload
  • batch_upload_to_pypi -> bacth_upload

It's better to overthink these design choices before the beta version so that we can be backward compatible afterward.

CHANGELOG.md Outdated
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer something more to-the-point for the user like:

- `batch_upload_to_pypi` method added to `Uploader`

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

CHANGELOG.md Outdated
@@ -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`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this line. Tests are implicitly logged with the main feature.

for name in names:
self.upload_to_pypi(name)


def upload_to_pypi(self, package_name):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not return True if everything went well?

Copy link
Member Author

@AHReccese AHReccese Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, I should think in more depth about what is False or what is True in this context, but ok I will return sth, maybe the number of names got reserved in this case instead of an ambitious boolean value.

@@ -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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the input to be listed. I think that's a more pythonic solution.
Imagine a simple use case from the user's point of view. They should pass their desired package names list by *pacakge_name to the batch_upload_to_pypi which can be a bit weird for novice users.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this syntax, the user can do both of these:
.batch_upload_to_pypi(NAME1, NAME2, NAME3) and also .batch_upload_to_pypi([NAME1, NAME2, NAME3])
so you can easily pass the array you want to it.
@sadrasabouri if it's not the case, walk through it more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not true I guess. If you use the array call version it tries to call the upload method with the list itself instead of elements. The alternative is .batch_upload(*[NAME1, NAME2, NAME3]).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sure I will investigate this, I think we both do have same intension, sure, I will take care of.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right, thanks
I will take care of it.
@sadrasabouri

Copy link
Member Author

@AHReccese AHReccese Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    def batch_upload(self, *names):
        """
        Upload batch of package names to PyPI.

        :param names: packages' names
        :type names: vararg
        :return: int(number of successfully reserved names)
        """
        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

Happy sir? tests also updated accordingly
@sadrasabouri

Comment on lines 41 to 44
for name in names:
self.upload_to_pypi(name)


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you accept my comments on returning True for upload_to_pypi. This can also return a logical AND of all uploading trials.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, in my opinion, it is way too geeky, I prefer to return the number of actually reserved names here.

# test batch of package names
uploader = Uploader(test_pypi_token, test_pypi= True)
uploader.batch_upload_to_pypi("numpy", "scikit-learn")
assert True == True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you accept my comment on returning True for upload_to_pypi, you can assert the output of that function here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again with the number of actual names reserved, I can handle associated test cases better and ok sure I will.
@sadrasabouri

Copy link
Member

@sadrasabouri sadrasabouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I just left another comment.

@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]
### Added
- `batch_upload` method added to `PyPIUploader`
### Changed
- `README.md` modified
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- `Uploader` changed to `PyPIUploader`

@AHReccese AHReccese requested a review from sadrasabouri April 16, 2024 11:47
Copy link
Member

@sadrasabouri sadrasabouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for you changes.
@sepandhaghighi would you please also take a quick look at the batch_upload implementation and let us know about your thoughts on it?

Comment on lines +33 to +39
def batch_upload(self, *names):
"""
Upload batch of package names to PyPI.

:param names: packages' names
:type names: vararg
:return: None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the doc-string return: None.

@AHReccese
Copy link
Member Author

Hi Sadra, Thank you for your time and review.
Since this is a very minor PR, If it's possible try to wrap it up soon.
@sadrasabouri

Copy link
Member

@sadrasabouri sadrasabouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. But we need a minor edit PR before release. I will do that after modern template PR.

@sadrasabouri sadrasabouri merged commit 76e7b37 into dev Apr 19, 2024
36 checks passed
@sadrasabouri sadrasabouri deleted the feature/batch_operation branch April 19, 2024 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants