aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.51k stars 1.17k forks source link

aws-sam-cli imposes strict pin on `typing_extensions` #3808

Closed tmwong2003 closed 1 year ago

tmwong2003 commented 2 years ago

Description:

On Python 3.9, attempting to install mypy_boto3_dynamodb==1.21.23 alongside aws-sam-cli==1.45.0 results in import errors when using BatchStatementRequestTypeDef because aws-sam-cli forces a version of typing_extensions<4.0.0. Is there a good reason for the CLI to lock typing_extensions?

Steps to reproduce:

$ pip install aws-sam-cli mypy_boto3_dynamodb

Observed result:

$ python -c "from mypy_boto3_dynamodb.type_defs import BatchStatementRequestTypeDef"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/theodorew/temp/lib/python3.9/site-packages/mypy_boto3_dynamodb/__init__.py", line 37, in <module>
    from .client import DynamoDBClient
  File "/Users/theodorew/temp/lib/python3.9/site-packages/mypy_boto3_dynamodb/client.py", line 36, in <module>
    from .paginator import (
  File "/Users/theodorew/temp/lib/python3.9/site-packages/mypy_boto3_dynamodb/paginator.py", line 43, in <module>
    from .type_defs import (
  File "/Users/theodorew/temp/lib/python3.9/site-packages/mypy_boto3_dynamodb/type_defs.py", line 20, in <module>
    from typing_extensions import NotRequired
ImportError: cannot import name 'NotRequired' from 'typing_extensions' (/Users/theodorew/temp/lib/python3.9/site-packages/typing_extensions.py)
$ sam --version
SAM CLI, version 1.45.0
$

Expected result:

Installing aws-sam-cli should not cause type annotations imports to fail; in theory, the annotations should have no effect on running code.

$ pip install typing_extensions==4.0.0
Looking in indexes: https://artifactory.local.23andme.net/artifactory/api/pypi/pypi/simple/
Collecting typing_extensions==4.0.0
  Downloading https://artifactory.local.23andme.net/artifactory/api/pypi/pypi/packages/packages/17/61/32c3ab8951142e061587d957226b5683d1387fb22d95b4f69186d92616d1/typing_extensions-4.0.0-py3-none-any.whl (22 kB)
Installing collected packages: typing_extensions
  Attempting uninstall: typing_extensions
    Found existing installation: typing-extensions 3.10.0.0
    Uninstalling typing-extensions-3.10.0.0:
      Successfully uninstalled typing-extensions-3.10.0.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
aws-sam-cli 1.45.0 requires typing-extensions==3.10.0.0, but you have typing-extensions 4.0.0 which is incompatible.
Successfully installed typing_extensions-4.0.0
$ python -c "from mypy_boto3_dynamodb.type_defs import BatchStatementRequestTypeDef"
$ 

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: macOS 12.3.1 (Monterey)
  2. sam --version: SAM CLI, version 1.45.0
  3. AWS region:

Add --debug flag to command you are running

corleyma commented 2 years ago

Re: resolving this unnecessarily strict pin, it seems like updating typing_extensions==3.10.0.0 to typing_extensions>=3.10.0.0 in the base requirements ought to be sufficient.

qingchm commented 2 years ago

Thanks for taking your issues to us! Software versions are pinned down to specific versions for many reasons, I will try to raise it to the team to see if we will be able to satisfy your ask!

tbugfinder commented 2 years ago

I'm having the same issue. I understand the need to pin versions however in this case it seems to be very restricted.

mikemeyer30 commented 2 years ago

I believe I'm having a similar issue; blocked on completing a deployment until this is loosened up a little

Edit: Found a way around this issue, had to update the version of tensor flow my application was using to 2.8.0 so that it also relies on typing_extensions==3.10.0.0.

sriram-mv commented 2 years ago

To follow up on this issue, It is recommended to use the native brew installation method instead so that aws-sam-cli is treated as its own binary instead.

jfuss commented 1 year ago

We try to pin as much as possible, this is to keep a tight closure on the application and ensure what is installed is what we ran tests with. Otherwise we risk changes to dependencies breaking the CLI (which has happened). You will only run into this if you are using pip which our recommendation is not to. If you really desire to use pip as an installation method, you will need to put SAM CLI into it's own venv to isolate the dependencies.

github-actions[bot] commented 1 year ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.