[monocdk-experiment] Python - import incorrect
See original GitHub issueWhen using monocdk-experiment package in Python, stack cannot be created because some package are not imported.
Reproduction Steps
Install dependencies
pip install monocdk.experiment
app.py
#!/usr/bin/env python3
from monocdk_experiment import App, Stack, aws_codebuild
app = App()
class TestStack(Stack):
def __init__(self, scope, id, **kwargs):
super().__init__(scope, id, **kwargs)
TestStack(app, "test-stack")
Synthesize stacks
cdk synth
Error Log
Traceback (most recent call last):
File "app.py", line 2, in <module>
from monocdk_experiment import App, Stack, aws_codebuild
File "/Users/zangror/.venv/lib/python3.8/site-packages/monocdk_experiment/aws_codebuild/__init__.py", line 34, in <module>
from ..aws_ec2 import (
File "/Users/zangror/.venv/lib/python3.8/site-packages/monocdk_experiment/aws_ec2/__init__.py", line 46, in <module>
from ..aws_logs import ILogGroup as _ILogGroup_6b54c8e1
File "/Users/zangror/.venv/lib/python3.8/site-packages/monocdk_experiment/aws_logs/__init__.py", line 2613, in <module>
class MetricFilter(
File "/Users/zangror/.venv/lib/python3.8/site-packages/monocdk_experiment/aws_logs/__init__.py", line 2668, in MetricFilter
period: typing.Optional[_Duration_5170c158] = None,
NameError: name '_Duration_5170c158' is not defined
Environment
- CLI Version: 1.51.0 (build 8c2d53c)
- Framework Version: 1.51.0
- Node.js Version: 12.6
- OS: Mac OS Catalina 10.15.5
- Language (Version): Python (3.8.2)
Other
How to fix the error ?
If I open the file /Users/zangror/.venv/lib/python3.8/site-packages/monocdk_experiment/aws_logs/init.py this is the content:
import abc
import builtins
import datetime
import enum
import typing
import jsii
import jsii.compat
import publication
from .._jsii import *
from .. import (
CfnResource as _CfnResource_7760e8e4,
Construct as _Construct_f50a3f53,
FromCloudFormationOptions as _FromCloudFormationOptions_5f49f6f1,
ICfnFinder as _ICfnFinder_3b168f30,
TreeInspector as _TreeInspector_154f5999,
IInspectable as _IInspectable_051e6ed8,
IResolvable as _IResolvable_9ceae33e,
Resource as _Resource_884d0774,
IResource as _IResource_72f7ee7e,
RemovalPolicy as _RemovalPolicy_5986e9f3,
)
from ..aws_cloudwatch import (
Metric as _Metric_53e89548,
MetricOptions as _MetricOptions_ad2c4d5d,
)
from ..aws_iam import (
IRole as _IRole_e69bbae4,
PolicyStatement as _PolicyStatement_f75dc775,
PolicyDocument as _PolicyDocument_1d1bca11,
Grant as _Grant_96af6d2d,
IGrantable as _IGrantable_0fcfc53a,
)
If I add manually this specific dependency, this import error disappears
import abc
import builtins
import datetime
import enum
import typing
import jsii
import jsii.compat
import publication
from .._jsii import *
from .. import (
CfnResource as _CfnResource_7760e8e4,
Construct as _Construct_f50a3f53,
FromCloudFormationOptions as _FromCloudFormationOptions_5f49f6f1,
ICfnFinder as _ICfnFinder_3b168f30,
TreeInspector as _TreeInspector_154f5999,
IInspectable as _IInspectable_051e6ed8,
IResolvable as _IResolvable_9ceae33e,
Resource as _Resource_884d0774,
IResource as _IResource_72f7ee7e,
RemovalPolicy as _RemovalPolicy_5986e9f3,
Duration as _Duration_5170c158, # <-- Here
)
from ..aws_cloudwatch import (
Metric as _Metric_53e89548,
MetricOptions as _MetricOptions_ad2c4d5d,
)
from ..aws_iam import (
IRole as _IRole_e69bbae4,
PolicyStatement as _PolicyStatement_f75dc775,
PolicyDocument as _PolicyDocument_1d1bca11,
Grant as _Grant_96af6d2d,
IGrantable as _IGrantable_0fcfc53a,
)
It seems that in all the packages, core.Duration, aws_cloudwatch.Unit are not imported correctly, which is really strange because the others imports are well resolved.
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:5 (4 by maintainers)
Top Results From Across the Web
aws-cdk/assertions module
Functions for writing test asserting against CDK applications, with focus on CloudFormation templates. The Template class includes a set of methods for writing ......
Read more >@monocdk-experiment/rewrite-imports - npm
Rewrites typescript 'import' statements from @aws-cdk/xxx to monocdk. Latest version: 1.180.0, last published: 5 hours ago.
Read more >How to migrate CDK v1 to CDK v2 in 10 minuets
Construct by import * as cdk from '@aws-cdk/core'; in CDK v1. ... AND you don't see it wrong, all experimental modules will be...
Read more >@aws-cdk/assert | Yarn - Package Manager
... type-checking it introduced for Python results in incorrect code being produced. ... monocdk: assert package has incorrect imports (#7404 (825c9e1) ...
Read more >How to upgrade CDK from CDKv1 to CDKv2 in an existing ...
Experimental modules still need to be installed one by one. ... For this application, which is a python CDK App, a requirements.txt is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Submitted a PR with a fix in
jsii
.@SomayaB monocdk is @RomainMuller