Rename Elasticsearch -> OpenSearch

Signed-off-by: Rushi Agrawal <[email protected]>
This commit is contained in:
Rushi Agrawal
2021-08-19 07:58:20 +05:30
parent 43f5ac58b5
commit 9e9269c8f3
139 changed files with 486 additions and 495 deletions
+26 -28
View File
@@ -25,7 +25,7 @@
# under the License.
"""A command line tool for building and verifying releases
Can be used for building both 'elasticsearch' and 'elasticsearchX' dists.
Can be used for building both 'opensearch' and 'elasticsearchX' dists.
Only requires 'name' in 'setup.py' and the directory to be changed.
"""
@@ -70,7 +70,7 @@ def run(*argv, expect_exit_code=0):
def test_dist(dist):
with set_tmp_dir() as tmp_dir:
dist_name = re.match(r"^(elasticsearch\d*)-", os.path.basename(dist)).group(1)
dist_name = re.match(r"^(opensearch\d*)-", os.path.basename(dist)).group(1)
# Build the venv and install the dist
run("python", "-m", "venv", os.path.join(tmp_dir, "venv"))
@@ -79,13 +79,13 @@ def test_dist(dist):
run(venv_python, "-m", "pip", "install", dist)
# Test the sync namespaces
run(venv_python, "-c", f"from {dist_name} import Elasticsearch")
run(venv_python, "-c", f"from {dist_name} import OpenSearch")
run(
venv_python,
"-c",
f"from {dist_name}.helpers import scan, bulk, streaming_bulk, reindex",
)
run(venv_python, "-c", f"from {dist_name} import Elasticsearch")
run(venv_python, "-c", f"from {dist_name} import OpenSearch")
run(
venv_python,
"-c",
@@ -96,7 +96,7 @@ def test_dist(dist):
run(
venv_python,
"-c",
f"from {dist_name} import AsyncElasticsearch",
f"from {dist_name} import AsyncOpenSearch",
expect_exit_code=256,
)
run(
@@ -108,7 +108,7 @@ def test_dist(dist):
# Install aiohttp and see that async is now available
run(venv_python, "-m", "pip", "install", "aiohttp")
run(venv_python, "-c", f"from {dist_name} import AsyncElasticsearch")
run(venv_python, "-c", f"from {dist_name} import AsyncOpenSearch")
run(
venv_python,
"-c",
@@ -117,18 +117,18 @@ def test_dist(dist):
# Only need to test 'async_types' for non-aliased package
# since 'aliased_types' tests both async and sync.
if dist_name == "elasticsearch":
if dist_name == "opensearch":
run(
venv_python,
"-m",
"mypy",
"--strict",
os.path.join(base_dir, "test_elasticsearch/test_types/async_types.py"),
os.path.join(base_dir, "test_opensearch/test_types/async_types.py"),
)
# Ensure that the namespaces are correct for the dist
for suffix in ("", "1", "2", "5", "6", "7", "8", "9", "10"):
distx_name = f"elasticsearch{suffix}"
distx_name = f"opensearch{suffix}"
run(
venv_python,
"-c",
@@ -136,15 +136,15 @@ def test_dist(dist):
expect_exit_code=256 if distx_name != dist_name else 0,
)
# Check that sync types work for 'elasticsearch' and
# that aliased types work for 'elasticsearchX'
if dist_name == "elasticsearch":
# Check that sync types work for 'opensearch' and
# that aliased types work for 'opensearchX'
if dist_name == "opensearch":
run(
venv_python,
"-m",
"mypy",
"--strict",
os.path.join(base_dir, "test_elasticsearch/test_types/sync_types.py"),
os.path.join(base_dir, "test_opensearch/test_types/sync_types.py"),
)
else:
run(
@@ -152,9 +152,7 @@ def test_dist(dist):
"-m",
"mypy",
"--strict",
os.path.join(
base_dir, "test_elasticsearch/test_types/aliased_types.py"
),
os.path.join(base_dir, "test_opensearch/test_types/aliased_types.py"),
)
# Uninstall the dist, see that we can't import things anymore
@@ -162,17 +160,17 @@ def test_dist(dist):
run(
venv_python,
"-c",
f"from {dist_name} import Elasticsearch",
f"from {dist_name} import OpenSearch",
expect_exit_code=256,
)
def main():
run("git", "checkout", "--", "setup.py", "elasticsearch/")
run("git", "checkout", "--", "setup.py", "opensearch/")
run("rm", "-rf", "build/", "dist/*", "*.egg-info", ".eggs")
# Grab the major version to be used as a suffix.
version_path = os.path.join(base_dir, "elasticsearch/_version.py")
version_path = os.path.join(base_dir, "opensearch/_version.py")
with open(version_path) as f:
version = re.search(
r"^__versionstr__\s+=\s+[\"\']([^\"\']+)[\"\']", f.read(), re.M
@@ -230,12 +228,12 @@ def main():
# Rename the module to fit the suffix.
shutil.move(
os.path.join(base_dir, "elasticsearch"),
os.path.join(base_dir, "elasticsearch%s" % suffix),
os.path.join(base_dir, "opensearch"),
os.path.join(base_dir, "opensearch%s" % suffix),
)
# Ensure that the version within 'elasticsearch/_version.py' is correct.
version_path = os.path.join(base_dir, f"elasticsearch{suffix}/_version.py")
# Ensure that the version within 'opensearch/_version.py' is correct.
version_path = os.path.join(base_dir, f"opensearch{suffix}/_version.py")
with open(version_path) as f:
version_data = f.read()
version_data = re.sub(
@@ -253,11 +251,11 @@ def main():
setup_py = f.read()
with open(setup_py_path, "w") as f:
f.truncate()
assert 'package_name = "elasticsearch"' in setup_py
assert 'package_name = "opensearch"' in setup_py
f.write(
setup_py.replace(
'package_name = "elasticsearch"',
'package_name = "elasticsearch%s"' % suffix,
'package_name = "opensearch"',
'package_name = "opensearch%s"' % suffix,
)
)
@@ -265,9 +263,9 @@ def main():
run("python", "setup.py", "sdist", "bdist_wheel")
# Clean up everything.
run("git", "checkout", "--", "setup.py", "elasticsearch/")
run("git", "checkout", "--", "setup.py", "opensearch/")
if suffix:
run("rm", "-rf", "elasticsearch%s/" % suffix)
run("rm", "-rf", "opensearch%s/" % suffix)
# Test everything that got created
dists = os.listdir(os.path.join(base_dir, "dist"))
+11 -11
View File
@@ -144,7 +144,7 @@ class Module:
def filepath(self):
return (
CODE_ROOT
/ f"elasticsearch/_async/client/{self.namespace}.py{'i' if self.is_pyi else ''}"
/ f"opensearch/_async/client/{self.namespace}.py{'i' if self.is_pyi else ''}"
)
@@ -184,8 +184,8 @@ class API:
# Try setting doc refs like 'current' and 'master' to our branches ref.
if BRANCH_NAME is not None:
revised_url = re.sub(
"/elasticsearch/reference/[^/]+/",
f"/elasticsearch/reference/{BRANCH_NAME}/",
"/opensearch/reference/[^/]+/",
f"/opensearch/reference/{BRANCH_NAME}/",
self.doc_url,
)
if is_valid_url(revised_url):
@@ -338,9 +338,9 @@ def download_artifact(version):
resp = http.request(
"GET", f"https://artifacts-api.elastic.co/v1/versions/{version}"
)
packages = json.loads(resp.data)["version"]["builds"][0]["projects"][
"elasticsearch"
]["packages"]
packages = json.loads(resp.data)["version"]["builds"][0]["projects"]["opensearch"][
"packages"
]
for package in packages:
if re.match(r"^rest-resources-zip-.*\.zip$", package):
zip_url = packages[package]["url"]
@@ -404,20 +404,20 @@ def dump_modules(modules):
additional_replacements = {
# We want to rewrite to 'Transport' instead of 'SyncTransport', etc
"AsyncTransport": "Transport",
"AsyncElasticsearch": "Elasticsearch",
"AsyncOpenSearch": "OpenSearch",
# We don't want to rewrite this class
"AsyncSearchClient": "AsyncSearchClient",
}
rules = [
unasync.Rule(
fromdir="/elasticsearch/_async/client/",
todir="/elasticsearch/client/",
fromdir="/opensearch/_async/client/",
todir="/opensearch/client/",
additional_replacements=additional_replacements,
),
]
filepaths = []
for root, _, filenames in os.walk(CODE_ROOT / "elasticsearch/_async"):
for root, _, filenames in os.walk(CODE_ROOT / "opensearch/_async"):
for filename in filenames:
if (
filename.rpartition(".")[-1]
@@ -430,7 +430,7 @@ def dump_modules(modules):
filepaths.append(os.path.join(root, filename))
unasync.unasync_files(filepaths, rules)
blacken(CODE_ROOT / "elasticsearch")
blacken(CODE_ROOT / "opensearch")
if __name__ == "__main__":