Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
Signed-off-by: Sai Medhini Reddy Maryada <[email protected]>
  • Loading branch information
Sai Medhini Reddy Maryada authored and Sai Medhini Reddy Maryada committed Mar 2, 2024
1 parent 4b69c09 commit 8472948
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 52 deletions.
40 changes: 38 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
# under the License.


import filecmp
import os
import shutil
from typing import Any

import nox
Expand Down Expand Up @@ -74,7 +77,7 @@ def format(session: Any) -> None:
session.run("black", *SOURCE_FILES)
session.run("python", "utils/license_headers.py", "fix", *SOURCE_FILES)

session.notify("lint")
# session.notify("lint")


@nox.session(python=["3.7"]) # type: ignore
Expand Down Expand Up @@ -145,5 +148,38 @@ def generate(session: Any) -> None:
:param session: current nox session
"""
session.install("-rdev-requirements.txt")
# Define paths
current_dir = os.path.dirname(os.path.abspath(__file__))
before_path = os.path.join(current_dir, "before_generate_opensearchpy")
# Create snapshots of the opensearchpy directory before and after running the generate session
shutil.copytree(os.path.join(current_dir, "opensearchpy"), before_path)
session.run("python", "utils/generate_api.py")
session.notify("format")
session.run("nox", "-s", "format")

after_path = os.path.join(current_dir, "opensearchpy")
# # Compare the two snapshots
# diff_files = filecmp.dircmp(
# before_path, os.path.join(current_dir, "opensearchpy")
# ).diff_files
# print("diff_files", diff_files)

all_files_dir1 = set(os.listdir(before_path))
all_files_dir2 = set(os.listdir(after_path))

# Find the union of file names
all_files_union = all_files_dir1.union(all_files_dir2)
print("all_files_union", all_files_union)

match, mismatch, errors = filecmp.cmpfiles(
before_path, after_path, all_files_union, shallow=False
)
print("match, mismatch, errors", match, mismatch, errors)
if len(mismatch) > 0 or len(errors) > 0:
print("Changes detected in the opensearchpy directory:")
session.run("python", "utils/changelog_updater.py")

else:
print("No changes detected in the opensearchpy directory")

# Clean up
shutil.rmtree(before_path)
8 changes: 5 additions & 3 deletions opensearchpy/_async/client/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ async def stats(
"""
return await self.transport.perform_request(
"GET",
"/_cluster/stats"
if node_id in SKIP_IN_PATH
else _make_path("_cluster", "stats", "nodes", node_id),
(
"/_cluster/stats"
if node_id in SKIP_IN_PATH
else _make_path("_cluster", "stats", "nodes", node_id)
),
params=params,
headers=headers,
)
Expand Down
8 changes: 5 additions & 3 deletions opensearchpy/_async/plugins/alerting.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ async def get_destination(
"""
return await self.transport.perform_request(
"GET",
_make_path("_plugins", "_alerting", "destinations", destination_id)
if destination_id
else _make_path("_plugins", "_alerting", "destinations"),
(
_make_path("_plugins", "_alerting", "destinations", destination_id)
if destination_id
else _make_path("_plugins", "_alerting", "destinations")
),
params=params,
headers=headers,
)
Expand Down
8 changes: 5 additions & 3 deletions opensearchpy/client/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ def stats(
"""
return self.transport.perform_request(
"GET",
"/_cluster/stats"
if node_id in SKIP_IN_PATH
else _make_path("_cluster", "stats", "nodes", node_id),
(
"/_cluster/stats"
if node_id in SKIP_IN_PATH
else _make_path("_cluster", "stats", "nodes", node_id)
),
params=params,
headers=headers,
)
Expand Down
10 changes: 7 additions & 3 deletions opensearchpy/helpers/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,13 @@ def get_definition(self) -> Any:
if "filters" in d:
d["filters"] = [
# comma delimited string given by user
fs if isinstance(fs, six.string_types) else
# list of strings or TokenFilter objects
", ".join(f.to_dict() if hasattr(f, "to_dict") else f for f in fs)
(
fs
if isinstance(fs, six.string_types)
else
# list of strings or TokenFilter objects
", ".join(f.to_dict() if hasattr(f, "to_dict") else f for f in fs)
)
for fs in self.filters
]
return d
Expand Down
8 changes: 5 additions & 3 deletions opensearchpy/plugins/alerting.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ def get_destination(
"""
return self.transport.perform_request(
"GET",
_make_path("_plugins", "_alerting", "destinations", destination_id)
if destination_id
else _make_path("_plugins", "_alerting", "destinations"),
(
_make_path("_plugins", "_alerting", "destinations", destination_id)
if destination_id
else _make_path("_plugins", "_alerting", "destinations")
),
params=params,
headers=headers,
)
Expand Down
14 changes: 7 additions & 7 deletions test_opensearchpy/test_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@
from opensearchpy.helpers import test
from opensearchpy.helpers.test import OpenSearchTestCase as BaseTestCase

client: Any = None
CLIENT: Any = None


def get_client(**kwargs: Any) -> Any:
global client
if client is False:
global CLIENT
if CLIENT is False:
raise SkipTest("No client is available")
if client is not None and not kwargs:
return client
if CLIENT is not None and not kwargs:
return CLIENT

try:
new_client = test.get_test_client(**kwargs)
except SkipTest:
client = False
CLIENT = False
raise

if not kwargs:
client = new_client
CLIENT = new_client

return new_client

Expand Down
46 changes: 46 additions & 0 deletions utils/changelog_updater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
#
# Modifications Copyright OpenSearch Contributors. See
# GitHub history for details.

import requests


def main() -> None:
"""
Updating the CHANGELOG.md
"""
response = requests.get(
"https://api.github.com/repos/opensearch-project/opensearch-api-specification/commits"
)
if response.ok:
commit_info = response.json()[0]
commit_url = commit_info["html_url"]
latest_commit_sha = commit_info.get("sha")
else:
raise Exception(
f"Failed to fetch opensearch-api-specification commit information. Status code: {response.status_code}"
)

with open("CHANGELOG.md", "r+", encoding="utf-8") as file:
content = file.read()
if commit_url not in content:
if "### Updated APIs" in content:
file_content = content.replace(
"### Updated APIs",
f"### Updated APIs\n- Updated opensearch-py APIs to reflect [opensearch-api-specification@{latest_commit_sha[:7]}]({commit_url})",
1,
)
file.seek(0)
file.write(file_content)
file.truncate()
else:
raise Exception("'Updated APIs' section is not present in CHANGELOG.md")


if __name__ == "__main__":
main()
28 changes: 0 additions & 28 deletions utils/generate_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,34 +764,6 @@ def dump_modules(modules: Any) -> None:
unasync.unasync_files(filepaths, rules)
blacken(CODE_ROOT / "opensearchpy")

# Updating the CHANGELOG.md
response = requests.get(
"https://api.github.com/repos/opensearch-project/opensearch-api-specification/commits"
)
if response.ok:
commit_info = response.json()[0]
commit_url = commit_info["html_url"]
latest_commit_sha = commit_info.get("sha")
else:
raise Exception(
f"Failed to fetch opensearch-api-specification commit information. Status code: {response.status_code}"
)

with open("CHANGELOG.md", "r+", encoding="utf-8") as file:
content = file.read()
if commit_url not in content:
if "### Updated APIs" in content:
file_content = content.replace(
"### Updated APIs",
f"### Updated APIs\n- Updated opensearch-py APIs to reflect [opensearch-api-specification@{latest_commit_sha[:7]}]({commit_url})",
1,
)
file.seek(0)
file.write(file_content)
file.truncate()
else:
raise Exception("'Updated APIs' section is not present in CHANGELOG.md")


if __name__ == "__main__":
dump_modules(read_modules())

0 comments on commit 8472948

Please sign in to comment.