Skip to content

Commit

Permalink
Minor edits applied (#23)
Browse files Browse the repository at this point in the history
* edit : minor edits.

* remove : extra spaces removed.

* fix : minor issues fixed in `reserver_obj.py`.

* update : `Uploader` updated to `PyPIUploader`.

* fix : tiny little blue line removed.
  • Loading branch information
sadrasabouri authored Apr 23, 2024
1 parent 819d533 commit abc9058
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 36 deletions.
1 change: 0 additions & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@

# Other Contributors #
----------

28 changes: 9 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@
<img src="https://github.com/openscilab/reserver/raw/main/otherfiles/reserver.png" width="300" height="300">
<br/>
<br/>
<a href="https://codecov.io/gh/openscilab/reserver">
<img src="https://codecov.io/gh/openscilab/reserver/branch/main/graph/badge.svg" alt="Codecov"/>
</a>
<a href="https://badge.fury.io/py/reserver">
<img src="https://badge.fury.io/py/reserver.svg" alt="PyPI version" height="18">
</a>
<a href="https://www.python.org/">
<img src="https://img.shields.io/badge/built%20with-Python3-green.svg" alt="built with Python3">
</a>
<a href="https://discord.gg/RD2y6SGuY3">
<img src="https://img.shields.io/discord/1064533716615049236.svg" alt="Discord Channel">
</a>
<a href="https://codecov.io/gh/openscilab/reserver"><img src="https://codecov.io/gh/openscilab/reserver/branch/main/graph/badge.svg" alt="Codecov"/></a>
<a href="https://badge.fury.io/py/reserver"><img src="https://badge.fury.io/py/reserver.svg" alt="PyPI version" height="18"></a>
<a href="https://www.python.org/"><img src="https://img.shields.io/badge/built%20with-Python3-green.svg" alt="built with Python3"></a>
<a href="https://discord.gg/RD2y6SGuY3"><img src="https://img.shields.io/discord/1064533716615049236.svg" alt="Discord Channel"></a>
</div>

----------
Expand Down Expand Up @@ -91,9 +83,9 @@ Reserver is an open source Python package that offers the ability to quickly
## Usage
### Secure your desired PyPI package name!
```python
from reserver import Uploader
uploader = Uploader(PYPI_API_TOKEN, test_pypi= False)
uploader.upload_to_pypi("CONSIDERED_NAME_FOR_YOUR_PACKAGE")
from reserver import PyPIUploader
uploader = PyPIUploader(PYPI_API_TOKEN, test_pypi= False)
uploader.upload("CONSIDERED_NAME_FOR_YOUR_PACKAGE")
```

## Issues & bug reports
Expand All @@ -104,9 +96,7 @@ Just fill an issue and describe it. We'll check it ASAP! or send an email to [in

You can also join our discord server

<a href="https://discord.gg/RD2y6SGuY3">
<img src="https://img.shields.io/discord/1064533716615049236.svg?style=for-the-badge" alt="Discord Channel">
</a>
<a href="https://discord.gg/RD2y6SGuY3"><img src="https://img.shields.io/discord/1064533716615049236.svg?style=for-the-badge" alt="Discord Channel"></a>

## References

Expand All @@ -123,4 +113,4 @@ Give a ⭐️ if this project helped you!
### Donate to our project
If you do like our project and we hope that you do, can you please support us? Our project is not and is never going to be working for profit. We need the money just so we can continue doing what we do ;-) .

<a href="https://openscilab.com/#donation" target="_blank"><img src="https://github.com/openscilab/reserver/raw/main/otherfiles/donation.png" height="90px" width="270px" alt="Reserver Donation"></a>
<a href="https://openscilab.com/#donation" target="_blank"><img src="https://github.com/openscilab/reserver/raw/main/otherfiles/donation.png" height="90px" width="270px" alt="Reserver Donation"></a>
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ vulture>=1.0
bandit>=1.5.1
pydocstyle>=3.0.0
pytest>=4.3.1
pytest-cov>=2.6.1
pytest-cov>=2.6.1
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
requests>=1.0.0
setuptools>=40.8.0
wheel>=0.40.0
twine>=4.0.0
twine>=4.0.0
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
10 changes: 5 additions & 5 deletions tests/test_reserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@

def test_package_exists():
# test reserved name
uploader = PyPIUploader(test_pypi_token, test_pypi= True)
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)
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 = PyPIUploader(wrong_pypi_token, test_pypi= True)
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 = PyPIUploader(test_pypi_token, test_pypi= True)
# uploader = PyPIUploader(test_pypi_token, test_pypi=True)
# uploader.upload_to_pypi(get_random_name())
assert True == True
assert True == True

0 comments on commit abc9058

Please sign in to comment.