Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
44 changes: 44 additions & 0 deletions scripts/check-for-namespace-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail

# TODO: Can we also check tests/? some folders in there require missing __init__.py
ROOTS=("ddtrace")
FAIL=0

echo "Checking for accidental namespace packages..."

for ROOT in "${ROOTS[@]}"; do
echo "Scanning '$ROOT'..."

# Only check roots that actually exist (CI safety)
if [[ ! -d "$ROOT" ]]; then
echo " (skipped: directory does not exist)"
continue
fi

# Walk all directories under the root
while IFS= read -r dir; do
# Skip __pycache__
[[ "$dir" == *"__pycache__"* ]] && continue

# Directory contains Python or Cython files?
if compgen -G "$dir/*.py" >/dev/null || compgen -G "$dir/*.pyx" >/dev/null; then

# And it must contain __init__.py
if [[ ! -f "$dir/__init__.py" ]]; then
echo "❌ Missing __init__.py in: $dir"
FAIL=1
fi
fi

done < <(find "$ROOT" -type d)
done

if [[ "$FAIL" -eq 1 ]]; then
echo
echo "❌ ERROR: Missing __init__.py detected in source or test packages."
echo " Please add empty __init__.py files to the directories listed above."
exit 1
else
echo "✅ All Python package directories contain __init__.py"
fi
5 changes: 5 additions & 0 deletions scripts/gen_gitlab_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ def check(name: str, command: str, paths: t.Set[str]) -> None:
command="scripts/check-dependency-bounds",
paths={"pyproject.toml"},
)
check(
name="Check for namespace packages",
command="scripts/check-for-namespace-packages.sh",
paths={"*"},
)
if not checks:
return

Expand Down
Loading