Skip to content

Add the pkgutil style init file to datadog_checks_dev for support on IDEs language server #20483

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AAraKKe
Copy link
Contributor

@AAraKKe AAraKKe commented Jun 11, 2025

What does this PR do?

This PR bring sback the pkgutil style __init__.py file to datadog_checks_dev that was removed previously in #19826.

Motivation

Language servers like Pylance (used in VS Code) are currently unable to resolve imports from the datadog_checks.dev package. This leads to incorrect import errors within the IDE, which breaks features like autocompletion and "Go to Definition" for test fixtures. This change aims to fix this issue to improve the developer experience.

This problem occurs because of an inconsistency in how the datadog_checks namespace package is defined:

  • The datadog-checks-base package uses a legacy pkgutil-style namespace (which requires an __init__.py file).
  • The datadog-checks-dev package uses a modern implicit namespace (which omits the __init__.py file).

Static analysis tools see the pkgutil-style __init__.py from the base package and correctly assume the entire datadog_checks namespace must follow that pattern. As a result, they do not discover the dev package, which uses the conflicting implicit method.

At runtime, this works because the code in the pkgutil __init__.py file dynamically extends the package path to include the dev directory. However, this runtime behavior cannot be inferred by static analysis, leading to the errors in the IDE.

From the Native Namespace docs:

It is extremely important that every distribution that uses the namespace package omits the init.py or uses a pkgutil-style init.py. If any distribution does not, it will cause the namespace logic to fail and the other sub-packages will not be importable.

EDIT: After talking with @ofek and @iliakur we decided to go ahead and get rid of the need of using the old pkgutil by removing it from datadog-checks-base. We have been documenting the proper imports for years already and decided it was time to get rid of it.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add the qa/skip-qa label if the PR doesn't need to be tested during QA.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

@AAraKKe AAraKKe added the qa/skip-qa Automatically skip this PR for the next QA label Jun 11, 2025
@AAraKKe AAraKKe marked this pull request as ready for review June 11, 2025 13:56
@AAraKKe AAraKKe requested a review from a team as a code owner June 11, 2025 13:56
Copy link

codecov bot commented Jun 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.92%. Comparing base (382ead7) to head (5246020).
Report is 2 commits behind head on master.

Additional details and impacted files
Flag Coverage Δ
activemq ?
ambari 85.75% <ø> (ø)
azure_iot_edge 82.08% <ø> (ø)
btrfs 83.33% <ø> (ø)
cassandra ?
cisco_aci 89.43% <ø> (ø)
cloud_foundry_api 96.11% <ø> (ø)
confluent_platform ?
dcgm 93.54% <ø> (ø)
dns_check 93.84% <ø> (ø)
eks_fargate 94.05% <ø> (ø)
hive ?
hivemq ?
hudi ?
ignite ?
infiniband 92.34% <ø> (ø)
jboss_wildfly ?
kafka ?
kube_controller_manager 97.88% <ø> (ø)
kube_dns 95.94% <ø> (ø)
kubelet 91.09% <ø> (ø)
kubernetes_state 89.49% <ø> (ø)
litellm 95.65% <ø> (ø)
mac_audit_logs 80.79% <ø> (ø)
network 80.86% <ø> (-13.04%) ⬇️
nvidia_nim 93.10% <ø> (ø)
presto ?
riakcs 88.82% <ø> (ø)
slurm 90.86% <ø> (ø)
solr ?
tcp_check 90.72% <ø> (-1.33%) ⬇️
tibco_ems 91.98% <ø> (ø)
tomcat ?
traffic_server 96.13% <ø> (ø)
weblogic ?

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AAraKKe AAraKKe force-pushed the aarakke/fix-dcd-namespace-for-language-server branch from 7e17300 to 20d8510 Compare June 16, 2025 14:53
@AAraKKe
Copy link
Contributor Author

AAraKKe commented Jun 16, 2025

Many of the checks are breaking because they are using relative imports. I know we were working on removing them in #20467 after having move ddev lint and formatter to ruff (in #20451).

I will mark this PR draft until that is finished or it will take a long time to actually get everything refactored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment