jsii: (aws_cdk): Py module error when using Bazel
Describe the bug
I have been able to localize the issue I am having to version 2.51.0. Prior to this version, all of my pylint tests are passing. However, after this version, I am getting many errors of the following form:
E0611: No name 'Duration' in module 'aws_cdk' (no-name-in-module)
This seems to apply to everything in the top-level aws_cdk
package. Subpackage import still seem to be working fine.
Expected Behavior
Clean pylint on imports like:
from aws_cdk import (
Duration,
)
Current Behavior
E0611: No name 'Duration' in module 'aws_cdk' (no-name-in-module)
Reproduction Steps
I’m having difficulty reproducing outside of my monorepo setup, so I’m mainly just looking for any insight on if anything changed and what might have caused this behavior.
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.53.0
Framework Version
2.53.0
Node.js Version
18.6.0
OS
Ubuntu
Language
Python
Language Version
3.9.10
Other information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 20 (4 by maintainers)
So the workaround (at least in my minimal reproduction repo’s case) was a bit more complicated. Here were the changes I had to make to get this working:
https://github.com/psalvaggio-dl/bazel-cdk-repro/compare/master...aspect_rules
While this change set does provide a workaround, I don’t think it is a great solution for the following reasons:
With respect to 5, I think this has given me a bit more insight into how this is supposed to look. I had another namespace package installed. When I look at the
runfiles
tree for my target, I see the following:The contents of
pip_<main_package>/<main_package>/__init__.py
were as normal, but containedto allow namespace packages and then the contents of
pip_<namespace_package>/<main_package>/__init__.py
were:The two statements are I think identical, although they are written a bit different. If we compare this to the AWS CDK, the main package’s
__init__.py
is missing this line and the namespace packages’__init__.py
files at theaws_cdk
level are missing entirely. I think replicating the behavior above might be the correct fix.This issue also appears to be affecting versions prior to 2.51.0 if alpha modules are used. I can work around these issues by disabling testing on all code that uses alpha modules, but this is not ideal. I am still stuck on 2.50 because with 2.51, the issue propagates up to the main
aws_cdk
module, rendering all CDK code untestable.Thanks, this might be a useful workaround for some people, but it is quite a major change to how Python is being built which many will not want to go with. I only mention this because I do not want an AWS developer who is not that familiar with Bazel to read your post and think “Ah there is an easy workaround, this does not need to be prioritised”, because that would not be right. I appreciate this is not what you were trying to say, and it is useful for the option you mention to be made more explicit.
+1 I have a customer facing this same issue and looking for guidance