aws / constructs

Define composable configuration models through code
Apache License 2.0
409 stars 42 forks source link

Update Python dependencies (typeguard) #2063

Open osqui0110 opened 10 months ago

osqui0110 commented 10 months ago

Hey! I'm not sure about how you manage python dependencies. I'm working on a project using glue Python shell scripts. Trying to add Pandera to validate Pandas DFs, my dependency manager (poetry) shows:

Because no versions of pandera match >0.18.0,<0.19.0
 and pandera (0.18.0) depends on typeguard (>=3.0.2), pandera (>=0.18.0,<0.19.0) requires typeguard (>=3.0.2).
And because constructs (10.3.0) depends on typeguard (>=2.13.3,<2.14.0)
 and no versions of constructs match >10.3.0,<11.0.0, pandera (>=0.18.0,<0.19.0) is incompatible with constructs (>=10.3.0,<11.0.0).
So, because testglue depends on both constructs (^10.3.0) and pandera (^0.18.0), version solving failed.

That version of Typeguard is quite old (currently 4.x)

Is it possible to use updated dependencies? thx!

iwanbolzern commented 8 months ago

Dear AWS Team,

We are in the same situation as @osqui0110. Would it be possible to update the typeguard version.

Thank you and all the best!

iwanbolzern commented 8 months ago

I hoppend a PR for jsii to fix this: https://github.com/aws/jsii/pull/4455 It would be great if someone could review it.

MatthewGrant commented 1 month ago

@mrgrain Me again, seeing a similar issue here with pinned typeguard package for the python runtime. Let me know if you think this can also be upgraded. Thanks.

mrgrain commented 1 month ago

The latest release should include this: https://github.com/aws/constructs/releases/tag/v10.3.1

LMK if it works.

MatthewGrant commented 1 month ago

The latest release should include this: https://github.com/aws/constructs/releases/tag/v10.3.1

LMK if it works.

You're the best! Looks like we are all good now. Thanks.

berkaycagir commented 1 month ago

constructs==10.3.1 (which pip installed with typeguard==4.3.0) broke our deployment which was creating an NLB through aws-cdk-lib==2.162.0, just as an FYI:

$ python
Python 3.12.7 (main, Oct  7 2024, 11:35:44) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from aws_cdk import aws_ec2 as ec2, aws_elasticloadbalancingv2 as elb2
>>> from aws_cdk import Stack
>>> stack = Stack()
>>> vpc = ec2.Vpc(stack, "test-vpc")
>>> nlb = elb2.NetworkLoadBalancer(stack, "test-nlb", vpc=vpc)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/jsii/_runtime.py", line 118, in __call__
    inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/aws_cdk/aws_elasticloadbalancingv2/__init__.py", line 16504, in __init__
    props = NetworkLoadBalancerProps(
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/aws_cdk/aws_elasticloadbalancingv2/__init__.py", line 17314, in __init__
    check_type(argname="argument vpc", value=vpc, expected_type=type_hints["vpc"])
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/aws_cdk/aws_elasticloadbalancingv2/__init__.py", line 967, in check_type
    typeguard.check_type(value=value, expected_type=expected_type, collection_check_strategy=typeguard.CollectionCheckStrategy.ALL_ITEMS) # type:ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/typeguard/_functions.py", line 106, in check_type
    check_type_internal(value, expected_type, memo)
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/typeguard/_checkers.py", line 861, in check_type_internal
    checker(value, origin_type, args, memo)
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/typeguard/_checkers.py", line 729, in check_protocol
    raise TypeCheckError(
typeguard.TypeCheckError: aws_cdk.aws_ec2.Vpc is not compatible with the IVpc protocol because its 'add_client_vpn_endpoint' method has mandatory keyword-only arguments in its declaration: cidr, server_certificate_arn
mrgrain commented 1 month ago

Thanks for the report @berkaycagir Can you help me understand what's the issue here?

It looks the new release of constructs caused your python project to now install typeguard v4, whereas previously it would pick typeguard v2?

And with that newer version of typeguard, there's an incompatibility with the VPC construct in aws-cdk-lib?

Does that some it up alright?

fraghag commented 1 month ago

constructs==10.3.1 (which pip installed with typeguard==4.3.0) broke our deployment which was creating an NLB through aws-cdk-lib==2.162.0, just as an FYI:

$ python
Python 3.12.7 (main, Oct  7 2024, 11:35:44) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from aws_cdk import aws_ec2 as ec2, aws_elasticloadbalancingv2 as elb2
>>> from aws_cdk import Stack
>>> stack = Stack()
>>> vpc = ec2.Vpc(stack, "test-vpc")
>>> nlb = elb2.NetworkLoadBalancer(stack, "test-nlb", vpc=vpc)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/jsii/_runtime.py", line 118, in __call__
    inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/aws_cdk/aws_elasticloadbalancingv2/__init__.py", line 16504, in __init__
    props = NetworkLoadBalancerProps(
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/aws_cdk/aws_elasticloadbalancingv2/__init__.py", line 17314, in __init__
    check_type(argname="argument vpc", value=vpc, expected_type=type_hints["vpc"])
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/aws_cdk/aws_elasticloadbalancingv2/__init__.py", line 967, in check_type
    typeguard.check_type(value=value, expected_type=expected_type, collection_check_strategy=typeguard.CollectionCheckStrategy.ALL_ITEMS) # type:ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/typeguard/_functions.py", line 106, in check_type
    check_type_internal(value, expected_type, memo)
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/typeguard/_checkers.py", line 861, in check_type_internal
    checker(value, origin_type, args, memo)
  File "/Users/.../.pyenv/versions/.../lib/python3.12/site-packages/typeguard/_checkers.py", line 729, in check_protocol
    raise TypeCheckError(
typeguard.TypeCheckError: aws_cdk.aws_ec2.Vpc is not compatible with the IVpc protocol because its 'add_client_vpn_endpoint' method has mandatory keyword-only arguments in its declaration: cidr, server_certificate_arn

The new typeguard is doing what it should. This error is due to a bug that let's jsii generate broken python code: https://github.com/aws/jsii/issues/4541

mrgrain commented 1 month ago

Yes, there's clearly something wrong with the code jsii produces.

https://github.com/aws/jsii/issues/4541 is a known issue, but this case seems to be different because the keyword args do match in both protocol and implementation. 🤔

mrgrain commented 1 month ago

Continuing the conversation here: https://github.com/aws/jsii/issues/4658

mrgrain commented 1 month ago

We yanked the 10.3.1 release of constructs from PyPI as a quick mitigation for most users. https://pypi.org/project/constructs/10.3.1/

We will revert this to an older version of typeguard soon.

Re-opened this issue to track that we eventually need to release support for newer typeguard versions.


To discuss the issue itself, please use https://github.com/aws/jsii/issues/4658

berkaycagir commented 1 month ago

Thanks for the report @berkaycagir Can you help me understand what's the issue here?

It looks the new release of constructs caused your python project to now install typeguard v4, whereas previously it would pick typeguard v2?

And with that newer version of typeguard, there's an incompatibility with the VPC construct in aws-cdk-lib?

Does that some it up alright?

I'm sorry I wasn't able to provide more details; but thank you very much for following up on it and the yank, I appreciate it.