Skip to main content

Detect conflicting directory names across Python's sys.path that shadow installed packages

Project description

detect-shadowed-modules

Detect conflicting directory names across Python's sys.path that may be shadowing your installed packages.

Problem

When Python imports a module, it searches directories in sys.path order. If the same directory name exists in multiple sys.path entries, only the first one is used—potentially shadowing packages you intended to import. This can lead to confusing import errors and unexpected behavior.

Example Conflict Scenario

sys.path = ['/project', '/usr/lib/python3/site-packages']

If both paths contain a requests/ directory:

  • /project/requests/ ← This shadows the real package
  • /usr/lib/python3/site-packages/requests/

When you import requests, Python will use /project/requests/ instead of the installed package, which is likely not what you want!

Installation

uv add detect-shadowed-modules

Or, you can just use via uvx:

uvx detect-shadowed-modules@latest --help

Usage

Command Line

# Print conflicts to stdout with scanning progress
detect-shadowed-modules

# Quiet mode (conflicts only, no progress messages)
detect-shadowed-modules -q

# Output as JSON
detect-shadowed-modules --json

As a Python Module

import detect_shadowed_modules

# Find conflicts
conflicts = detect_shadowed_modules.find_conflicts()

# Generate a human-readable report
report = detect_shadowed_modules.format_report(conflicts)
print(report)

# Or get JSON output
json_output = detect_shadowed_modules.format_json(conflicts)
print(json_output)

Output Examples

Human-Readable Format

Conflicting directory names detected:

These directories exist in multiple sys.path locations. The first
location listed will shadow the others during import.

  requests/
  → /home/user/myproject/requests (shadows others)
    /usr/lib/python3/site-packages/requests [requests] (shadowed)

JSON Format

{
  "shadowed": [
    {
      "path": "/usr/lib/python3/site-packages/requests",
      "shadowed_by": "/home/user/myproject/requests",
      "owner": "requests"
    }
  ]
}

How It Works

The tool scans all directories in sys.path and:

  1. Identifies subdirectories in each path
  2. Detects when the same directory name appears in multiple locations
  3. Reports which packages are being shadowed and by what
  4. Attempts to identify the installed package that owns each directory

Excluded from scanning:

  • Hidden directories (starting with .)
  • __pycache__ directories
  • Package metadata directories (.dist-info, .egg-info)

Exit Codes

  • 0: No conflicts found
  • 1: Conflicts detected

This makes it easy to use in CI/CD pipelines or pre-commit hooks.

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

detect_shadowed_modules-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

detect_shadowed_modules-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file detect_shadowed_modules-0.1.0.tar.gz.

File metadata

  • Download URL: detect_shadowed_modules-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for detect_shadowed_modules-0.1.0.tar.gz
Algorithm Hash digest
SHA256 967490ae656f654426632253a7afb616c20362d5057295156fe84eea932b819b
MD5 28977b0bc7889f56acfcde81c831fefa
BLAKE2b-256 cee97b7502443aecadfeef870657b6dc0626e123abf8f55327e41b8c7fb28615

See more details on using hashes here.

File details

Details for the file detect_shadowed_modules-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: detect_shadowed_modules-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for detect_shadowed_modules-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed6c3001ef8881ffbb7d49cadcade488b07feb09959409ee63147bfff068bfb0
MD5 ccb47dbce8b1f2af631746b246557c3b
BLAKE2b-256 2cb1c99d45b7ebb372ec46a0e2592f58216e089eefcf8529ae9bdcaf8f2562f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page