Skip to content

Conversation

torresxb1
Copy link
Contributor

@torresxb1 torresxb1 commented Oct 12, 2021

Issue #, if available:

Description of changes:
Py27hash fix changes + removing python 2 from testing (the fix doesn't work with python 2, plus it's being deprecated).

Description of how you validated changes:
Added unit tests, ran changes through test suite

Checklist:

  • Add/update tests using:
  • make pr passes
  • Update documentation
  • Verify transformed template deploys and application functions as expected

Examples?

Please reach out in the comments, if you want to add an example. Examples will be
added to sam init through https://github.com/awslabs/aws-sam-cli-app-templates/

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Our officially supported Python versions are 2.7, 3.6, 3.7 and 3.8. Follow the idioms from this [excellent cheatsheet](http://python-future.org/compatible_idioms.html) to
make sure your code is compatible with both Python 2.7 and 3 (>=3.6) versions.
Our CI/CD pipeline is setup to run unit tests against both Python 2.7 and 3 versions. So make sure you test it with both versions before sending a Pull Request.
Our officially supported Python versions are 3.6, 3.7 and 3.8.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we're deprecating python 2, and this PR removes tests from running in python 2, I decided to also remove all other references to it. Let me know if I should undo the changes to documentation in case we want to do them more formally later on.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should update our setup.py to constraint to specific py versions too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did remove python 2.7 from setup.py in this PR, but I wasn't sure about Programming Language :: Python so that one is still in the file. Should I also remove it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking more like this: https://github.com/aws/aws-sam-cli/blob/develop/setup.py#L57 Maybe outside of this PR, but we don't actually constrain what python version are supported. So we can make the code none compatible but it could still be install-able through pip in python2.7

@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2021

Codecov Report

Merging #2182 (9181397) into develop (e7a1496) will increase coverage by 0.81%.
The diff coverage is 96.86%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2182      +/-   ##
===========================================
+ Coverage    93.58%   94.39%   +0.81%     
===========================================
  Files           90       97       +7     
  Lines         6124     7084     +960     
  Branches      1260     1433     +173     
===========================================
+ Hits          5731     6687     +956     
+ Misses         183      181       -2     
- Partials       210      216       +6     
Impacted Files Coverage Δ
samtranslator/model/api/http_api_generator.py 91.21% <75.00%> (+0.02%) ⬆️
samtranslator/model/api/api_generator.py 93.69% <89.09%> (-0.67%) ⬇️
samtranslator/model/apigateway.py 96.95% <96.00%> (-0.20%) ⬇️
samtranslator/__init__.py 100.00% <100.00%> (ø)
samtranslator/feature_toggle/dialup.py 100.00% <100.00%> (ø)
samtranslator/feature_toggle/feature_toggle.py 100.00% <100.00%> (+12.16%) ⬆️
samtranslator/intrinsics/actions.py 98.79% <100.00%> (+0.07%) ⬆️
samtranslator/metrics/method_decorator.py 100.00% <100.00%> (ø)
samtranslator/metrics/metrics.py 100.00% <100.00%> (ø)
samtranslator/model/__init__.py 97.64% <100.00%> (ø)
... and 33 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b89575...9181397. Read the comment docs.

@torresxb1 torresxb1 changed the title Py27hash fix fix: Py27hash fix Oct 13, 2021
@torresxb1 torresxb1 requested review from jfuss and marekaiv October 13, 2021 21:41
Our officially supported Python versions are 2.7, 3.6, 3.7 and 3.8. Follow the idioms from this [excellent cheatsheet](http://python-future.org/compatible_idioms.html) to
make sure your code is compatible with both Python 2.7 and 3 (>=3.6) versions.
Our CI/CD pipeline is setup to run unit tests against both Python 2.7 and 3 versions. So make sure you test it with both versions before sending a Pull Request.
Our officially supported Python versions are 3.6, 3.7 and 3.8.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should update our setup.py to constraint to specific py versions too.

if self.identity.get("Context"):
identity_source_context = list(map(lambda c: "context." + c, self.identity.get("Context")))
identity_source_context = []
for c in self.identity.get("Context"):
Copy link
Contributor

Choose a reason for hiding this comment

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

I see a pattern across these functions. Can we abstract this into a function?

+ make_shorthand(function_arn)
+ "/invocations"
)
if function_arn.get("Fn::GetAtt") and isinstance(function_arn["Fn::GetAtt"][0], Py27UniStr):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why only [0]? What happens if Fn::GetAtt:[] is defined?

Copy link
Contributor

Choose a reason for hiding this comment

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

function_arn is always of the form {"Fn::GetAtt": ["<function_logical_id>", "Arn"]} as it's created from function.get_runtime_attr("arn"). We only want to check if the function logical id is a Py27UniStr instance.

+ make_shorthand(function_arn)
+ "/invocations"
)
if function_arn.get("Fn::GetAtt") and isinstance(function_arn["Fn::GetAtt"][0], Py27UniStr):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why only GetAtt?

Copy link
Contributor

Choose a reason for hiding this comment

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

function_arn is always of the form {"Fn::GetAtt": ["<function_logical_id>", "Arn"]} as it's created from function.get_runtime_attr("arn"). So we only need to check Fn::GetAtt.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is a big assumption. It may be true today but a change could impact this code path unknowingly. I'll trust the team this is sufficient but intrinsic functions have bitten SAM so many times that checking like this seems risk. We should find ways to encapsulate this logic in some manner to reduce the intrinsic function reading spread throughout the code base.

if parameter_values is None:
raise ValueError("`parameter_values` argument is required")

self.validate_datatypes(sam_template)
Copy link
Contributor

Choose a reason for hiding this comment

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

self is weird to me here. I would assume if we are using self that validate_datatypes would not be a static method.

@@ -0,0 +1,23 @@
The AWS Serverless Application Model includes the following third-party software/licensing:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this file adding in our generated .whl files?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, will update it to include in the wheel

tox.ini Outdated
# and then run "tox" from this directory.

[tox]
envlist = py27, py36, py37, py38
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove py27

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missed that one, thank you

editor.add_auth_to_method(api=api, path=self.Path, method_name=self.Method, auth=self.Auth)


def _build_apigw_integration_uri(function, partition):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

didn't want to include partition as a parameter because I thought both ways would be equivalent, but a lot of tests failed when going with either way.

@torresxb1 torresxb1 requested a review from jfuss October 27, 2021 00:25
@hawflau hawflau merged commit a5db070 into develop Jan 3, 2022
@aahung aahung deleted the py27hash-20210918 branch February 7, 2023 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants