From 621181fec80579ad8c31683c2d84bec730e6f3bb Mon Sep 17 00:00:00 2001 From: Phil Adams Date: Tue, 6 Aug 2024 14:22:10 -0500 Subject: [PATCH] fix(build): migrate setup.py to pyproject.toml This commit migrates the project from the setup.py style of publishing to using pyproject.toml instead. Signed-off-by: Phil Adams --- .bumpversion.toml | 6 +- .travis.yml | 16 ++--- MANIFEST.in | 2 - Makefile | 33 ++++++--- .../authenticators/cp4d_authenticator.py | 2 +- .../authenticators/iam_authenticator.py | 2 +- ibm_cloud_sdk_core/base_service.py | 4 +- ibm_cloud_sdk_core/detailed_response.py | 2 +- .../token_managers/cp4d_token_manager.py | 2 +- .../token_managers/iam_token_manager.py | 2 +- pyproject.toml | 63 ++++++++++++++++ requirements-dev.txt | 6 -- requirements.txt | 4 -- setup.py | 71 ------------------- 14 files changed, 101 insertions(+), 114 deletions(-) delete mode 100644 requirements-dev.txt delete mode 100644 requirements.txt delete mode 100644 setup.py diff --git a/.bumpversion.toml b/.bumpversion.toml index 8191f320..b7bdfa98 100644 --- a/.bumpversion.toml +++ b/.bumpversion.toml @@ -8,9 +8,9 @@ search = "__version__ = '{current_version}'" replace = "__version__ = '{new_version}'" [[tool.bumpversion.files]] -filename = "setup.py" -search = "__version__ = '{current_version}'" -replace = "__version__ = '{new_version}'" +filename = "pyproject.toml" +search = "version = \"{current_version}\"" +replace = "version = \"{new_version}\"" [[tool.bumpversion.files]] filename = "README.md" diff --git a/.travis.yml b/.travis.yml index 307bdce8..09b36146 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,7 @@ stages: if: (tag IS present) AND (fork = false) # Default "install" and "script" steps. -install: - - pip install setuptools=="60.8.2" +install: true script: - make ci @@ -44,12 +43,7 @@ jobs: - stage: Publish-Release python: "3.8" name: Publish-To-PyPi - before_deploy: - - pip install bump-my-version - deploy: - - provider: pypi - setuptools_version: "60.8.2" - user: $PYPI_USER - password: $PYPI_TOKEN - repository: https://upload.pypi.org/legacy - skip_cleanup: true + script: + - make ci + - make publish-deps + - make publish-release diff --git a/MANIFEST.in b/MANIFEST.in index 68bc171c..1aba38f6 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1 @@ -include requirements.txt -include requirements-dev.txt include LICENSE diff --git a/Makefile b/Makefile index 7559c748..58d41d62 100644 --- a/Makefile +++ b/Makefile @@ -3,24 +3,30 @@ # example: "make setup" PYTHON=python3 +LINT=black LINT_DIRS=ibm_cloud_sdk_core test test_integration -setup: deps dev_deps install_project +setup: deps dev-deps install-project -all: upgrade_pip setup test-unit lint +all: upgrade-pip setup test-unit lint -ci: setup test-unit lint +ci: all -upgrade_pip: +publish-release: build-dist publish-dist + +upgrade-pip: ${PYTHON} -m pip install --upgrade pip deps: - ${PYTHON} -m pip install -r requirements.txt + ${PYTHON} -m pip install . + +dev-deps: + ${PYTHON} -m pip install .[dev] -dev_deps: - ${PYTHON} -m pip install -r requirements-dev.txt +publish-deps: + ${PYTHON} -m pip install .[publish] -install_project: +install-project: ${PYTHON} -m pip install -e . test-unit: @@ -28,7 +34,14 @@ test-unit: lint: ${PYTHON} -m pylint ${LINT_DIRS} - black --check ${LINT_DIRS} + ${LINT} --check ${LINT_DIRS} lint-fix: - black ${LINT_DIRS} + ${LINT} ${LINT_DIRS} + +build-dist: + rm -fr dist + ${PYTHON} -m build + +publish-dist: + TWINE_USERNAME=__token__ ${PYTHON} -m twine upload --non-interactive --verbose -r testpypi dist/* diff --git a/ibm_cloud_sdk_core/authenticators/cp4d_authenticator.py b/ibm_cloud_sdk_core/authenticators/cp4d_authenticator.py index ec389051..bcde5089 100644 --- a/ibm_cloud_sdk_core/authenticators/cp4d_authenticator.py +++ b/ibm_cloud_sdk_core/authenticators/cp4d_authenticator.py @@ -62,7 +62,7 @@ def __init__( disable_ssl_verification: bool = False, headers: Optional[Dict[str, str]] = None, proxies: Optional[Dict[str, str]] = None, - verify: Optional[str] = None + verify: Optional[str] = None, ) -> None: # Check the type of `disable_ssl_verification`. Must be a bool. if not isinstance(disable_ssl_verification, bool): diff --git a/ibm_cloud_sdk_core/authenticators/iam_authenticator.py b/ibm_cloud_sdk_core/authenticators/iam_authenticator.py index dac36fbe..02c67dd9 100644 --- a/ibm_cloud_sdk_core/authenticators/iam_authenticator.py +++ b/ibm_cloud_sdk_core/authenticators/iam_authenticator.py @@ -66,7 +66,7 @@ def __init__( disable_ssl_verification: bool = False, headers: Optional[Dict[str, str]] = None, proxies: Optional[Dict[str, str]] = None, - scope: Optional[str] = None + scope: Optional[str] = None, ) -> None: # Check the type of `disable_ssl_verification`. Must be a bool. if not isinstance(disable_ssl_verification, bool): diff --git a/ibm_cloud_sdk_core/base_service.py b/ibm_cloud_sdk_core/base_service.py index e97fcc10..27298189 100644 --- a/ibm_cloud_sdk_core/base_service.py +++ b/ibm_cloud_sdk_core/base_service.py @@ -94,7 +94,7 @@ def __init__( service_url: str = None, authenticator: Authenticator = None, disable_ssl_verification: bool = False, - enable_gzip_compression: bool = False + enable_gzip_compression: bool = False, ) -> None: self.set_service_url(service_url) self.http_client = requests.Session() @@ -364,7 +364,7 @@ def prepare_request( params: Optional[dict] = None, data: Optional[Union[str, dict]] = None, files: Optional[Union[Dict[str, Tuple[str]], List[Tuple[str, Tuple[str, ...]]]]] = None, - **kwargs + **kwargs, ) -> dict: """Build a dict that represents an HTTP service request. diff --git a/ibm_cloud_sdk_core/detailed_response.py b/ibm_cloud_sdk_core/detailed_response.py index d92e8998..257f300e 100644 --- a/ibm_cloud_sdk_core/detailed_response.py +++ b/ibm_cloud_sdk_core/detailed_response.py @@ -40,7 +40,7 @@ def __init__( *, response: Optional[Union[dict, requests.Response]] = None, headers: Optional[Dict[str, str]] = None, - status_code: Optional[int] = None + status_code: Optional[int] = None, ) -> None: self.result = response self.headers = headers diff --git a/ibm_cloud_sdk_core/token_managers/cp4d_token_manager.py b/ibm_cloud_sdk_core/token_managers/cp4d_token_manager.py index ddbfb867..9f4b623b 100644 --- a/ibm_cloud_sdk_core/token_managers/cp4d_token_manager.py +++ b/ibm_cloud_sdk_core/token_managers/cp4d_token_manager.py @@ -63,7 +63,7 @@ def __init__( disable_ssl_verification: bool = False, headers: Optional[Dict[str, str]] = None, proxies: Optional[Dict[str, str]] = None, - verify: Optional[str] = None + verify: Optional[str] = None, ) -> None: self.username = username self.password = password diff --git a/ibm_cloud_sdk_core/token_managers/iam_token_manager.py b/ibm_cloud_sdk_core/token_managers/iam_token_manager.py index 91a48917..39bafb0b 100644 --- a/ibm_cloud_sdk_core/token_managers/iam_token_manager.py +++ b/ibm_cloud_sdk_core/token_managers/iam_token_manager.py @@ -71,7 +71,7 @@ def __init__( disable_ssl_verification: bool = False, headers: Optional[Dict[str, str]] = None, proxies: Optional[Dict[str, str]] = None, - scope: Optional[str] = None + scope: Optional[str] = None, ) -> None: super().__init__( url=url, diff --git a/pyproject.toml b/pyproject.toml index 6ae249d0..456191b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,66 @@ +[project] +name = "ibm-cloud-sdk-core" +version = "3.20.4" +authors = [ + { name="IBM", email="devxsdk@us.ibm.com" } +] +description = "Core library used by SDKs for IBM Cloud Services" +readme = "README.md" +requires-python = ">=3.8" +classifiers = [ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Software Development :: Libraries :: Application Frameworks", +] +keywords=["ibm", "cloud", "ibm cloud services"] +dependencies = [ + "requests>=2.31.0,<3.0.0", + "urllib3>=2.1.0,<3.0.0", + "python_dateutil>=2.8.2,<3.0.0", + "PyJWT>=2.8.0,<3.0.0", +] + +[project.urls] +Repository = "https://github.com/IBM/python-sdk-core" +Documentation = "https://github.com/IBM/python-sdk-core/blob/main/README.md" +Issues = "https://github.com/IBM/python-sdk-core/issues" +Changelog = "https://github.com/IBM/python-sdk-core/blob/main/CHANGELOG.md" +Contributing = "https://github.com/IBM/python-sdk-core/blob/main/CONTRIBUTING.md" +License = "https://github.com/IBM/python-sdk-core/blob/main/LICENSE" + +[project.optional-dependencies] +dev = [ + "coverage>=7.3.2,<8.0.0", + "pylint>=3.0.0,<4.0.0", + "pytest>=7.4.2,<8.0.0", + "pytest-cov>=4.1.0,<5.0.0", + "responses>=0.23.3,<1.0.0", + "black>=24.0.0,<25.0.0", +] +publish = [ + "build", + "twine" +] + +[build-system] +requires = ["setuptools>=67.7.2"] +build-backend = "setuptools.build_meta" + +[tool.setuptools] +packages = ["ibm_cloud_sdk_core"] + [tool.black] line-length = 120 skip-string-normalization = true diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index a80bcd71..00000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,6 +0,0 @@ -coverage>=7.3.2,<8.0.0 -pylint>=3.0.0,<4.0.0 -pytest>=7.4.2,<8.0.0 -pytest-cov>=4.1.0,<5.0.0 -responses>=0.23.3,<1.0.0 -black>=24.0.0,<25.0.0 diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 0fd6e2a2..00000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -requests>=2.31.0,<3.0.0 -urllib3>=2.1.0,<3.0.0 -python_dateutil>=2.8.2,<3.0.0 -PyJWT>=2.8.0,<3.0.0 diff --git a/setup.py b/setup.py deleted file mode 100644 index febbbb01..00000000 --- a/setup.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python -# Copyright 2019 IBM All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import sys -import pkg_resources -from setuptools import setup, find_packages - -__version__ = '3.20.4' - -if sys.argv[-1] == 'publish': - # test server - os.system('python setup.py register -r pypitest') - os.system('python setup.py sdist upload -r pypitest') - - # production server - os.system('python setup.py register -r pypi') - os.system('python setup.py sdist upload -r pypi') - sys.exit() - -with open('requirements.txt', encoding='utf-8') as f: - install_requires = [str(req) for req in pkg_resources.parse_requirements(f)] -with open('requirements-dev.txt', encoding='utf-8') as f: - tests_require = [str(req) for req in pkg_resources.parse_requirements(f)] - -with open("README.md", "r", encoding='utf-8') as fh: - readme = fh.read() - -setup( - name='ibm-cloud-sdk-core', - version=__version__, - description='Core library used by SDKs for IBM Cloud Services', - license='Apache 2.0', - install_requires=install_requires, - tests_require=tests_require, - author='IBM', - author_email='devxsdk@us.ibm.com', - long_description=readme, - long_description_content_type='text/markdown', - url='https://github.com/IBM/python-sdk-core', - packages=find_packages(), - include_package_data=True, - keywords='ibm, cloud, ibm cloud services', - classifiers=[ - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: Apache Software License', - 'Operating System :: OS Independent', - 'Topic :: Software Development :: Libraries :: Python Modules', - 'Topic :: Software Development :: Libraries :: Application Frameworks', - ], - zip_safe=True, -)