Skip to content

Commit 675c22a

Browse files
Updated build-dists.py to work with pyproject.toml
1 parent 41f4ef7 commit 675c22a

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

utils/build-dists.py

Lines changed: 20 additions & 25 deletions
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
@@ -65,7 +65,7 @@ def run(*argv, expect_exit_code=0):
6565

6666
def test_dist(dist):
6767
with set_tmp_dir() as tmp_dir:
68-
dist_name = re.match(r"^(elasticsearch\d*)-", os.path.basename(dist)).group(1)
68+
dist_name = re.match(r"^(elasticsearch_serverless\d*)-", os.path.basename(dist)).group(1)
6969

7070
# Build the venv and install the dist
7171
run("python", "-m", "venv", os.path.join(tmp_dir, "venv"))
@@ -80,6 +80,7 @@ def test_dist(dist):
8080
"mypy",
8181
"numpy",
8282
"pandas-stubs",
83+
"opentelemetry-api",
8384
)
8485
run(venv_python, "-m", "pip", "install", dist)
8586

@@ -127,7 +128,7 @@ def test_dist(dist):
127128

128129
# Ensure that the namespaces are correct for the dist
129130
for suffix in ("", "1", "2", "5", "6", "7", "8", "9", "10"):
130-
distx_name = f"elasticsearch{suffix}"
131+
distx_name = f"elasticsearch_serverless{suffix}"
131132
run(
132133
venv_python,
133134
"-c",
@@ -136,7 +137,7 @@ def test_dist(dist):
136137
)
137138

138139
# Check that sync types work for 'elasticsearch_serverless' and
139-
# that aliased types work for 'elasticsearchX'
140+
# that aliased types work for 'elasticsearch_serverlessX'
140141
if dist_name == "elasticsearch_serverless":
141142
run(
142143
venv_python,
@@ -174,16 +175,16 @@ def test_dist(dist):
174175

175176

176177
def main():
177-
run("git", "checkout", "--", "setup.py", "elasticsearch_serverless/")
178-
run("rm", "-rf", "build/", "dist/*", "*.egg-info", ".eggs")
178+
run("git", "checkout", "--", "pyproject.toml", "elasticsearch_serverless/")
179+
run("rm", "-rf", "dist")
179180

180181
# Grab the major version to be used as a suffix.
181182
version_path = os.path.join(base_dir, "elasticsearch_serverless/_version.py")
182183
with open(version_path) as f:
183184
version = re.search(
184185
r"^__versionstr__\s+=\s+[\"\']([^\"\']+)[\"\']", f.read(), re.M
185186
).group(1)
186-
major_version = version.split(".")[0]
187+
# major_version = version.split(".")[0]
187188

188189
# If we're handed a version from the build manager we
189190
# should check that the version is correct or write
@@ -231,17 +232,17 @@ def main():
231232
)
232233
exit(1)
233234

234-
for suffix in ("", major_version):
235+
for suffix in ("",):
235236
run("rm", "-rf", "build/", "*.egg-info", ".eggs")
236237

237238
# Rename the module to fit the suffix.
238239
shutil.move(
239240
os.path.join(base_dir, "elasticsearch_serverless"),
240-
os.path.join(base_dir, f"elasticsearch{suffix}"),
241+
os.path.join(base_dir, f"elasticsearch_serverless{suffix}"),
241242
)
242243

243244
# Ensure that the version within 'elasticsearch_serverless/_version.py' is correct.
244-
version_path = os.path.join(base_dir, f"elasticsearch{suffix}/_version.py")
245+
version_path = os.path.join(base_dir, f"elasticsearch_serverless{suffix}/_version.py")
245246
with open(version_path) as f:
246247
version_data = f.read()
247248
version_data = re.sub(
@@ -253,31 +254,25 @@ def main():
253254
f.truncate()
254255
f.write(version_data)
255256

256-
# Rewrite setup.py with the new name.
257-
setup_py_path = os.path.join(base_dir, "setup.py")
258-
with open(setup_py_path) as f:
259-
setup_py = f.read()
260-
with open(setup_py_path, "w") as f:
257+
# Rewrite pyproject.toml with the new name.
258+
pyproject_toml_path = os.path.join(base_dir, "pyproject.toml")
259+
with open(pyproject_toml_path) as f:
260+
pyproject_toml = f.read()
261+
with open(pyproject_toml_path, "w") as f:
261262
f.truncate()
262-
assert 'package_name = "elasticsearch_serverless"' in setup_py
263-
f.write(
264-
setup_py.replace(
265-
'package_name = "elasticsearch_serverless"',
266-
f'package_name = "elasticsearch{suffix}"',
267-
)
268-
)
263+
f.write(pyproject_toml.replace("elasticsearch_serverless", f"elasticsearch_serverless{suffix}"))
269264

270265
# Build the sdist/wheels
271266
run("python", "-m", "build")
272267

273268
# Clean up everything.
274-
run("git", "checkout", "--", "setup.py", "elasticsearch_serverless/")
269+
run("git", "checkout", "--", "pyproject.toml", "elasticsearch_serverless/")
275270
if suffix:
276-
run("rm", "-rf", f"elasticsearch{suffix}/")
271+
run("rm", "-rf", f"elasticsearch_serverless{suffix}/")
277272

278273
# Test everything that got created
279274
dists = os.listdir(os.path.join(base_dir, "dist"))
280-
assert len(dists) == 4
275+
assert len(dists) == 2
281276
for dist in dists:
282277
test_dist(os.path.join(base_dir, "dist", dist))
283278
os.system('bash -c "chmod a+w dist/*"')

0 commit comments

Comments
 (0)