Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed double-writes. #874

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added option to pass custom headers to 'AWSV4SignerAsyncAuth' ([863](https://github.com/opensearch-project/opensearch-py/pull/863))
- Added sync and async sample that uses `search_after` parameter ([859](https://github.com/opensearch-project/opensearch-py/pull/859))
### Updated APIs
- Updated opensearch-py APIs to reflect [opensearch-api-specification@a2afe56](https://github.com/opensearch-project/opensearch-api-specification/commit/a2afe567254c42aee70b74a8d7d7228c982b56db)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated, remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was confused because it auto-popped somehow

### Changed
- Small refactor of AWS Signer classes for both sync and async clients ([866](https://github.com/opensearch-project/opensearch-py/pull/866))
- Small refactor to fix overwriting the module files when generating apis ([874](https://github.com/opensearch-project/opensearch-py/pull/874))
### Deprecated
### Removed
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion test_opensearchpy/test_async/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ async def test_nowarn_when_test_uses_https_if_verify_certs_is_off(self) -> None:
assert (
str(w[0].message) == "enable_cleanup_closed ignored because "
"https://github.com/python/cpython/pull/118960 is fixed in "
"Python version sys.version_info(major=3, minor=12, micro=7, releaselevel='final', serial=0)"
"Python version sys.version_info(major=3, minor=12, micro=8, releaselevel='final', serial=0)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fine, but I'd prefer we fixed it once and for all by checking that the string contains https://github.com/python/cpython/pull/118960 and none of the other stuff.

)

assert isinstance(con.session, aiohttp.ClientSession)
Expand Down
82 changes: 41 additions & 41 deletions utils/generate_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,52 +272,52 @@ def dump(self) -> None:
if "from " + utils + " import" not in line
)

with open(self.filepath, "w", encoding="utf-8") as file:
if update_header is True:
file.write(
self.header[:license_position]
+ "\n"
+ header_content
+ "\n\n"
+ "#replace_token#\n"
+ self.header[license_position:]
)
else:
file.write(
self.header[:header_position]
+ "\n"
+ "#replace_token#\n"
+ self.header[header_position:]
)
for api in self._apis:
file.write(api.to_python())
module_content = ""
if update_header is True:
module_content += (
self.header[:license_position]
+ "\n"
+ header_content
+ "\n\n"
+ "#replace_token#\n"
+ self.header[license_position:]
)
else:
module_content += (
self.header[:header_position]
+ "\n"
+ "#replace_token#\n"
+ self.header[header_position:]
)
for api in self._apis:
module_content += api.to_python()

# Generating imports for each module
utils_imports = ""
file_content = ""
with open(self.filepath, encoding="utf-8") as file:
content = file.read()
keywords = [
"SKIP_IN_PATH",
"_normalize_hosts",
"_escape",
"_make_path",
"query_params",
"_bulk_body",
"_base64_auth_header",
"NamespacedClient",
"AddonClient",
]
present_keywords = [keyword for keyword in keywords if keyword in content]

if present_keywords:
utils_imports = "from " + utils + " import"
result = f"{utils_imports} {', '.join(present_keywords)}"
utils_imports = result
file_content = content.replace("#replace_token#", utils_imports)

keywords = [
"SKIP_IN_PATH",
"_normalize_hosts",
"_escape",
"_make_path",
"query_params",
"_bulk_body",
"_base64_auth_header",
"NamespacedClient",
"AddonClient",
]
present_keywords = [
keyword for keyword in keywords if keyword in module_content
]

if present_keywords:
utils_imports = "from " + utils + " import"
result = f"{utils_imports} {', '.join(present_keywords)}"
utils_imports = result
module_content = module_content.replace("#replace_token#", utils_imports)

with open(self.filepath, "w", encoding="utf-8") as file:
file.write(file_content)
file.write(module_content)

@property
def filepath(self) -> Any:
Expand Down
Loading