Skip to content

Conversation

@kanterov
Copy link
Collaborator

Changes

Add tests for recursive imports.

Right now, we have carefully crafted all imports so it isn't a problem. We need tests to avoid regressions. For example, previously, we had a problem with importing from databricks.bundles.jobs before databricks.bundles.core resulted in errors. And introducing such regression in the code doesn't break any existing tests.

Tests

Unit test

@kanterov kanterov temporarily deployed to test-trigger-is March 20, 2025 10:50 — with GitHub Actions Inactive
@kanterov kanterov marked this pull request as ready for review March 20, 2025 10:50
@kanterov kanterov temporarily deployed to test-trigger-is March 20, 2025 10:50 — with GitHub Actions Inactive
Naive implementation can have depenency due to typing. To break it we should be
using TYPE_CHECKING imports. Otherwise, there is a cycle between
databricks.bundles.core.Resource and databricks.bundles.jobs.Job
(or other resources).
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't fully understand this paragraph, can you rephrase?

original_modules = sys.modules.copy()

for module in original_modules.keys():
if module.startswith("databricks.bundles"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as below (can be a constant).

Suggested change
if module.startswith("databricks.bundles"):
if module.startswith("databricks.bundles."):

@kanterov kanterov force-pushed the python-avoid-recursive-imports branch from e196ef9 to 9b491b9 Compare March 24, 2025 13:30
@kanterov kanterov temporarily deployed to test-trigger-is March 24, 2025 13:30 — with GitHub Actions Inactive
@kanterov kanterov temporarily deployed to test-trigger-is March 24, 2025 13:58 — with GitHub Actions Inactive
@kanterov kanterov temporarily deployed to test-trigger-is March 24, 2025 14:02 — with GitHub Actions Inactive
@kanterov kanterov temporarily deployed to test-trigger-is March 24, 2025 14:05 — with GitHub Actions Inactive
@kanterov kanterov temporarily deployed to test-trigger-is March 24, 2025 15:00 — with GitHub Actions Inactive
@kanterov kanterov temporarily deployed to test-trigger-is March 25, 2025 07:32 — with GitHub Actions Inactive
"pytest-cov==5.0.0",
"pytest==8.3.3",
"ruff==0.6.8",
"ruff==0.9.1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's necessary because otherwise ruff in GH actions doesn't agree with ruff in experimental/python

Copy link
Contributor

Choose a reason for hiding this comment

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

(ideally this is a separate PR)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍, fixed in #2566

@kanterov kanterov requested a review from pietern March 25, 2025 08:29
@kanterov
Copy link
Collaborator Author

@pietern, thanks for the suggestions. I've refactored the code and comments to make it more straightforward.

"pytest-cov==5.0.0",
"pytest==8.3.3",
"ruff==0.6.8",
"ruff==0.9.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

(ideally this is a separate PR)

@kanterov kanterov force-pushed the python-avoid-recursive-imports branch from aac98a4 to 70b3edd Compare March 27, 2025 15:57
@kanterov kanterov temporarily deployed to test-trigger-is March 27, 2025 15:57 — with GitHub Actions Inactive
@kanterov kanterov temporarily deployed to test-trigger-is March 27, 2025 15:59 — with GitHub Actions Inactive
@kanterov kanterov added this pull request to the merge queue Mar 27, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 27, 2025
@kanterov kanterov temporarily deployed to test-trigger-is March 27, 2025 18:51 — with GitHub Actions Inactive
@kanterov kanterov enabled auto-merge March 27, 2025 18:51
@kanterov kanterov added this pull request to the merge queue Mar 27, 2025
Merged via the queue into main with commit babcd94 Mar 27, 2025
15 checks passed
@kanterov kanterov deleted the python-avoid-recursive-imports branch March 27, 2025 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants