diff --git a/.readthedocs.yml b/.readthedocs.yml index b8dd3e7ca..eee10c078 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -11,5 +11,6 @@ build: python: install: - - requirements: dev-requirements.txt - path: . + extra_requirements: + - "docs" diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index f7a1c216d..000000000 --- a/MANIFEST.in +++ /dev/null @@ -1,14 +0,0 @@ -include CONTRIBUTING.md -include LICENSE -include MANIFEST.in -include README.md -include NOTICE -include CHANGELOG.md -include setup.py -recursive-include elasticsearch* py.typed *.pyi -recursive-include docs/sphinx * - -prune docs/sphinx/_build -prune test_elasticsearch -recursive-exclude * __pycache__ -recursive-exclude * *.py[co] diff --git a/dev-requirements.txt b/dev-requirements.txt deleted file mode 100644 index 330cb2701..000000000 --- a/dev-requirements.txt +++ /dev/null @@ -1,35 +0,0 @@ -elastic-transport>=8.13, <9 -requests>=2, <3 -aiohttp -pytest -pytest-cov -pytest-asyncio -coverage -jinja2 -python-dateutil -unasync -pyyaml>=5.4 -isort -black -twine -build -nox - -pandas -orjson - -# mmr for vectorstore -numpy -simsimd - -# Testing the 'search_mvt' API response -mapbox-vector-tile -# Python 3.7 gets an old version of mapbox-vector-tile, requiring an -# old version of protobuf -protobuf<4; python_version<="3.7" - -# Docs -# Override Read the Docs default (sphinx<2 and sphinx-rtd-theme<0.5) -sphinx>2 -sphinx-rtd-theme>0.5 -sphinx-autodoc-typehints diff --git a/noxfile.py b/noxfile.py index 12ad4f02e..8c71af9fc 100644 --- a/noxfile.py +++ b/noxfile.py @@ -22,7 +22,6 @@ SOURCE_DIR = os.path.dirname(os.path.abspath(__file__)) SOURCE_FILES = ( "docs/sphinx/conf.py", - "setup.py", "noxfile.py", "elasticsearch/", "test_elasticsearch/", @@ -48,22 +47,17 @@ def pytest_argv(): @nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]) def test(session): - session.install( - ".[async,requests,orjson,vectorstore_mmr]", env=INSTALL_ENV, silent=False - ) - session.install("-r", "dev-requirements.txt", silent=False) + session.install(".[dev]", env=INSTALL_ENV, silent=False) session.run(*pytest_argv()) @nox.session(python=["3.7", "3.12"]) def test_otel(session): - session.install(".[async,requests]", env=INSTALL_ENV, silent=False) session.install( + ".[dev]", "opentelemetry-api", "opentelemetry-sdk", - "-r", - "dev-requirements.txt", silent=False, ) @@ -129,8 +123,5 @@ def lint(session): @nox.session() def docs(session): - session.install("-rdev-requirements.txt") - session.install(".") - session.run("python", "-m", "pip", "install", "sphinx-autodoc-typehints") - + session.install(".[docs]") session.run("sphinx-build", "docs/sphinx/", "docs/sphinx/_build", "-b", "html") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..20f206d27 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,123 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "elasticsearch" +description = "Python client for Elasticsearch" +readme = "README.md" +license = "Apache-2.0" +requires-python = ">=3.7" +authors = [ + { name = "Elastic Client Library Maintainers", email = "client-libs@elastic.co" }, +] +maintainers = [ + { name = "Elastic Client Library Maintainers", email = "client-libs@elastic.co" }, +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "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 :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", +] +keywords = [ + "elasticsearch", + "elastic", + "kibana", + "mapping", + "REST", + "search", + "client", + "index", +] +dynamic = ["version"] +dependencies = [ + "elastic-transport>=8.13,<9", +] + +[project.optional-dependencies] +async = ["aiohttp>=3,<4"] +requests = ["requests>=2.4.0, !=2.32.2, <3.0.0"] +orjson = ["orjson>=3"] +# Maximal Marginal Relevance (MMR) for search results +vectorstore_mmr = ["numpy>=1", "simsimd>=3"] +dev = [ + "requests>=2, <3", + "aiohttp", + "pytest", + "pytest-cov", + "pytest-asyncio", + "coverage", + "jinja2", + "python-dateutil", + "unasync", + "pyyaml>=5.4", + "isort", + "black", + "twine", + "build", + "nox", + "orjson", + "numpy", + "simsimd", + "pandas", + "mapbox-vector-tile", + # Python 3.7 gets an old version of mapbox-vector-tile, requiring an old version of protobuf + "protobuf<4; python_version<=\"3.7\"", +] +docs = [ + "sphinx", + "sphinx-rtd-theme", + "sphinx-autodoc-typehints" +] + +[project.urls] +Documentation = "https://elasticsearch-py.readthedocs.io/" +Homepage = "https://github.com/elastic/elasticsearch-py" +"Issue Tracker" = "https://github.com/elastic/elasticsearch-py/issues" +"Source Code" = "https://github.com/elastic/elasticsearch-py" + +[tool.hatch.version] +path = "elasticsearch/_version.py" +pattern = "__versionstr__ = \"(?P[^']+)\"" + +[tool.hatch.build.targets.sdist] +include = [ + "/elasticsearch", + "/CHANGELOG.md", + "/CONTRIBUTING.md", + "/LICENSE", + "/NOTICE", + "/README.md", + "/setup.cfg", + "/docs/sphinx", +] + +[tool.hatch.build.targets.wheel] +packages = ["elasticsearch"] + +[tool.pytest.ini_options] +junit_family = "legacy" +xfail_strict = true +markers = "otel" + +[tool.isort] +profile = "black" + +[tool.coverage.report] +exclude_lines = [ + "raise NotImplementedError*", +] + +[tool.mypy] +ignore_missing_imports = true diff --git a/setup.cfg b/setup.cfg index d8e0ce63d..403f26a50 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,17 +1,2 @@ [flake8] ignore = E203, E266, E501, W503 - -[tool:pytest] -junit_family=legacy -addopts = -vvv --cov-report=term-missing --cov=elasticsearch --cov-config=.coveragerc -markers = otel - -[tool:isort] -profile=black - -[report] -exclude_lines= - raise NotImplementedError* - -[mypy] -ignore_missing_imports = True diff --git a/setup.py b/setup.py deleted file mode 100644 index 5f246bce2..000000000 --- a/setup.py +++ /dev/null @@ -1,86 +0,0 @@ -# -*- coding: utf-8 -*- -# Licensed to Elasticsearch B.V. under one or more contributor -# license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright -# ownership. Elasticsearch B.V. licenses this file to you 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 re -from os.path import abspath, dirname, join - -from setuptools import find_packages, setup - -package_name = "elasticsearch" -base_dir = abspath(dirname(__file__)) - -with open(join(base_dir, package_name, "_version.py")) as f: - package_version = re.search( - r"__versionstr__\s+=\s+[\"\']([^\"\']+)[\"\']", f.read() - ).group(1) - -with open(join(base_dir, "README.md")) as f: - readme = f.read() - - -packages = [ - package - for package in find_packages(where=".", exclude=("test_elasticsearch*",)) - if package == package_name or package.startswith(package_name + ".") -] - -setup( - name=package_name, - description="Python client for Elasticsearch", - license="Apache-2.0", - url="https://github.com/elastic/elasticsearch-py", - long_description=readme, - long_description_content_type="text/markdown", - version=package_version, - author="Elastic Client Library Maintainers", - author_email="client-libs@elastic.co", - project_urls={ - "Documentation": "https://elasticsearch-py.readthedocs.io", - "Source Code": "https://github.com/elastic/elasticsearch-py", - "Issue Tracker": "https://github.com/elastic/elasticsearch-py/issues", - }, - packages=packages, - package_data={"elasticsearch": ["py.typed", "*.pyi"]}, - include_package_data=True, - zip_safe=False, - classifiers=[ - "Development Status :: 5 - Production/Stable", - "License :: OSI Approved :: Apache Software License", - "Intended Audience :: Developers", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "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 :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", - ], - python_requires=">=3.7", - install_requires=["elastic-transport>=8.13,<9"], - extras_require={ - "requests": ["requests>=2.4.0, !=2.32.2, <3.0.0"], - "async": ["aiohttp>=3,<4"], - "orjson": ["orjson>=3"], - # Maximal Marginal Relevance (MMR) for search results - "vectorstore_mmr": ["numpy>=1", "simsimd>=3"], - }, -) diff --git a/utils/build-dists.py b/utils/build-dists.py index a73210803..103e95f0e 100644 --- a/utils/build-dists.py +++ b/utils/build-dists.py @@ -17,7 +17,7 @@ """A command line tool for building and verifying releases Can be used for building both 'elasticsearch' and 'elasticsearchX' dists. -Only requires 'name' in 'setup.py' and the directory to be changed. +Only requires 'name' in 'pyproject.toml' and the directory to be changed. """ import contextlib @@ -170,8 +170,8 @@ def test_dist(dist): def main(): - run("git", "checkout", "--", "setup.py", "elasticsearch/") - run("rm", "-rf", "build/", "dist/*", "*.egg-info", ".eggs") + run("git", "checkout", "--", "pyproject.toml", "elasticsearch/") + run("rm", "-rf", "dist") # Grab the major version to be used as a suffix. version_path = os.path.join(base_dir, "elasticsearch/_version.py") @@ -249,25 +249,19 @@ def main(): f.truncate() f.write(version_data) - # Rewrite setup.py with the new name. - setup_py_path = os.path.join(base_dir, "setup.py") - with open(setup_py_path) as f: - setup_py = f.read() - with open(setup_py_path, "w") as f: + # Rewrite pyproject.toml with the new name. + pyproject_toml_path = os.path.join(base_dir, "pyproject.toml") + with open(pyproject_toml_path) as f: + pyproject_toml = f.read() + with open(pyproject_toml_path, "w") as f: f.truncate() - assert 'package_name = "elasticsearch"' in setup_py - f.write( - setup_py.replace( - 'package_name = "elasticsearch"', - f'package_name = "elasticsearch{suffix}"', - ) - ) + f.write(pyproject_toml.replace("elasticsearch", f"elasticsearch{suffix}")) # Build the sdist/wheels run("python", "-m", "build") # Clean up everything. - run("git", "checkout", "--", "setup.py", "elasticsearch/") + run("git", "checkout", "--", "pyproject.toml", "elasticsearch/") if suffix: run("rm", "-rf", f"elasticsearch{suffix}/")