Remove redundant mock backport dependency and upgrade syntax for Python 3.8+ (#785)
* Upgrade syntax with pyupgrade --py38-plus Signed-off-by: Hugo van Kemenade <[email protected]> * Convert to f-strings with flynt Signed-off-by: Hugo van Kemenade <[email protected]> * Format with Black Signed-off-by: Hugo van Kemenade <[email protected]> * Remove redundant mock backport dependency Signed-off-by: Hugo van Kemenade <[email protected]> * isort imports Signed-off-by: Hugo van Kemenade <[email protected]> * Add changelog entry Signed-off-by: Hugo van Kemenade <[email protected]> --------- Signed-off-by: Hugo van Kemenade <[email protected]>
This commit is contained in:
@@ -69,7 +69,7 @@ def run(*argv: Any, expect_exit_code: int = 0) -> None:
|
||||
else:
|
||||
os.chdir(TMP_DIR)
|
||||
|
||||
cmd = " ".join(shlex.quote(x) for x in argv)
|
||||
cmd = shlex.join(argv)
|
||||
print("$ " + cmd)
|
||||
exit_code = os.system(cmd)
|
||||
if exit_code != expect_exit_code:
|
||||
@@ -270,7 +270,7 @@ def main() -> None:
|
||||
# Rename the module to fit the suffix.
|
||||
shutil.move(
|
||||
os.path.join(BASE_DIR, "opensearchpy"),
|
||||
os.path.join(BASE_DIR, "opensearchpy%s" % suffix),
|
||||
os.path.join(BASE_DIR, f"opensearchpy{suffix}"),
|
||||
)
|
||||
|
||||
# Ensure that the version within 'opensearchpy/_version.py' is correct.
|
||||
@@ -279,7 +279,7 @@ def main() -> None:
|
||||
version_data = file.read()
|
||||
version_data = re.sub(
|
||||
r"__versionstr__: str = \"[^\"]+\"",
|
||||
'__versionstr__: str = "%s"' % version,
|
||||
f'__versionstr__: str = "{version}"',
|
||||
version_data,
|
||||
)
|
||||
with open(version_path, "w", encoding="utf-8") as file:
|
||||
@@ -296,7 +296,7 @@ def main() -> None:
|
||||
file.write(
|
||||
setup_py.replace(
|
||||
'PACKAGE_NAME = "opensearch-py"',
|
||||
'PACKAGE_NAME = "opensearch-py%s"' % suffix,
|
||||
f'PACKAGE_NAME = "opensearch-py{suffix}"',
|
||||
)
|
||||
)
|
||||
|
||||
@@ -306,7 +306,7 @@ def main() -> None:
|
||||
# Clean up everything.
|
||||
run("git", "checkout", "--", "setup.py", "opensearchpy/")
|
||||
if suffix:
|
||||
run("rm", "-rf", "opensearchpy%s/" % suffix)
|
||||
run("rm", "-rf", f"opensearchpy{suffix}/")
|
||||
|
||||
# Test everything that got created
|
||||
dists = os.listdir(os.path.join(BASE_DIR, "dist"))
|
||||
|
||||
@@ -95,7 +95,7 @@ def blacken(filename: Any) -> None:
|
||||
assert result.exit_code == 0, result.output
|
||||
|
||||
|
||||
@lru_cache()
|
||||
@lru_cache
|
||||
def is_valid_url(url: str) -> bool:
|
||||
"""
|
||||
makes a call to the url
|
||||
@@ -222,7 +222,7 @@ class Module:
|
||||
|
||||
# Identifying the insertion point for the "THIS CODE IS AUTOMATICALLY GENERATED" header.
|
||||
if os.path.exists(self.filepath):
|
||||
with open(self.filepath, "r", encoding="utf-8") as file:
|
||||
with open(self.filepath, encoding="utf-8") as file:
|
||||
content = file.read()
|
||||
if header_separator in content:
|
||||
update_header = False
|
||||
@@ -249,7 +249,7 @@ class Module:
|
||||
generated_file_header_path = os.path.join(
|
||||
current_script_folder, "generated_file_headers.txt"
|
||||
)
|
||||
with open(generated_file_header_path, "r", encoding="utf-8") as header_file:
|
||||
with open(generated_file_header_path, encoding="utf-8") as header_file:
|
||||
header_content = header_file.read()
|
||||
|
||||
# Imports are temporarily removed from the header and are regenerated
|
||||
@@ -287,7 +287,7 @@ class Module:
|
||||
# Generating imports for each module
|
||||
utils_imports = ""
|
||||
file_content = ""
|
||||
with open(self.filepath, "r", encoding="utf-8") as file:
|
||||
with open(self.filepath, encoding="utf-8") as file:
|
||||
content = file.read()
|
||||
keywords = [
|
||||
"SKIP_IN_PATH",
|
||||
|
||||
@@ -55,7 +55,7 @@ def does_file_need_fix(filepath: str) -> bool:
|
||||
if not re.search(r"\.py$", filepath):
|
||||
return False
|
||||
existing_header = ""
|
||||
with open(filepath, mode="r", encoding="utf-8") as file:
|
||||
with open(filepath, encoding="utf-8") as file:
|
||||
for line in file:
|
||||
line = line.strip()
|
||||
if len(line) == 0 or line in LINES_TO_KEEP:
|
||||
@@ -73,7 +73,7 @@ def add_header_to_file(filepath: str) -> None:
|
||||
writes the license header to the beginning of a file
|
||||
:param filepath: relative or absolute filepath to update
|
||||
"""
|
||||
with open(filepath, mode="r", encoding="utf-8") as file:
|
||||
with open(filepath, encoding="utf-8") as file:
|
||||
lines = list(file)
|
||||
i = 0
|
||||
for i, line in enumerate(lines):
|
||||
|
||||
Reference in New Issue
Block a user