Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(core): Python package aws-cdk-lib is missing the __version__ attribute #28875

Closed
mwebber opened this issue Jan 26, 2024 · 3 comments
Closed
Labels
@aws-cdk/core Related to core CDK functionality effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@mwebber
Copy link

mwebber commented Jan 26, 2024

Describe the bug

The normal convention in the Python world is for pip-installed packages to report their version number via the __version__ attribute. However, aws_cdk does not currently support this, so code cannot introspect its environment to check whether, for example, the expected version of aws_cdk is being used.

Expected Behavior

I expected it to work in the same was as most other Python packages, e.g

# this works
>>> import boto3
>>> boto3.__version__
'1.34.3'

Thus, I should be able to do

# this doesn't work, but should
>>> import aws_cdk
>>> aws_cdk.__version__
'2.113.0'

Current Behavior

# current behavior
>>> import aws_cdk
>>> aws_cdk.__version__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'aws_cdk' has no attribute '__version__'

Reproduction Steps

This can be tested in a stand-alone environment easily enough

Show that version not defined

python3
import aws_cdk
print(aws_cdk.__version__)
# AttributeError thrown here
exit()

The version is available in the package metadata, it's just not exposed as a python attribute

pip show aws-cdk-lib
Name: aws-cdk-lib
Version: 2.113.0
Summary: Version 2 of the AWS Cloud Development Kit library
Home-page: https://github.com/aws/aws-cdk
Author: Amazon Web Services
Author-email:
License: Apache-2.0
Location: /xxx/.venv/lib/python3.11/site-packages
Requires: aws-cdk.asset-awscli-v1, aws-cdk.asset-kubectl-v20, aws-cdk.asset-node-proxy-agent-v6, constructs, jsii, publication, typeguard

Possible Solution

No response

Additional Information/Context

The following workaround can be used to get what appears to be the CDK version, but it's clearly an irregular approach.

from aws_cdk._jsii import __jsii_assembly__ as jsii_assembly
print("*** have", jsii_assembly.version)

CDK CLI Version

2.113.0 (build ccd534a)

Framework Version

No response

Node.js Version

v20.10.0

OS

macOS 13.4.1

Language

Python

Language Version

Python (3.11.6)

Other information

No response

@mwebber mwebber added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 26, 2024
@github-actions github-actions bot added the @aws-cdk/core Related to core CDK functionality label Jan 26, 2024
@pahud pahud added p2 feature-request A feature should be added or improved. effort/small Small work item – less than a day of effort and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 29, 2024
@pahud
Copy link
Contributor

pahud commented Jan 29, 2024

Makes sense. Thank you for the feature request.

@mwebber
Copy link
Author

mwebber commented Feb 8, 2024

@pahud After further investigation, I found pallets/flask#5230, which suggests that __version__ is superseded by importlib.metadata..

This already works:

from importlib import metadata
[x.version for x in metadata.distributions() if x.name=='aws-cdk-lib'][0]
'2.113.0'

so maybe this ticket can be closed as unnecessary.

Copy link

⚠️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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

3 participants