Skip to content

Commit 77d83d1

Browse files
committed
chore: consolidate property lists, mark unused methods, document validator
Three cleanup items from the review: #5: _ARTIFACT_PATH_PROPERTIES in template.py was a hand-maintained set of property names that duplicated PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES in models.py. Replaced with a frozenset derived from the canonical source so the two cannot drift. #6: SamTranslatorWrapper.get_original_template() and get_dynamic_artifact_properties() are only called in tests — callers now consume LanguageExtensionResult directly. Added a TODO comment rather than deleting (would require removing ~20 test methods across 3 files — not worth the churn in this PR). #7: Documented that get_translated_template_if_valid mutates self.sam_template when language extensions are present. The mutation is idempotent (re-expanding an already-expanded template is a no-op) so double-calling is safe, but the comment makes the contract explicit.
1 parent 7c9e94b commit 77d83d1

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

samcli/commands/_utils/template.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from botocore.utils import set_value_from_jmespath
1212

1313
from samcli.commands.exceptions import UserException
14+
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
1415
from samcli.lib.cfn_language_extensions.utils import (
1516
FOREACH_REQUIRED_ELEMENTS,
1617
is_foreach_key,
@@ -29,20 +30,12 @@
2930
)
3031
from samcli.yamlhelper import yaml_dump, yaml_parse
3132

32-
# Artifact path property names that represent local file paths in SAM-generated Mappings.
33-
# These need relative path adjustment when templates are moved between directories.
34-
_ARTIFACT_PATH_PROPERTIES = {
35-
"CodeUri",
36-
"ImageUri",
37-
"ContentUri",
38-
"Content",
39-
"DefinitionUri",
40-
"BodyS3Location",
41-
"DefinitionS3Location",
42-
"SchemaUri",
43-
"TemplateURL",
44-
"Location",
45-
}
33+
# Artifact path property names derived from PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
34+
# so the two lists cannot drift. Used by _update_sam_mappings_relative_paths to
35+
# identify which SAM-generated Mapping values are local paths needing adjustment.
36+
_ARTIFACT_PATH_PROPERTIES = frozenset(
37+
prop for props in PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES.values() for prop in props
38+
)
4639

4740

4841
class TemplateNotFoundException(UserException):

samcli/lib/samlib/wrapper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def run_plugins(self, convert_local_uris=True):
107107
def template(self):
108108
return copy.deepcopy(self._sam_template)
109109

110+
# TODO: get_original_template and get_dynamic_artifact_properties are only
111+
# called in tests. Callers now consume LanguageExtensionResult directly.
112+
# Consider removing these methods and their backing fields
113+
# (_original_template, _dynamic_artifact_properties) in a follow-up.
110114
def get_original_template(self) -> Dict[str, Any]:
111115
"""
112116
Get the original unexpanded template for CloudFormation deployment.

samcli/lib/translate/sam_template_validator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ def get_translated_template_if_valid(self):
8787
boto_session=self.boto3_session,
8888
)
8989

90-
# Process language extensions before validation if AWS::LanguageExtensions transform is present
90+
# Process language extensions before validation if AWS::LanguageExtensions transform is present.
91+
# Note: this mutates self.sam_template when LE is present. The assignment is idempotent
92+
# (expand_language_extensions returns a deepcopy, and re-expanding an already-expanded
93+
# template is a no-op since the transform is still present but ForEach is already resolved).
9194
parameter_values = dict(IntrinsicsSymbolTable.DEFAULT_PSEUDO_PARAM_VALUES)
9295
parameter_values.update(self.parameter_overrides)
9396
result = expand_language_extensions(self.sam_template, parameter_values=parameter_values)

0 commit comments

Comments
 (0)