From 8b53f4235897a5560e36a29a001194c23ae15dad Mon Sep 17 00:00:00 2001 From: Webster Mudge Date: Thu, 12 Sep 2024 12:40:44 -0400 Subject: [PATCH] Convert to using hatch for build and release tooling Signed-off-by: Webster Mudge --- pyproject.toml | 85 +++++++++++++++++++++++++++++++++++++---- src/cdpy/__version__.py | 15 ++++++++ src/cdpy/common.py | 7 ++-- tests/__init__.py | 14 +++++++ 4 files changed, 110 insertions(+), 11 deletions(-) create mode 100644 src/cdpy/__version__.py diff --git a/pyproject.toml b/pyproject.toml index 89a5bed..d06a55b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,78 @@ +[project] +name = "cdpy" +description = "A Pythonic client wrapper for Cloudera CDP CLI" +license = "Apache-2.0" +authors = [ + { name = "Cloudera, Inc.", email = "cloudera-labs@cloudera.com" } +] +keywords = [ + "cloudera", + "cdp", + "ansible-navigator", +] +classifiers = [ + "Development Status :: 4 - Beta", + "Programming Language :: Python" +] +readme = "README.rst" +requires-python = ">=3.8" +dependencies = [ + "importlib-metadata", + "cdpcli-beta>=0.9.101" +] +dynamic = ["version"] + +[project.urls] +Documentation = "https://github.com/cloudera-labs/cdpy/" +"Source Code" = "https://github.com/cloudera-labs/cdpy/" + +[tool.hatch.version] +path = "src/cdpy/__version__.py" + +[tool.hatch.build.targets.sdist] +include = [ + "/src", + "/tests", +] + +[tool.hatch.envs.default] +dependencies = [ + "coverage[toml]", + "pytest", + "pytest-cov", + "wheel", + "flake8", + "pre-commit" +] + +[tool.hatch.envs.default.scripts] +test = 'pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=cdpy --cov=tests' + +[flake8] +# Some sane defaults for the code style checker flake8 +exclude = [ + "build", + "dist", + ".eggs", + "docs/conf.py", +] + +[tool.hatch.envs.docs] +dependencies = [ + "sphinx" +] + +[tool.hatch.envs.docs.scripts] + +[tool.hatch.envs.test] +dependencies = [ + "pytest", + "pytest-sugar" +] + +[[tool.hatch.envs.test.matrix]] +python = ["3.8", "3.9", "3.10", "3.11", "3.12"] + [build-system] -# AVOID CHANGING REQUIRES: IT WILL BE UPDATED BY PYSCAFFOLD! -requires = ["setuptools>=46.1.0", "setuptools_scm[toml]>=5"] -build-backend = "setuptools.build_meta" - -[tool.setuptools_scm] -# For smarter version schemes and other configuration options, -# check out https://github.com/pypa/setuptools_scm -version_scheme = "no-guess-dev" +requires = ["hatchling"] +build-backend = "hatchling.build" diff --git a/src/cdpy/__version__.py b/src/cdpy/__version__.py new file mode 100644 index 0000000..fa7aff4 --- /dev/null +++ b/src/cdpy/__version__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Cloudera, Inc. +# +# 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 +# +# https://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. + +VERSION="1.3.0" diff --git a/src/cdpy/common.py b/src/cdpy/common.py index 11478b5..67db8ae 100644 --- a/src/cdpy/common.py +++ b/src/cdpy/common.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- from datetime import datetime -import pkg_resources from time import time, sleep import html import io @@ -29,6 +28,8 @@ from cdpcli.retryhandler import create_retry_handler from cdpcli.translate import build_retry_config +from cdpy.__version__ import VERSION + class CdpWarning(UserWarning): """Class for deriving custom warnings from UserWarning""" @@ -291,7 +292,7 @@ def _warning_format(message, category, filename, lineno, line=None): } def _make_user_agent_header(self): - cdpy_version = pkg_resources.get_distribution('cdpy').version + cdpy_version = VERSION return '%s CDPY/%s CDPCLI/%s Python/%s %s/%s' % ( self.agent_header, cdpy_version, @@ -630,7 +631,7 @@ def _handle_std_call(self, client, call_function, payload): full_response = raw_response return full_response - def call(self, svc: str, func: str, ret_field: str = None, squelch: ['Squelch'] = None, ret_error: bool = False, + def call(self, svc: str, func: str, ret_field: str = None, squelch: list['Squelch'] = None, ret_error: bool = False, redirect_headers: dict = None, **kwargs: Union[dict, bool, str, list]) -> Union[list, dict, 'CdpError']: """ Wraps the call to an underlying CDP CLI Service, handles common errors, and parses output diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..d13420e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,14 @@ +# Copyright 2024 Cloudera, Inc. +# +# 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 +# +# https://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. +