diff --git a/CHANGELOG.md b/CHANGELOG.md index d4d2741..a5c0bd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 969dabc..2ad6526 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 | `test@test.com` | 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 [reserver@openscilab.com](mailto:reserver@openscilab.com "reserver@openscilab.com"). diff --git a/reserver/reserver_obj.py b/reserver/reserver_obj.py index ceb3669..5c908d1 100644 --- a/reserver/reserver_obj.py +++ b/reserver/reserver_obj.py @@ -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. @@ -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 @@ -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 @@ -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 @@ -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: diff --git a/reserver/util.py b/reserver/util.py index 769e1b1..520e7ed 100644 --- a/reserver/util.py +++ b/reserver/util.py @@ -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.