Skip to content

Commit

Permalink
Enhancements (#52)
Browse files Browse the repository at this point in the history
* CLI samples of reserving package name(s) with customized package parameters added

* `CHANGELOG.md` updated

* add `batch_operation` in `Programmatical` usage

* `autopep8.sh` applied

* `README.md` updated

* `README.md` updated

* fix space issue in paths

* `README.md` updated

* doc : minor edit in README.md headers

---------

Co-authored-by: sepandhaghighi <[email protected]>
  • Loading branch information
AHReccese and sepandhaghighi authored Aug 26, 2024
1 parent 8ad30e9 commit 6b513aa
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `batch_upload` tests
- `read_json` method in `util.py`
### Changed
- `README.md` updated
- `upload` method in `reserver_obj.py`
- `batch_upload` method `reserver_obj.py`
## [0.2] - 2024-06-17
Expand Down
47 changes: 45 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,17 @@ Reserver is an open source Python package that offers the ability to quickly
## Usage

### Programmatically
Reserve a package name in main PyPI (pypi.org)
```python
from reserver import PyPIUploader
uploader = PyPIUploader(PYPI_API_TOKEN, test_pypi= False)
uploader = PyPIUploader(PYPI_TOKEN, test_pypi=False)
uploader.upload("CONSIDERED_NAME_FOR_YOUR_PACKAGE")
```
Reserve batch of names with custom user-defined parameters in test PyPI (test.pypi.org)
```python
uploader = PyPIUploader(TEST_PYPI_TOKEN, test_pypi=True)
uploader.batch_upload(["PACKAGE_NAME_1", "PACKAGE_NAME_2"], ["config1.json", "config2.json"])
```
### CLI
⚠️ You can use `reserver` or `python -m reserver` to run this program
#### Version
Expand All @@ -85,13 +91,50 @@ reserver --version
```
#### Reserve in test PyPI (test.pypi.org)
```console
reserver --name sample_name1 sample_name2 --token=PYPI_TOKEN --test
reserver --name sample_name1 sample_name2 --token=TEST_PYPI_TOKEN --test
```
#### Reserve in main PyPI (pypi.org)
```console
reserver --name sample_name1 sample_name2 --token=PYPI_TOKEN
```
#### Customizing package parameters

You can customize the following package parameters for reservations on PyPI using the Reserver CLI. The details and defaults are provided in the table below.

| Parameter | Type | Default | Description |
|---|---|---|---|
| `description` | string | `This name has been reserved using Reserver` | A short description of your PyPI package name reservation. |
| `author` | string | `Development Team` | The name of the author or development team. |
| `author_email` | email address | `[email protected]` | An email address for contact. |
| `url` | web address | `https://url.com` | The project's main repository URL. |
| `download_url` | web address | `https://download_url.com` | The download URL for the package. |
| `source` | web address | `https://github.com/source` | The source code repository URL. |
| `license` | string | `MIT` | The license under which your package is distributed. |

There are two ways to define these custom parameters:

**1. Single `param.json` for all packages:**

This approach uses a single JSON file (`param.json`) to define common parameters for all packages. This file could hold information like those described in the table.

Here's how to use this method:

```console
reserver --name sample_name1 sample_name2 --param config.json --token=PYPI_TOKEN
```
**2. Dedicated `param.json` per package:**

This approach allows for more customization by having a separate JSON file for each package. Each file would contain parameters specific to that particular package.

Here's how this method works:

```console
reserver --name sample_name1 sample_name2 --param name1_param.json name2_param.json --token=PYPI_TOKEN
```

Choose the method that best suits your needs. Using a single `param.json` is efficient for packages with similar information, while separate files offer more granular control.

⚠️ You can use all available features on both `pypi.org` and `test.pypi.org`.
## Issues & bug reports

Just fill an issue and describe it. We'll check it ASAP! or send an email to [[email protected]](mailto:[email protected] "[email protected]").
Expand Down
20 changes: 10 additions & 10 deletions reserver/reserver_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .util import has_named_parameter, remove_dir, read_json
from .reserver_func import does_package_exist, generate_template_setup_py


class PyPIUploader:
"""
The Reserver PyPIUploader class reserves a package name by uploading a template repo to pypi account.
Expand Down Expand Up @@ -43,7 +44,7 @@ def batch_upload(self, names, user_params_path=None):
:return: Number of successfully reserved packages
"""
reserved_successfully = 0
if user_params_path == None:
if user_params_path is None:
for name in names:
if self.upload(name):
reserved_successfully += 1
Expand Down Expand Up @@ -78,9 +79,9 @@ def upload(self, package_name, user_parameters=None):
print("This package already exists in PyPI.")
return False

if user_parameters != None:
if user_parameters is not None:
user_parameters = read_json(user_parameters)

generate_template_setup_py(package_name, user_parameters)

environ["TWINE_USERNAME"] = self.username
Expand All @@ -97,17 +98,16 @@ def upload(self, package_name, user_parameters=None):
# prevent from uploading any other previously build library in this path.
if path.exists(generated_dist_folder):
remove_dir(generated_dist_folder)

commands = [executable + " " + generated_setup_file_path + " sdist bdist_wheel "]
commands = [f'"{executable}" "{generated_setup_file_path}" sdist bdist_wheel']
if self.test_pypi:
commands += [
executable + " -m twine upload --repository testpypi " + generated_tar_gz_file,
executable + " -m twine upload --repository testpypi " + generated_wheel_file,
f'"{executable}" -m twine upload --repository testpypi "{generated_tar_gz_file}"',
f'"{executable}" -m twine upload --repository testpypi "{generated_wheel_file}"',
]
else:
commands += [
executable + " -m twine upload --verbose " + generated_tar_gz_file,
executable + " -m twine upload --verbose " + generated_wheel_file,
f'"{executable}" -m twine upload --verbose "{generated_tar_gz_file}"',
f'"{executable}" -m twine upload --verbose "{generated_wheel_file}"',
]
# Run the commands
publish_failed = False
Expand All @@ -123,7 +123,7 @@ def upload(self, package_name, user_parameters=None):
error = e.output
try:
error = error.decode(chardet.detect(error)['encoding'])
except:
except BaseException:
error = error.decode('utf-8')
if command == commands[-2]:
if "403" in error and "Invalid or non-existent authentication information" in error:
Expand Down
1 change: 1 addition & 0 deletions reserver/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .reserver_errors import ReserverBaseError
from .reserver_param import INVALID_CONFIG_FILE_NAME_ERROR, PARAM_FILE_DOES_NOT_EXIST_ERROR


def has_named_parameter(func, param_name):
"""
Check whether the given function has a parameter named param_name or not.
Expand Down

0 comments on commit 6b513aa

Please sign in to comment.