Skip to content

Commit b44e963

Browse files
authored
Migrate to pyproject.toml and hatchling (elastic#2600)
1 parent 48b3482 commit b44e963

8 files changed

+138
-179
lines changed

.readthedocs.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ build:
1111

1212
python:
1313
install:
14-
- requirements: dev-requirements.txt
1514
- path: .
15+
extra_requirements:
16+
- "docs"

MANIFEST.in

-14
This file was deleted.

dev-requirements.txt

-35
This file was deleted.

noxfile.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
SOURCE_DIR = os.path.dirname(os.path.abspath(__file__))
2323
SOURCE_FILES = (
2424
"docs/sphinx/conf.py",
25-
"setup.py",
2625
"noxfile.py",
2726
"elasticsearch/",
2827
"test_elasticsearch/",
@@ -48,22 +47,17 @@ def pytest_argv():
4847

4948
@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"])
5049
def test(session):
51-
session.install(
52-
".[async,requests,orjson,vectorstore_mmr]", env=INSTALL_ENV, silent=False
53-
)
54-
session.install("-r", "dev-requirements.txt", silent=False)
50+
session.install(".[dev]", env=INSTALL_ENV, silent=False)
5551

5652
session.run(*pytest_argv())
5753

5854

5955
@nox.session(python=["3.7", "3.12"])
6056
def test_otel(session):
61-
session.install(".[async,requests]", env=INSTALL_ENV, silent=False)
6257
session.install(
58+
".[dev]",
6359
"opentelemetry-api",
6460
"opentelemetry-sdk",
65-
"-r",
66-
"dev-requirements.txt",
6761
silent=False,
6862
)
6963

@@ -129,8 +123,5 @@ def lint(session):
129123

130124
@nox.session()
131125
def docs(session):
132-
session.install("-rdev-requirements.txt")
133-
session.install(".")
134-
session.run("python", "-m", "pip", "install", "sphinx-autodoc-typehints")
135-
126+
session.install(".[docs]")
136127
session.run("sphinx-build", "docs/sphinx/", "docs/sphinx/_build", "-b", "html")

pyproject.toml

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "elasticsearch"
7+
description = "Python client for Elasticsearch"
8+
readme = "README.md"
9+
license = "Apache-2.0"
10+
requires-python = ">=3.7"
11+
authors = [
12+
{ name = "Elastic Client Library Maintainers", email = "[email protected]" },
13+
]
14+
maintainers = [
15+
{ name = "Elastic Client Library Maintainers", email = "[email protected]" },
16+
]
17+
classifiers = [
18+
"Development Status :: 5 - Production/Stable",
19+
"Intended Audience :: Developers",
20+
"License :: OSI Approved :: Apache Software License",
21+
"Operating System :: OS Independent",
22+
"Programming Language :: Python",
23+
"Programming Language :: Python :: 3",
24+
"Programming Language :: Python :: 3.7",
25+
"Programming Language :: Python :: 3.8",
26+
"Programming Language :: Python :: 3.9",
27+
"Programming Language :: Python :: 3.10",
28+
"Programming Language :: Python :: 3.11",
29+
"Programming Language :: Python :: 3.12",
30+
"Programming Language :: Python :: Implementation :: CPython",
31+
"Programming Language :: Python :: Implementation :: PyPy",
32+
]
33+
keywords = [
34+
"elasticsearch",
35+
"elastic",
36+
"kibana",
37+
"mapping",
38+
"REST",
39+
"search",
40+
"client",
41+
"index",
42+
]
43+
dynamic = ["version"]
44+
dependencies = [
45+
"elastic-transport>=8.13,<9",
46+
]
47+
48+
[project.optional-dependencies]
49+
async = ["aiohttp>=3,<4"]
50+
requests = ["requests>=2.4.0, !=2.32.2, <3.0.0"]
51+
orjson = ["orjson>=3"]
52+
# Maximal Marginal Relevance (MMR) for search results
53+
vectorstore_mmr = ["numpy>=1", "simsimd>=3"]
54+
dev = [
55+
"requests>=2, <3",
56+
"aiohttp",
57+
"pytest",
58+
"pytest-cov",
59+
"pytest-asyncio",
60+
"coverage",
61+
"jinja2",
62+
"python-dateutil",
63+
"unasync",
64+
"pyyaml>=5.4",
65+
"isort",
66+
"black",
67+
"twine",
68+
"build",
69+
"nox",
70+
"orjson",
71+
"numpy",
72+
"simsimd",
73+
"pandas",
74+
"mapbox-vector-tile",
75+
# Python 3.7 gets an old version of mapbox-vector-tile, requiring an old version of protobuf
76+
"protobuf<4; python_version<=\"3.7\"",
77+
]
78+
docs = [
79+
"sphinx",
80+
"sphinx-rtd-theme",
81+
"sphinx-autodoc-typehints"
82+
]
83+
84+
[project.urls]
85+
Documentation = "https://elasticsearch-py.readthedocs.io/"
86+
Homepage = "https://github.com/elastic/elasticsearch-py"
87+
"Issue Tracker" = "https://github.com/elastic/elasticsearch-py/issues"
88+
"Source Code" = "https://github.com/elastic/elasticsearch-py"
89+
90+
[tool.hatch.version]
91+
path = "elasticsearch/_version.py"
92+
pattern = "__versionstr__ = \"(?P<version>[^']+)\""
93+
94+
[tool.hatch.build.targets.sdist]
95+
include = [
96+
"/elasticsearch",
97+
"/CHANGELOG.md",
98+
"/CONTRIBUTING.md",
99+
"/LICENSE",
100+
"/NOTICE",
101+
"/README.md",
102+
"/setup.cfg",
103+
"/docs/sphinx",
104+
]
105+
106+
[tool.hatch.build.targets.wheel]
107+
packages = ["elasticsearch"]
108+
109+
[tool.pytest.ini_options]
110+
junit_family = "legacy"
111+
xfail_strict = true
112+
markers = "otel"
113+
114+
[tool.isort]
115+
profile = "black"
116+
117+
[tool.coverage.report]
118+
exclude_lines = [
119+
"raise NotImplementedError*",
120+
]
121+
122+
[tool.mypy]
123+
ignore_missing_imports = true

setup.cfg

-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,2 @@
11
[flake8]
22
ignore = E203, E266, E501, W503
3-
4-
[tool:pytest]
5-
junit_family=legacy
6-
addopts = -vvv --cov-report=term-missing --cov=elasticsearch --cov-config=.coveragerc
7-
markers = otel
8-
9-
[tool:isort]
10-
profile=black
11-
12-
[report]
13-
exclude_lines=
14-
raise NotImplementedError*
15-
16-
[mypy]
17-
ignore_missing_imports = True

setup.py

-86
This file was deleted.

utils/build-dists.py

+10-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
"""A command line tool for building and verifying releases
1919
Can be used for building both 'elasticsearch' and 'elasticsearchX' dists.
20-
Only requires 'name' in 'setup.py' and the directory to be changed.
20+
Only requires 'name' in 'pyproject.toml' and the directory to be changed.
2121
"""
2222

2323
import contextlib
@@ -170,8 +170,8 @@ def test_dist(dist):
170170

171171

172172
def main():
173-
run("git", "checkout", "--", "setup.py", "elasticsearch/")
174-
run("rm", "-rf", "build/", "dist/*", "*.egg-info", ".eggs")
173+
run("git", "checkout", "--", "pyproject.toml", "elasticsearch/")
174+
run("rm", "-rf", "dist")
175175

176176
# Grab the major version to be used as a suffix.
177177
version_path = os.path.join(base_dir, "elasticsearch/_version.py")
@@ -249,25 +249,19 @@ def main():
249249
f.truncate()
250250
f.write(version_data)
251251

252-
# Rewrite setup.py with the new name.
253-
setup_py_path = os.path.join(base_dir, "setup.py")
254-
with open(setup_py_path) as f:
255-
setup_py = f.read()
256-
with open(setup_py_path, "w") as f:
252+
# Rewrite pyproject.toml with the new name.
253+
pyproject_toml_path = os.path.join(base_dir, "pyproject.toml")
254+
with open(pyproject_toml_path) as f:
255+
pyproject_toml = f.read()
256+
with open(pyproject_toml_path, "w") as f:
257257
f.truncate()
258-
assert 'package_name = "elasticsearch"' in setup_py
259-
f.write(
260-
setup_py.replace(
261-
'package_name = "elasticsearch"',
262-
f'package_name = "elasticsearch{suffix}"',
263-
)
264-
)
258+
f.write(pyproject_toml.replace("elasticsearch", f"elasticsearch{suffix}"))
265259

266260
# Build the sdist/wheels
267261
run("python", "-m", "build")
268262

269263
# Clean up everything.
270-
run("git", "checkout", "--", "setup.py", "elasticsearch/")
264+
run("git", "checkout", "--", "pyproject.toml", "elasticsearch/")
271265
if suffix:
272266
run("rm", "-rf", f"elasticsearch{suffix}/")
273267

0 commit comments

Comments
 (0)