Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/pip/requirements/develop/wheel…
Browse files Browse the repository at this point in the history
…-0.45.0
  • Loading branch information
mndeveci authored Nov 15, 2024
2 parents dfef53e + 13d2379 commit fe84433
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 37 deletions.
31 changes: 16 additions & 15 deletions DEVELOPMENT_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Gitpod is free for 50 hours per month - make sure to stop your workspace when yo
## Environment Setup
### 1. Prerequisites (Python Virtual Environment)

AWS SAM CLI is mainly written in Python 3 and we support Python 3.7 and 3.8.
So having a Python environment with aforementioned versions is required.
AWS SAM CLI is mainly written in Python 3 and we support Python 3.8 and above.
So, having a Python environment with this version is required.

Having a dedicated Python virtual environment ensures it won't "pollute" or get "polluted"
by other python packages. Here we introduce two ways of setting up a Python virtual environment:
Expand Down Expand Up @@ -163,26 +163,27 @@ contribute to the repository, there are a few more things to consider.

### Make Sure AWS SAM CLI Work in Multiple Python Versions

We support 3.7 and 3.8 versions. Our CI/CD pipeline is setup to run
We support version 3.8 and above. Our CI/CD pipeline is setup to run
unit tests against all Python versions. So make sure you test it
with all versions before sending a Pull Request.
See [Unit testing with multiple Python versions](#unit-testing-with-multiple-python-versions-optional).
See [Unit testing with multiple Python versions](#unit-testing-with-multiple-python-versions-optional).
This is most important if you are developing in a Python version greater than the minimum supported version (currently 3.8), as any new features released in 3.9+ will not work.

If you chose to use `pyenv` in the previous session, setting up a
different Python version should be easy:

(assuming you are in virtual environment `samcli38`)
(assuming you are in virtual environment named `samcli39` with Python version 3.9.x)

```sh
# Your shell now should looks like "(samcli38) $"
pyenv deactivate samcli38 # "(samcli38)" will disappear
pyenv install 3.7.10 # one time setup
pyenv virtualenv 3.7.10 samcli37 # one time setup
pyenv activate samcli37
# Your shell now should looks like "(samcli37) $"
# Your shell now should look like "(samcli39) $"
pyenv deactivate samcli39 # "(samcli39)" will disappear
pyenv install 3.8.9 # one time setup
pyenv virtualenv 3.8.9 samcli38 # one time setup
pyenv activate samcli38
# Your shell now should look like "(samcli38) $"

# You can verify the version of Python
python --version # Python 3.7.10
python --version # Python 3.8.9

make init # one time setup, this will put a file `samdev` available in $PATH
```
Expand Down Expand Up @@ -255,9 +256,9 @@ We also suggest to run `make pr` or `./Make -pr` in all Python versions.
#### Unit Testing with Multiple Python Versions (Optional)

Currently, SAM CLI only supports Python3 versions (see setup.py for exact versions). For the most
part, code that works in Python3.7 will work in Python3.8. You only run into problems if you are
trying to use features released in a higher version (for example features introduced into Python3.8
will not work in Python3.7). If you want to test in many versions, you can create a virtualenv for
part, code that works in Python3.8 will work in Python3.9. You only run into problems if you are
trying to use features released in a higher version (for example features introduced into Python3.9
will not work in Python3.8). If you want to test in many versions, you can create a virtualenv for
each version and flip between them (sourcing the activate script). Typically, we run all tests in
one python version locally and then have our ci (appveyor) run all supported versions.

Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ regex!=2021.10.8
tzlocal==5.2

#Adding cfn-lint dependency for SAM validate
cfn-lint~=1.18.4
cfn-lint~=1.19.0

# Type checking boto3 objects
boto3-stubs[apigateway,cloudformation,ecr,iam,lambda,s3,schemas,secretsmanager,signer,stepfunctions,sts,xray,sqs,kinesis]==1.35.56
6 changes: 3 additions & 3 deletions requirements/reproducible-linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ cffi==1.17.1 \
--hash=sha256:f7f5baafcc48261359e14bcd6d9bff6d4b28d9103847c9e136694cb0501aef87 \
--hash=sha256:fc48c783f9c87e60831201f2cce7f3b2e4846bf4d8728eabe54d60700b318a0b
# via cryptography
cfn-lint==1.18.4 \
--hash=sha256:73dadc33d6a91c69651cb08fe919138ab4e2f6cf1be1e361f7c6dcbccd1527ba \
--hash=sha256:76741e76fa26f31bfacc3eb465eddd93ad535838d84fbc6dd092817d8e22d57f
cfn-lint==1.19.0 \
--hash=sha256:63835e083f7831e54c512bce4808754df221b5895aed9a114c71879d1cc4ebff \
--hash=sha256:9c43a6b866915df6d2ac5584000ef05e53c67624809808c2cebd3dc6154b7c14
# via aws-sam-cli (setup.py)
chardet==5.2.0 \
--hash=sha256:1b3b6ff479a8c414bc3fa2c0852995695c4a026dcd6d0633b2dd092ca39c1cf7 \
Expand Down
6 changes: 3 additions & 3 deletions requirements/reproducible-mac.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ cffi==1.17.1 \
--hash=sha256:f7f5baafcc48261359e14bcd6d9bff6d4b28d9103847c9e136694cb0501aef87 \
--hash=sha256:fc48c783f9c87e60831201f2cce7f3b2e4846bf4d8728eabe54d60700b318a0b
# via cryptography
cfn-lint==1.18.4 \
--hash=sha256:73dadc33d6a91c69651cb08fe919138ab4e2f6cf1be1e361f7c6dcbccd1527ba \
--hash=sha256:76741e76fa26f31bfacc3eb465eddd93ad535838d84fbc6dd092817d8e22d57f
cfn-lint==1.19.0 \
--hash=sha256:63835e083f7831e54c512bce4808754df221b5895aed9a114c71879d1cc4ebff \
--hash=sha256:9c43a6b866915df6d2ac5584000ef05e53c67624809808c2cebd3dc6154b7c14
# via aws-sam-cli (setup.py)
chardet==5.2.0 \
--hash=sha256:1b3b6ff479a8c414bc3fa2c0852995695c4a026dcd6d0633b2dd092ca39c1cf7 \
Expand Down
6 changes: 3 additions & 3 deletions requirements/reproducible-win.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ cffi==1.17.1 \
--hash=sha256:f7f5baafcc48261359e14bcd6d9bff6d4b28d9103847c9e136694cb0501aef87 \
--hash=sha256:fc48c783f9c87e60831201f2cce7f3b2e4846bf4d8728eabe54d60700b318a0b
# via cryptography
cfn-lint==1.18.4 \
--hash=sha256:73dadc33d6a91c69651cb08fe919138ab4e2f6cf1be1e361f7c6dcbccd1527ba \
--hash=sha256:76741e76fa26f31bfacc3eb465eddd93ad535838d84fbc6dd092817d8e22d57f
cfn-lint==1.19.0 \
--hash=sha256:63835e083f7831e54c512bce4808754df221b5895aed9a114c71879d1cc4ebff \
--hash=sha256:9c43a6b866915df6d2ac5584000ef05e53c67624809808c2cebd3dc6154b7c14
# via aws-sam-cli (setup.py)
chardet==5.2.0 \
--hash=sha256:1b3b6ff479a8c414bc3fa2c0852995695c4a026dcd6d0633b2dd092ca39c1cf7 \
Expand Down
2 changes: 1 addition & 1 deletion samcli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
SAM CLI version
"""

__version__ = "1.128.0"
__version__ = "1.129.0"
23 changes: 14 additions & 9 deletions samcli/commands/init/init_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,21 @@ def _get_manifest(self):
"""
try:
response = requests.get(MANIFEST_URL, timeout=10)
body = response.text
# if the commit is not exist then MANIFEST_URL will be invalid, fall back to use manifest in latest commit
if response.status_code == Status.NOT_FOUND.value:
LOG.warning(
"Request to MANIFEST_URL: %s failed, the commit hash in this url maybe invalid, "
"Using manifest.json in the latest commit instead.",
MANIFEST_URL,
)
if not response.ok:
# if the commit is not exist then MANIFEST_URL will be invalid,
# fall back to use manifest in latest commit
if response.status_code == Status.NOT_FOUND.value:
LOG.warning(
"Request to MANIFEST_URL: %s failed, the commit hash in this url maybe invalid, "
"Using manifest.json in the latest commit instead.",
MANIFEST_URL,
)
else:
LOG.debug(
"Request to MANIFEST_URL: %s failed, with %s status code", MANIFEST_URL, response.status_code
)
raise ManifestNotFoundException()

body = response.text
except (requests.Timeout, requests.ConnectionError, ManifestNotFoundException):
LOG.debug("Request to get Manifest failed, attempting to clone the repository")
self.clone_templates_repo()
Expand Down
2 changes: 1 addition & 1 deletion samcli/runtime_config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"app_template_repo_commit": "994ec01c08fa415ed20258d72cb7f750b8b8211d"
"app_template_repo_commit": "a22d509a91e0ceca3eb596ab13d5ebe76ff0a894"
}
1 change: 1 addition & 0 deletions tests/integration/validate/test_validate_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def test_lint_supported_runtimes(self):
"python3.10",
"python3.11",
"python3.12",
"python3.13",
"ruby3.2",
"ruby3.3",
]
Expand Down
20 changes: 19 additions & 1 deletion tests/unit/commands/init/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path
from typing import Dict, Any
from unittest import TestCase
from unittest.mock import patch, ANY
from unittest.mock import patch, ANY, Mock

import botocore.exceptions
import click
Expand Down Expand Up @@ -2204,6 +2204,24 @@ def test_must_return_runtime_from_base_image_name(self):
runtime = get_runtime(IMAGE, base_image)
self.assertEqual(runtime, expected_runtime[index])

@patch("samcli.commands.init.init_templates.requests")
@patch.object(InitTemplates, "__init__", MockInitTemplates.__init__)
def test_must_fallback_for_non_ok_http_response(self, requests_mock):
requests_mock.get.return_value = Mock(ok=False)
requests_mock.Timeout = requests.Timeout
requests_mock.ConnectionError = requests.ConnectionError

template = InitTemplates()
with mock.patch.object(
template, "clone_templates_repo", wraps=template.clone_templates_repo
) as mocked_clone_templates_repo:
with mock.patch.object(
template, "get_manifest_path", wraps=template.get_manifest_path
) as mocked_get_manifest_path:
template.get_preprocessed_manifest()
mocked_clone_templates_repo.assert_called_once()
mocked_get_manifest_path.assert_called_once()

@patch("samcli.commands.init.init_templates.InitTemplates._get_manifest")
@patch.object(InitTemplates, "__init__", MockInitTemplates.__init__)
def test_must_process_manifest(self, _get_manifest_mock):
Expand Down

0 comments on commit fe84433

Please sign in to comment.