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

fix(python): imports between subpackages are broken #1528

Merged
merged 18 commits into from
May 14, 2020

Conversation

RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented Apr 10, 2020

Commit Message

fix(python): imports between subpackages are broken (#1528)

Using absolute imports from a sub-package to another of the same root
package causes cycles in the module loading machinery, resulting in
obscure errors (typically, the loader complaining that the root module
name is not defined).

This changes the name generation mechanism so that relative imports are
used to refer to sub-packages within a same root, as per the best
practices. This allows the module loaded to flatten the loop and
successfully load everything (granted, as always, there is no
intractible loop between the sub-packages).

End Commit Message


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Using absolute imports from a sub-package to another of the same root
package causes cycles in the module loading machinery, resulting in
obscure errors (typically, the loader complaining that the root module
name is not defined).

This changes the name generation mechanism so that relative imports are
used to refer to sub-packages within a same root, as per the best
practices. This allows the module loaded to flatten the loop and
successfully load everything (granted, as always, there is no
intractible loop between the sub-packages).

In addition, this change makes the `._jsii` submodule take care of
ensuring the current package's depencencies' assemblies are loaded up
before loading it's own module. This alleviated the need to
systematically import all dependencies from each sub-package, instead
only loading up the packages that are effectively used within a module.
@RomainMuller RomainMuller self-assigned this Apr 10, 2020
@mergify mergify bot added contribution/core This is a PR that came from AWS. labels Apr 10, 2020
@@ -1168,3 +1168,9 @@ def test_collection_of_interfaces_map_of_structs():
def test_collection_of_interfaces_map_of_interfaces():
for elt in InterfaceCollections.map_of_interfaces().values():
assert getattr(elt, "ring") is not None


@pytest.mark.skip # Currently broken because submodule names aren't case-adjusted correctly :(
Copy link
Contributor Author

@RomainMuller RomainMuller Apr 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pre-existing bug I'm merely shedding some light on. In order to fix this, I believe we'll need the kind of work in #1502 - specifically modeling the submodules information (including of dependencies) as part of the Assembly, so we can tell a PascalCased submodule name apart from a nested type's parent.

Technically, we are already loading some submodules (jsii_calc.composite for example), but those are of the "inline namespace" species that predated the submodules feature (as it was introduced in #1286), and it coincidentally avoids the buggy parts here...

@RomainMuller RomainMuller requested review from a team and removed request for MrArnoldPalmer April 10, 2020 14:39
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: 3a6fa30
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

eladb
eladb previously requested changes Apr 12, 2020
packages/jsii-pacmak/lib/targets/python/type-name.ts Outdated Show resolved Hide resolved
packages/jsii-pacmak/lib/targets/python/type-name.ts Outdated Show resolved Hide resolved
packages/jsii-pacmak/lib/targets/python/type-name.ts Outdated Show resolved Hide resolved
packages/jsii-pacmak/lib/targets/python/type-name.ts Outdated Show resolved Hide resolved
packages/jsii-pacmak/lib/targets/python/type-name.ts Outdated Show resolved Hide resolved
@RomainMuller RomainMuller requested a review from eladb April 14, 2020 14:50
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: 4a5d4c7
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: 78c012f
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: c53214e
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: f99aed4
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: d9e0b1c
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Restore unconditional import of datetime, enum, and typing. While they're not necessary all the time, unconditional import doesn't hurt much.
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: 7bcd976
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

RomainMuller added a commit that referenced this pull request Apr 17, 2020
Adds a `submodules` property on the `Assembly` structure, and carry it
forward in the `dependencyClosure`, so the information can later be used
to improve code generation for languages such as Python where the
submodule structure is modeled as first-class entity that needs to be
propertly dealt with. It can also help with properly adjusting the
submodule names so they look more "native" in target languages, without
facing problems when trying to generate type names in dependent packages.

The forwarding of dependent submodules is not exercized in the current
regression test suite because of a pair of other bugs (#1528, #1557)
that need to be addressed before the generated Python code can
successfully load. The last of those PRs to be merged will incldude the
necessary test coverage.
mergify bot pushed a commit that referenced this pull request Apr 20, 2020
Adds a `submodules` property on the `Assembly` structure, and carry it
forward in the `dependencyClosure`, so the information can later be used
to improve code generation for languages such as Python where the
submodule structure is modeled as first-class entity that needs to be
propertly dealt with. It can also help with properly adjusting the
submodule names so they look more "native" in target languages, without
facing problems when trying to generate type names in dependent packages.

The forwarding of dependent submodules is not exercized in the current
regression test suite because of a pair of other bugs (#1528, #1557)
that need to be addressed before the generated Python code can
successfully load. The last of those PRs to be merged will incldude the
necessary test coverage. This change is necessary for these PRs to
be able to fix their respective issues.
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: af3757f
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: 356ff42
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: 1d34a2d
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: ad6728e
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@RomainMuller RomainMuller added the language/python Related to Python bindings label May 12, 2020
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: 24e8747
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@RomainMuller RomainMuller dismissed eladb’s stale review May 12, 2020 11:40

As discussed, dismissing to allow another reviewer to have final word

@RomainMuller RomainMuller requested review from MrArnoldPalmer and removed request for eladb May 12, 2020 11:40
@mergify
Copy link
Contributor

mergify bot commented May 13, 2020

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label May 13, 2020
@mergify
Copy link
Contributor

mergify bot commented May 13, 2020

Merging (with squash)...

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-Blkkw9bQFn8A
  • Commit ID: e047b26
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 84e0f48 into master May 14, 2020
@mergify mergify bot deleted the rmuller/redo-python-name-resolver branch May 14, 2020 00:01
@mergify
Copy link
Contributor

mergify bot commented May 14, 2020

Merging (with squash)...

@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. language/python Related to Python bindings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants