From 6250aacafe9598644dc9cf89db02f5d36b1d1c55 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 21 Sep 2020 16:44:39 -0500 Subject: [PATCH] [7.x] Update build_dists.py to build namespaced packages Co-authored-by: Seth Michael Larson --- utils/build_dists.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/utils/build_dists.py b/utils/build_dists.py index a9602561..ff794055 100644 --- a/utils/build_dists.py +++ b/utils/build_dists.py @@ -128,8 +128,41 @@ def test_dist(dist): def main(): run("rm", "-rf", "build/", "dist/", "*.egg-info", ".eggs") - run("python", "setup.py", "sdist", "bdist_wheel") + # Grab the major version to be used as a suffix. + setup_py_path = os.path.join(base_dir, "setup.py") + with open(setup_py_path) as f: + major_version = re.search(r"^VERSION = \((\d+),", f.read(), re.M).group(1) + + for suffix in ("", major_version): + run("rm", "-rf", "build/", "*.egg-info", ".eggs") + + # Rename the module to fit the suffix. + shutil.move( + os.path.join(base_dir, "elasticsearch"), + os.path.join(base_dir, "elasticsearch%s" % suffix), + ) + + # Rewrite setup.py with the new name. + with open(setup_py_path) as f: + setup_py = f.read() + with open(setup_py_path, "w") as f: + f.truncate() + f.write( + setup_py.replace( + 'name="elasticsearch",', 'name="elasticsearch%s",' % suffix + ) + ) + + # Build the sdist/wheels + run("python", "setup.py", "sdist", "bdist_wheel") + + # Clean up everything. + run("git", "checkout", "--", "setup.py", "elasticsearch/") + if suffix: + run("rm", "-rf", "elasticsearch%s/" % suffix) + + # Test everything that got created for dist in os.listdir(os.path.join(base_dir, "dist")): test_dist(os.path.join(base_dir, "dist", dist))