From 6ec837bbdaa8cdfd28f3058b1f0f2d42e5c5c928 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 19 Sep 2022 13:52:14 +0300 Subject: [PATCH 1/8] Switch to PEP 517 packaging using hatchling Refs #1316 Refs #1649 Remake of #2388 Co-authored-by: Ofek Lev --- .github/workflows/docs.yaml | 2 +- .github/workflows/pypi-publish.yaml | 6 +-- CONTRIBUTING.md | 2 +- INSTALL | 6 --- MANIFEST.in | 8 ---- docs/examples/opentelemetry/README.md | 2 +- pyproject.toml | 63 ++++++++++++++++++++++++++ setup.py | 65 --------------------------- tasks.py | 2 +- 9 files changed, 69 insertions(+), 87 deletions(-) delete mode 100644 INSTALL delete mode 100644 MANIFEST.in create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index a3512b46dc..747b3b6d76 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -36,7 +36,7 @@ jobs: sudo apt-get install -yqq pandoc make - name: run code linters run: | - pip install -r requirements.txt -r dev_requirements.txt -r docs/requirements.txt + pip install -r dev_requirements.txt -r docs/requirements.txt invoke build-docs - name: upload docs diff --git a/.github/workflows/pypi-publish.yaml b/.github/workflows/pypi-publish.yaml index e4815aa1b5..94c79c7c4a 100644 --- a/.github/workflows/pypi-publish.yaml +++ b/.github/workflows/pypi-publish.yaml @@ -21,12 +21,10 @@ jobs: - name: Install dev tools run: | pip install -r dev_requirements.txt - pip install twine wheel + pip install build twine wheel - name: Build package - run: | - python setup.py build - python setup.py sdist bdist_wheel + run: python -m build . - name: Basic package test prior to upload run: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d87e6ba1c3..79983e4cb5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,7 +38,7 @@ Here's how to get started with your code contribution: a. python -m venv .venv b. source .venv/bin/activate c. pip install -r dev_requirements.txt - c. pip install -r requirements.txt + c. pip install -e . 4. If you need a development environment, run `invoke devenv`. Note: this relies on docker-compose to build environments, and assumes that you have a version supporting [docker profiles](https://docs.docker.com/compose/profiles/). 5. While developing, make sure the tests pass by running `invoke tests` diff --git a/INSTALL b/INSTALL deleted file mode 100644 index 951f7dea8a..0000000000 --- a/INSTALL +++ /dev/null @@ -1,6 +0,0 @@ - -Please use - python setup.py install - -and report errors to Andy McCurdy (sedrik@gmail.com) - diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 80afb437ff..0000000000 --- a/MANIFEST.in +++ /dev/null @@ -1,8 +0,0 @@ -include INSTALL -include LICENSE -include README.md -include dev_requirements.txt -include pytest.ini -exclude __pycache__ -recursive-include tests * -recursive-exclude tests *.pyc diff --git a/docs/examples/opentelemetry/README.md b/docs/examples/opentelemetry/README.md index a1d1c04eda..58085c9637 100644 --- a/docs/examples/opentelemetry/README.md +++ b/docs/examples/opentelemetry/README.md @@ -24,7 +24,7 @@ source .venv/bin/active **Step 3**. Install dependencies: ```shell -pip install -r requirements.txt +pip install -e . ``` **Step 4**. Start the services using Docker and make sure Uptrace is running: diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..e54dade48f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,63 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "redis" +version = "5.2.1" +description = "Python client for Redis database and key-value store" +readme = "README.md" +license = "MIT" +requires-python = ">=3.8" +authors = [ + { name = "Redis Inc.", email = "oss@redis.com" }, +] +keywords = [ + "Redis", + "database", + "key-value-store", +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "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", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", +] +dependencies = [ + 'async-timeout>=4.0.3; python_full_version<"3.11.3"', + "PyJWT~=2.9.0", +] + +[project.optional-dependencies] +hiredis = [ + "hiredis>=3.0.0", +] +ocsp = [ + "cryptography>=36.0.1", + "pyopenssl==20.0.1", + "requests>=2.31.0", +] + +[project.urls] +Changes = "https://github.com/redis/redis-py/releases" +Code = "https://github.com/redis/redis-py" +Documentation = "https://redis.readthedocs.io/en/latest/" +Homepage = "https://github.com/redis/redis-py" +"Issue tracker" = "https://github.com/redis/redis-py/issues" + +[tool.hatch.build.targets.sdist] +include = [ + "/redis", +] diff --git a/setup.py b/setup.py deleted file mode 100644 index 2cde3fb51b..0000000000 --- a/setup.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env python -from setuptools import find_packages, setup - -setup( - name="redis", - description="Python client for Redis database and key-value store", - long_description=open("README.md").read().strip(), - long_description_content_type="text/markdown", - keywords=["Redis", "key-value store", "database"], - license="MIT", - version="5.2.1", - packages=find_packages( - include=[ - "redis", - "redis._parsers", - "redis.asyncio", - "redis.auth", - "redis.commands", - "redis.commands.bf", - "redis.commands.json", - "redis.commands.search", - "redis.commands.timeseries", - "redis.commands.graph", - "redis.parsers", - ] - ), - package_data={"redis": ["py.typed"]}, - include_package_data=True, - url="https://github.com/redis/redis-py", - project_urls={ - "Documentation": "https://redis.readthedocs.io/en/latest/", - "Changes": "https://github.com/redis/redis-py/releases", - "Code": "https://github.com/redis/redis-py", - "Issue tracker": "https://github.com/redis/redis-py/issues", - }, - author="Redis Inc.", - author_email="oss@redis.com", - python_requires=">=3.8", - install_requires=[ - 'async-timeout>=4.0.3; python_full_version<"3.11.3"', - "PyJWT~=2.9.0", - ], - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Environment :: Console", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3 :: Only", - "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", - "Programming Language :: Python :: 3.13", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", - ], - extras_require={ - "hiredis": ["hiredis>=3.0.0"], - "ocsp": ["cryptography>=36.0.1", "pyopenssl==23.2.1", "requests>=2.31.0"], - }, -) diff --git a/tasks.py b/tasks.py index f7b728aed4..8a5cae97b2 100644 --- a/tasks.py +++ b/tasks.py @@ -97,4 +97,4 @@ def clean(c): @task def package(c): """Create the python packages""" - run("python setup.py sdist bdist_wheel") + run("python -m build .") From 8e467b72dc5051ecacc3843196edbd00abb5aeac Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 27 Aug 2024 12:26:37 +0300 Subject: [PATCH 2/8] Use a single source of truth for version info --- pyproject.toml | 5 ++++- redis/__init__.py | 13 ++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e54dade48f..10ecaab86f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "redis" -version = "5.2.1" +dynamic = ["version"] description = "Python client for Redis database and key-value store" readme = "README.md" license = "MIT" @@ -57,6 +57,9 @@ Documentation = "https://redis.readthedocs.io/en/latest/" Homepage = "https://github.com/redis/redis-py" "Issue tracker" = "https://github.com/redis/redis-py/issues" +[tool.hatch.version] +path = "redis/__init__.py" + [tool.hatch.build.targets.sdist] include = [ "/redis", diff --git a/redis/__init__.py b/redis/__init__.py index 94324a0de8..f82a876b2d 100644 --- a/redis/__init__.py +++ b/redis/__init__.py @@ -1,5 +1,3 @@ -from importlib import metadata - from redis import asyncio # noqa from redis.backoff import default_backoff from redis.client import Redis, StrictRedis @@ -44,16 +42,9 @@ def int_or_str(value): return value -try: - __version__ = metadata.version("redis") -except metadata.PackageNotFoundError: - __version__ = "99.99.99" - +__version__ = "5.2.1" +VERSION = tuple(map(int_or_str, __version__.split("."))) -try: - VERSION = tuple(map(int_or_str, __version__.split("."))) -except AttributeError: - VERSION = tuple([99, 99, 99]) __all__ = [ "AuthenticationError", From 7327e73c1f795aeab30747d6082d6d58d185ae6f Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Fri, 21 Feb 2025 10:31:42 +0200 Subject: [PATCH 3/8] Uninstall redis wheel installed as redis-entraid dep --- .github/actions/run-tests/action.yml | 2 ++ .github/workflows/install_and_test.sh | 1 + .github/workflows/integration.yaml | 1 + .github/workflows/pypi-publish.yaml | 1 + 4 files changed, 5 insertions(+) diff --git a/.github/actions/run-tests/action.yml b/.github/actions/run-tests/action.yml index ca775f5a5b..63a6889b9b 100644 --- a/.github/actions/run-tests/action.yml +++ b/.github/actions/run-tests/action.yml @@ -39,6 +39,8 @@ runs: pip install -U setuptools wheel pip install -r requirements.txt pip install -r dev_requirements.txt + pip uninstall -y redis # uninstall Redis package installed via redis-entraid + pip install -e . # install the working copy if [ "${{inputs.parser-backend}}" == "hiredis" ]; then pip install "hiredis${{inputs.hiredis-version}}" echo "PARSER_BACKEND=$(echo "${{inputs.parser-backend}}_${{inputs.hiredis-version}}" | sed 's/[^a-zA-Z0-9]/_/g')" >> $GITHUB_ENV diff --git a/.github/workflows/install_and_test.sh b/.github/workflows/install_and_test.sh index 5c879c1b3a..778dbe0b20 100755 --- a/.github/workflows/install_and_test.sh +++ b/.github/workflows/install_and_test.sh @@ -21,6 +21,7 @@ python -m venv ${DESTENV} source ${DESTENV}/bin/activate pip install --upgrade --quiet pip pip install --quiet -r dev_requirements.txt +pip uninstall -y redis # uninstall Redis package installed via redis-entraid invoke devenv --endpoints=all-stack invoke package diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 45e0d5bf8e..55195d4163 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -54,6 +54,7 @@ jobs: - name: run code linters run: | pip install -r dev_requirements.txt + pip uninstall -y redis # uninstall Redis package installed via redis-entraid invoke linters redis_version: diff --git a/.github/workflows/pypi-publish.yaml b/.github/workflows/pypi-publish.yaml index 94c79c7c4a..50f9fb601f 100644 --- a/.github/workflows/pypi-publish.yaml +++ b/.github/workflows/pypi-publish.yaml @@ -21,6 +21,7 @@ jobs: - name: Install dev tools run: | pip install -r dev_requirements.txt + pip uninstall -y redis # uninstall Redis package installed via redis-entraid pip install build twine wheel - name: Build package From 9cb7ac470f3e6effae8a8709e96825ffc06eb4ca Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 25 Feb 2025 09:56:35 +0200 Subject: [PATCH 4/8] Add build as dev_requirement --- dev_requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/dev_requirements.txt b/dev_requirements.txt index 619fbf479c..a5abf34172 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -1,3 +1,4 @@ +build black==24.3.0 click==8.0.4 flake8-isort From 34bedf996529c2975930a20348e1823ae119d04b Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 25 Feb 2025 09:58:18 +0200 Subject: [PATCH 5/8] Get rid of requirements.txt --- .github/actions/run-tests/action.yml | 1 - .github/workflows/integration.yaml | 2 +- requirements.txt | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 requirements.txt diff --git a/.github/actions/run-tests/action.yml b/.github/actions/run-tests/action.yml index 63a6889b9b..b656685ec9 100644 --- a/.github/actions/run-tests/action.yml +++ b/.github/actions/run-tests/action.yml @@ -37,7 +37,6 @@ runs: echo "::group::Installing dependencies" pip install -U setuptools wheel - pip install -r requirements.txt pip install -r dev_requirements.txt pip uninstall -y redis # uninstall Redis package installed via redis-entraid pip install -e . # install the working copy diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index 55195d4163..bb56e8a024 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -38,7 +38,7 @@ jobs: - uses: actions/checkout@v4 - uses: pypa/gh-action-pip-audit@v1.0.8 with: - inputs: requirements.txt dev_requirements.txt + inputs: dev_requirements.txt ignore-vulns: | GHSA-w596-4wvx-j9j6 # subversion related git pull, dependency for pytest. There is no impact here. diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 9760e5bb13..0000000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -async-timeout>=4.0.3 -PyJWT~=2.9.0 \ No newline at end of file From 66f344c92a95d88320110e519a8812c367a24dca Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 25 Feb 2025 10:01:21 +0200 Subject: [PATCH 6/8] Get rid of setuptools and wheel deps --- .github/actions/run-tests/action.yml | 1 - .github/workflows/pypi-publish.yaml | 6 +----- dev_requirements.txt | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/actions/run-tests/action.yml b/.github/actions/run-tests/action.yml index b656685ec9..d822e1d499 100644 --- a/.github/actions/run-tests/action.yml +++ b/.github/actions/run-tests/action.yml @@ -36,7 +36,6 @@ runs: set -e echo "::group::Installing dependencies" - pip install -U setuptools wheel pip install -r dev_requirements.txt pip uninstall -y redis # uninstall Redis package installed via redis-entraid pip install -e . # install the working copy diff --git a/.github/workflows/pypi-publish.yaml b/.github/workflows/pypi-publish.yaml index 50f9fb601f..048d06c53c 100644 --- a/.github/workflows/pypi-publish.yaml +++ b/.github/workflows/pypi-publish.yaml @@ -18,11 +18,7 @@ jobs: uses: actions/setup-python@v5 with: python-version: 3.9 - - name: Install dev tools - run: | - pip install -r dev_requirements.txt - pip uninstall -y redis # uninstall Redis package installed via redis-entraid - pip install build twine wheel + - run: pip install build twine - name: Build package run: python -m build . diff --git a/dev_requirements.txt b/dev_requirements.txt index a5abf34172..7ee7ac2b75 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -15,6 +15,5 @@ pytest-timeout ujson>=4.2.0 uvloop vulture>=2.3.0 -wheel>=0.30.0 numpy>=1.24.0 redis-entraid==0.3.0b1 From ec0635837d67fadee3beb30d0902a91a07f1effc Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 25 Feb 2025 10:43:56 +0200 Subject: [PATCH 7/8] Move pytest configuration to pyproject.toml --- pyproject.toml | 23 +++++++++++++++++++++++ pytest.ini | 20 -------------------- 2 files changed, 23 insertions(+), 20 deletions(-) delete mode 100644 pytest.ini diff --git a/pyproject.toml b/pyproject.toml index 10ecaab86f..85172ff36a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,3 +64,26 @@ path = "redis/__init__.py" include = [ "/redis", ] + +[tool.pytest.ini_options] +addopts = "-s" +markers = [ + "redismod: run only the redis module tests", + "graph: run only the redisgraph tests", + "pipeline: pipeline tests", + "onlycluster: marks tests to be run only with cluster mode redis", + "onlynoncluster: marks tests to be run only with standalone redis", + "ssl: marker for only the ssl tests", + "asyncio: marker for async tests", + "replica: replica tests", + "experimental: run only experimental tests", + "cp_integration: credential provider integration tests", +] +asyncio_mode = "auto" +timeout = 30 +filterwarnings = [ + "always", + "ignore:RedisGraph support is deprecated as of Redis Stack 7.2:DeprecationWarning", + # Ignore a coverage warning when COVERAGE_CORE=sysmon for Pythons < 3.12. + "ignore:sys.monitoring isn't available:coverage.exceptions.CoverageWarning", +] diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 68fee2b603..0000000000 --- a/pytest.ini +++ /dev/null @@ -1,20 +0,0 @@ -[pytest] -addopts = -s -markers = - redismod: run only the redis module tests - graph: run only the redisgraph tests - pipeline: pipeline tests - onlycluster: marks tests to be run only with cluster mode redis - onlynoncluster: marks tests to be run only with standalone redis - ssl: marker for only the ssl tests - asyncio: marker for async tests - replica: replica tests - experimental: run only experimental tests - cp_integration: credential provider integration tests -asyncio_mode = auto -timeout = 30 -filterwarnings = - always - ignore:RedisGraph support is deprecated as of Redis Stack 7.2:DeprecationWarning - # Ignore a coverage warning when COVERAGE_CORE=sysmon for Pythons < 3.12. - ignore:sys.monitoring isn't available:coverage.exceptions.CoverageWarning From a0252772a90904faac7f300cfa11997cba096dd7 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 25 Feb 2025 10:45:01 +0200 Subject: [PATCH 8/8] Retain tests and dev_requirements.txt in sdist --- pyproject.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 85172ff36a..7becde948e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,6 +61,13 @@ Homepage = "https://github.com/redis/redis-py" path = "redis/__init__.py" [tool.hatch.build.targets.sdist] +include = [ + "/redis", + "/tests", + "dev_requirements.txt", +] + +[tool.hatch.build.targets.wheel] include = [ "/redis", ]