Skip to content

Lifecycle python to 3.11 drop 3.6,7 #427

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

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion .github/workflows/pr-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
AWS_REGION: us-east-1
strategy:
matrix:
python: [3.7, 3.8, 3.9]
python: ["3.8", "3.9", "3.10", "3.11"]
java: [8, 11]
runs-on: ubuntu-latest
steps:
Expand Down
30 changes: 15 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
repos:
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.9.3
rev: v5.10.1
hooks:
- id: isort
# language_version: python3.6
- repo: https://github.com/ambv/black
rev: 22.3.0
rev: 23.9.1
hooks:
- id: black
# language_version: python3.6
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.0.0
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: end-of-file-fixer
- id: mixed-line-ending
args:
- --fix=lf
- id: trailing-whitespace
- id: pretty-format-json
args:
- --autofix
- --indent=4
- --no-sort-keys
- id: check-merge-conflict
- id: check-yaml
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear>=19.3.0
Expand All @@ -26,22 +34,14 @@ repos:
- flake8-comprehensions>=2.1.0
- flake8-debugger>=3.1.0
- flake8-pep3101>=1.2.1
# language_version: python3.6
- id: pretty-format-json
args:
- --autofix
- --indent=4
- --no-sort-keys
- id: check-merge-conflict
- id: check-yaml
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-mock-methods
- id: python-no-log-warn
- repo: https://github.com/PyCQA/bandit
rev: 1.7.0 # TODO: update once a release > 1.5.1 hits with this change in
rev: 1.7.5 # TODO: update once a release > 1.5.1 hits with this change in
hooks:
- id: bandit
files: "^python/"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ If you are using this package to build resource providers for CloudFormation, in

**Prerequisites**

- Python version 3.6 or above
- Python version 3.8 or above
- Your choice of Java IDE
- Lombok: The code generated by the CloudFormation CLI uses [Lombok](https://projectlombok.org/), which requires support in IDEs for some syntax highlighting to work. For the best development experience, it is recommended you install Lombok support in your IDE.

Expand Down
74 changes: 39 additions & 35 deletions python/rpdk/java/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
def logdebug(func: object):
def wrapper(*args, **kwargs):
log_msg = func.__name__ if not func.__doc__ else func.__doc__
entry_message = "{} started".format(log_msg)
entry_message = f"{log_msg} started".format()
LOG.debug(entry_message)
if "entity" in kwargs:
writing_message = "Writing {}".format(kwargs["entity"])
writing_message = f"Writing {log_msg}"
LOG.debug(writing_message)
result = func(*args, **kwargs)
exit_message = "{} complete".format(log_msg)
exit_message = f"{log_msg} complete"
LOG.debug(exit_message)
return result

Expand Down Expand Up @@ -109,9 +109,7 @@ def _prompt_for_namespace(self, project):

namespace = tuple(safe_reserved(s.lower()) for s in namespace)

prompt = "Enter a package name (empty for default '{}'): ".format(
".".join(namespace)
)
prompt = f"Enter a package name (empty for default '{'.'.join(namespace)}'): "

self.namespace = input_with_validation(prompt, validate_namespace(namespace))
project.settings["namespace"] = self.namespace
Expand Down Expand Up @@ -225,7 +223,7 @@ def init_shared(self, project, src, tst, resources):
path = project.root / "pom.xml"
LOG.debug("Writing Maven POM: %s", path)
template = self.env.get_template("init/shared/pom.xml")
artifact_id = "{}-handler".format(project.hypenated_name)
artifact_id = f"{project.hypenated_name}-handler"
jacoco_excluded_paths = self._get_jacoco_maven_plugin_excluded_paths(
project=project,
)
Expand Down Expand Up @@ -355,14 +353,18 @@ def init_hook_handlers(self, project, src, tst):
"""Writing hook stub handlers and tests"""
handlers = project.schema.get("handlers")
for operation in HOOK_OPERATIONS:
entity = "{}HookHandler.java".format(operation)
entity_test = "{}HookHandlerTest.java".format(operation)
entity = f"{operation}HookHandler.java"
entity_test = f"{operation}HookHandlerTest.java"

stub_entity = "Stub{}HookHandler.java".format(
operation if self._is_aws_guided(project) else ""
stub_entity = (
"Stub"
f"{operation if self._is_aws_guided(project) else ''}"
"HookHandler.java"
)
stub_entity_test = "Stub{}HookHandlerTest.java".format(
operation if self._is_aws_guided(project) else ""
stub_entity_test = (
"Stub"
f"{operation if self._is_aws_guided(project) else ''}"
"HookHandlerTest.java"
)
target_names = handlers.get(operation[0].lower() + operation[1:], {}).get(
"targetNames", ["My::Example::Resource"]
Expand Down Expand Up @@ -391,14 +393,17 @@ def init_resource_handlers(self, project, src, tst):
"""Writing stub handlers and tests"""
pojo_name = "ResourceModel"
for operation in RESOURCE_OPERATIONS:
entity = "{}Handler.java".format(operation)
entity_test = "{}HandlerTest.java".format(operation)

stub_entity = "Stub{}Handler.java".format(
operation if operation == "List" or self._is_aws_guided(project) else ""
entity = f"{operation}Handler.java"
entity_test = f"{operation}HandlerTest.java"

stub_entity = (
"Stub"
# pylint: disable=line-too-long
f"{operation if operation == 'List' or self._is_aws_guided(project) else ''}" # noqa: B950
"Handler.java"
)
stub_entity_test = "Stub{}HandlerTest.java".format(
operation if operation == "List" else ""
stub_entity_test = (
f"Stub{operation if operation == 'List' else ''}HandlerTest.java"
)

self._writing_component(
Expand Down Expand Up @@ -535,7 +540,7 @@ def generate_resource(self, src, project):
pojo_template = self.env.get_template("generate/POJO.java")

for model_name, properties in models.items():
path = src / "{}.java".format(model_name)
path = src / f"{model_name}.java"
LOG.debug("%s POJO: %s", model_name, path)

if model_name == "ResourceModel":
Expand Down Expand Up @@ -609,7 +614,7 @@ def generate_hook(self, src, project): # pylint: disable=too-many-statements
pojo_template = self.env.get_template("generate/POJO.java")

for model_name, properties in models.items():
path = src / "{}.java".format(model_name)
path = src / f"{model_name}.java"
LOG.debug("%s POJO: %s", model_name, path)

if model_name == "HookInputModel": # pragma: no cover
Expand Down Expand Up @@ -640,11 +645,10 @@ def generate_hook(self, src, project): # pylint: disable=too-many-statements
target_name = "".join(
[s.capitalize() for s in target_namespace]
) # awssqsqueue -> AwsSqsQueue
target_schema_file_name = "{}.json".format(
"-".join(target_namespace)
) # awssqsqueue -> aws-sqs-queue.json
target_model_package_name = "{}.model.{}".format(
self.package_name, ".".join(target_namespace)
target_schema_file_name = f"{'-'.join(target_namespace)}.json"
# awssqsqueue -> aws-sqs-queue.json
target_model_package_name = (
f"{self.package_name}.model.{'.'.join(target_namespace)}"
)
target_model_dir = (src / "model").joinpath(*target_namespace)
target_model_dir.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -691,7 +695,7 @@ def generate_hook(self, src, project): # pylint: disable=too-many-statements
pojo_template = self.env.get_template("generate/POJO.java")

for model_name, properties in models.items():
path = target_model_dir / "{}.java".format(model_name)
path = target_model_dir / f"{model_name}.java"
LOG.debug("%s POJO: %s", model_name, path)

if model_name == target_name:
Expand Down Expand Up @@ -724,7 +728,7 @@ def generate_hook(self, src, project): # pylint: disable=too-many-statements
)
project.overwrite(path, contents)

path = target_model_dir / "{}TargetModel.java".format(target_name)
path = target_model_dir / f"{target_name}TargetModel.java"
contents = base_template.render(
type_name=target_type_name,
model_name=target_name,
Expand Down Expand Up @@ -799,10 +803,10 @@ def _update_settings(self, project):
)
if java_plugin_dependency_version < MINIMUM_JAVA_DEPENDENCY_VERSION:
raise JavaPluginVersionNotSupportedError(
"'aws-cloudformation-rpdk-java-plugin' {} is no longer supported."
"Please update it in pom.xml to version {} or above.".format(
java_plugin_dependency_version, MINIMUM_JAVA_DEPENDENCY_VERSION
)
f"'aws-cloudformation-rpdk-java-plugin' "
f"{java_plugin_dependency_version} "
"is no longer supported. Please update it in pom.xml to version "
f"{MINIMUM_JAVA_DEPENDENCY_VERSION} or above."
)
except JavaPluginNotFoundError:
LOG.info(
Expand Down Expand Up @@ -833,7 +837,7 @@ def _update_settings(self, project):
@staticmethod
def _find_jar(project):
jar_glob = list(
(project.root / "target").glob("{}-*.jar".format(project.hypenated_name))
(project.root / "target").glob(f"{project.hypenated_name}-*.jar")
)
if not jar_glob:
LOG.debug("No Java Archives matched at %s", str(project.root / "target"))
Expand All @@ -855,7 +859,7 @@ def _find_jar(project):
@staticmethod
def _get_java_plugin_dependency_version(project):
try:
tree = ET.parse(project.root / "pom.xml")
tree = ET.parse(project.root / "pom.xml") # nosec
root = tree.getroot()
namespace = {"mvn": "http://maven.apache.org/POM/4.0.0"}
plugin_dependency_version = root.find(
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def find_version(*file_paths):
include_package_data=True,
zip_safe=True,
install_requires=["cloudformation-cli>=0.2.23"],
python_requires=">=3.6",
python_requires=">=3.8",
entry_points={"rpdk.v1.languages": ["java = rpdk.java.codegen:JavaLanguagePlugin"]},
license="Apache License 2.0",
classifiers=[
Expand All @@ -50,9 +50,10 @@ def find_version(*file_paths):
"Topic :: Software Development :: Code Generators",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
keywords="Amazon Web Services AWS CloudFormation",
)
20 changes: 9 additions & 11 deletions tests/test_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def mock_input_with_validation(prompt, validate): # pylint: disable=unused-argu
{"test": lambda: JavaLanguagePlugin},
clear=True,
), patch("rpdk.java.codegen.input_with_validation", new=mock_cli):
project.init("AWS::Foo::{}".format(RESOURCE), "test")
project.init(f"AWS::Foo::{RESOURCE}", "test")
return project


Expand All @@ -124,7 +124,7 @@ def mock_input_with_validation(prompt, validate): # pylint: disable=unused-argu
{"test": lambda: JavaLanguagePlugin},
clear=True,
), patch("rpdk.java.codegen.input_with_validation", new=mock_cli):
hook_project.init_hook("AWS::Foo::{}".format(RESOURCE), "test")
hook_project.init_hook(f"AWS::Foo::{RESOURCE}", "test")
return hook_project


Expand All @@ -134,14 +134,14 @@ def test_java_language_plugin_module_is_set():


def test_initialize(project):
expected_group_id = "software.amazon.foo.{}".format(RESOURCE.lower())
handler = "{}.HandlerWrapper::handleRequest".format(expected_group_id)
expected_group_id = f"software.amazon.foo.{RESOURCE.lower()}"
handler = f"{expected_group_id}.HandlerWrapper::handleRequest"
assert_test_initialize(project, handler, expected_group_id)


def test_hook_initialize(hook_project):
expected_group_id = "software.amazon.foo.{}".format(HOOK.lower())
handler = "{}.HookHandlerWrapper::handleRequest".format(expected_group_id)
expected_group_id = f"software.amazon.foo.{HOOK.lower()}"
handler = f"{expected_group_id}.HookHandlerWrapper::handleRequest"
assert_test_initialize(hook_project, handler, expected_group_id)


Expand All @@ -158,9 +158,7 @@ def assert_test_initialize(
with path.open("r", encoding="utf-8") as f:
template = yaml.safe_load(f)
handler_properties = template["Resources"]["TypeFunction"]["Properties"]
code_uri = "./target/{}-handler-1.0-SNAPSHOT.jar".format(
test_project.hypenated_name
)
code_uri = f"./target/{test_project.hypenated_name}-handler-1.0-SNAPSHOT.jar"
assert handler_properties["CodeUri"] == code_uri
assert handler_properties["Handler"] == handler
assert handler_properties["Runtime"] == test_project._plugin.RUNTIME
Expand Down Expand Up @@ -372,7 +370,7 @@ def make_target(project, count):
target.mkdir(exist_ok=True)
jar_paths = []
for i in range(count):
jar_path = target / "{}-{}.0-SNAPSHOT.jar".format(project.hypenated_name, i)
jar_path = target / f"{project.hypenated_name}-{i}.0-SNAPSHOT.jar"
jar_path.touch()
jar_paths.append(jar_path)
return jar_paths
Expand Down Expand Up @@ -423,7 +421,7 @@ def test_generate_without_java_plugin_in_pom_should_not_fail(project):


def test__get_plugin_version_invalid_pom(project):
with open(project.root / "pom.xml", "w") as pom:
with open(project.root / "pom.xml", "w", encoding="utf-8") as pom:
pom.write("invalid pom")
pom.close()
with pytest.raises(InvalidMavenPOMError):
Expand Down