-
Notifications
You must be signed in to change notification settings - Fork 245
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
(aws_cdk): Py module error when using Bazel #3881
Comments
Upon further investigation, this appears to be more of an issue with how Bazel and pylint interact. With this upgrade, there are a couple new packages that |
|
While I can tell pylint to ignore CDK, the splitting of the package also seems to have broken my unit tests through |
I have been able to reproduce the issue with a minimal example: https://github.com/psalvaggio-dl/bazel-cdk-repro
|
I also opened an issue with
Explanation from @philsc at
Any thoughts about whether there might be something wrong with the main library's |
For anyone else running into this issue, there is a workaround, although it involves switching from
Then depend on |
Thanks for reporting this, I'm not familiar with Bazel at all - If this is an issue that's isolated to CDK customers using Bazel, which it seems to be, then why would this be a bug with CDK? I see the comment left in the other issue:
Can we have this comment elaborated upon? Why does having an extra |
Would this help?
So maybe switching to the
|
I'm transferring this to the jsii repo, since this would be changed through jsii. Thanks again for the report 🙂 |
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 |
Pinging this thread since I'm still stuck on 2.50. Is this a fix that I could help with? I'm not familiar with TypeScript, but it seems to me like the jsii/packages/jsii-pacmak/lib/targets/python.ts Line 2033 in cc6d294
|
It would be really useful if this was fixed - it is essentially preventing Bazel users from using recent aws-cdk-lib versions. |
+1 I have a customer facing this same issue and looking for guidance |
Regarding the changes made by @psalvaggio-dl, it seems like the primary change for getting past the import failures are actually using the
to
I still think this should be addressed , but I wanted to provide another workaround for anyone else stumbling into this problem. |
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. |
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: psalvaggio-dl/bazel-cdk-repro@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
The contents of from pkgutil import extend_path
__path__ = extend_path(__path__, __name__) to allow namespace packages and then the contents of __path__ = __import__('pkgutil').extend_path(__path__, __name__) 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 |
Would really appreciate it if someone can point me to a Bazel workspace that has targets for synthesizing and deploying a Python-based CDK. Can't seem to find an example anywhere. |
+1 we are also encountering this issue. @psalvaggio-dl 's fix above seems to have fixed our issue for the meantime. |
#4437) In Bazel, every package is extracted into a separate directory that are all put into the `$PYTHONPATH` individually. However when searching, Python will latch onto the directory that has an `__init__.py` in it and only import from that directory. Example: ``` eco_package1/ └── site-packages/ └── eco/ └── package1/ └── __init__.py eco/ └── site-packages/ └── eco/ └── __init__.py ``` In this case, the following command will fail: ```py import eco.package1 ``` Because `eco/package1/__init__.py` is not in the same directory as `eco/__init__.py`. We can fix this by generating a command into every `__init__.py` that uses `pkgutil` to extend the search path for a package; it will put all directories in `$PYTHONPATH` that contain the same package onto the search path for submodules. The command looks like this: ```py from pkgutil import extend_path __path__ = extend_path(__path__, __name__) ``` Resolves #3881, thanks to @psalvaggio-dl for providing a repro and doing the research for a fix. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
This issue is now closed. Comments on closed issues are hard for our team to see. |
@psalvaggio-dl did this fix the issue for you? It didn't for me, although I think it might have helped. I was able to get a simple example working with My understanding is that Edit: It sort of looks like these packages do set the
But I still get the following import error unless
|
@michaelboyd2 Yes we still have the issue (I used to work with Phil, I am still at the company). I can't seem to include Adding some more context, adding the |
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:
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:
Current Behavior
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
The text was updated successfully, but these errors were encountered: