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

[Python] Issue when importing nested submodules. #3408

Closed
1 of 5 tasks
agdimech opened this issue Mar 4, 2022 · 3 comments · Fixed by #3540
Closed
1 of 5 tasks

[Python] Issue when importing nested submodules. #3408

agdimech opened this issue Mar 4, 2022 · 3 comments · Fixed by #3540
Labels
bug This issue is a bug. module/runtime Issues affecting the `jsii-runtime` p1

Comments

@agdimech
Copy link
Contributor

agdimech commented Mar 4, 2022

🐛 Bug Report

Affected Languages

  • TypeScript or Javascript
  • Python
  • Java
  • .NET (C#, F#, ...)
  • Go

General Information

  • JSII Version: 1.54.0 (build b1b977a), typescript 3.9.10
  • Platform: Darwin 3c22fb43e27e.ant.amazon.com 20.6.0 Darwin Kernel Version 20.6.0: Wed Jan 12 22:22:42 PST 2022; root:xnu-7195.141.19~2/RELEASE_X86_64 x86_64

What is the problem?

I am extending TypescriptProject from Projen within my own package. When I run pacmak it successfully generates the python distributable, however at runtime when I import my module I am experiencing the following error:

module 'projen.github' has no attribute 'workflows'

I did some digging and this is likely due to a bug in how nested packages in python are imported.

Looking at how it is being imported in the generated dist:

import projen.github.workflows

vs how it should be imported:

from projen.github.workflows import (
    JobStep as _JobStep_c3287c05, Triggers as _Triggers_e9ae7617
)

If I look at the generated imports for the TypeScriptProject, they are correctly importing using aliases, just not sure why my code is not (perhaps because it is a different assembly?).

I manually edited my imports to use aliases as above and it resolves the issue.

Here is a link to the generated artifact that you can reference: https://pypi.org/project/aws-prototyping-sdk/

Linked projen issue: projen/projen#1653

@agdimech agdimech added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 4, 2022
@NGL321 NGL321 added module/runtime Issues affecting the `jsii-runtime` p1 and removed needs-triage This issue or PR still needs to be triaged. labels Mar 4, 2022
@agdimech
Copy link
Contributor Author

I am thinking it may be because of this import?

It seems to be complaining that the projen.github.workflows attribute doesn't exist and if I look through the generated projen python code in the below files, I can't seem to find a wrapper component with the attribute jsii_type="projen.github.workflows":

  • /projen/github/init.py
  • /projen/github/workflows/init.py

@agdimech
Copy link
Contributor Author

You can repo this locally by running: npx projen new --from aws-prototyping-sdk pdk-pipeline-py.

Note: the generated .projenrc.py is synthesized with an incorrect module_name due to a bug in projen: projen/projen#1851.

Workaround: manually rename the import in .projenrc.py from aws-prototyping-sdk -> aws_prototyping_sdk

RomainMuller added a commit that referenced this issue May 13, 2022
Nested submodules were not registered in the `__all__` list of their
parent, and so were not visible to import statement such as
`from fully.qualified.submodule.path import Name`.

This changes how submodules get loaded so that they are always declared
and loaded with the context of their immediate parent sub•module, which
guarantees they are present in the relevant `__all__` list.

Fixes #3408
RomainMuller added a commit that referenced this issue May 13, 2022
Nested submodules were not registered in the `__all__` list of their
parent, and so were not visible to import statement such as
`from fully.qualified.submodule.path import Name`.

This changes how submodules get loaded so that they are always declared
and loaded with the context of their immediate parent sub•module, which
guarantees they are present in the relevant `__all__` list.

Fixes #3408
@mergify mergify bot closed this as completed in #3540 May 13, 2022
mergify bot pushed a commit that referenced this issue May 13, 2022
Nested submodules were not registered in the `__all__` list of their
parent, and so were not visible to import statement such as
`from fully.qualified.submodule.path import Name`.

This changes how submodules get loaded so that they are always declared
and loaded with the context of their immediate parent sub•module, which
guarantees they are present in the relevant `__all__` list.

Fixes #3408



---

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
@github-actions
Copy link
Contributor

⚠️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
bug This issue is a bug. module/runtime Issues affecting the `jsii-runtime` p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants