From 9a866fac9533bd6126b78bb476a8a26fee954f17 Mon Sep 17 00:00:00 2001 From: DevForge Engineer Date: Mon, 18 May 2026 15:43:15 -0400 Subject: [PATCH] fix: correct __main__.py entry point to import cli instead of nonexistent main The __main__.py module was importing main from deadcode.cli but the CLI group function is named cli. This caused python -m deadcode to fail with ImportError. - Fix import in __main__.py to reference cli instead of main - Add regression test verifying python -m deadcode --help works - Fix import ordering (ruff I001) in test_scanner.py --- src/deadcode/__main__.py | 4 ++-- tests/test_scanner.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/deadcode/__main__.py b/src/deadcode/__main__.py index 152c7ce..9041762 100644 --- a/src/deadcode/__main__.py +++ b/src/deadcode/__main__.py @@ -1,5 +1,5 @@ """Allow running deadcode as: python -m deadcode""" -from deadcode.cli import main +from deadcode.cli import cli if __name__ == "__main__": - main() + cli() diff --git a/tests/test_scanner.py b/tests/test_scanner.py index fc3afd1..55481cb 100644 --- a/tests/test_scanner.py +++ b/tests/test_scanner.py @@ -6,6 +6,7 @@ import pytest from deadcode.cli import cli from deadcode.scanner import DeadCodeScanner +from pathlib import Path @pytest.fixture @@ -292,3 +293,18 @@ def test_stats_command(self, runner, sample_project): assert result.exit_code == 0 assert "Files scanned" in result.output assert "Unused exports" in result.output + + def test_main_module_entry_point(self, runner): + """Test that python -m deadcode works (__main__ entry point fix).""" + import subprocess + import sys + result = subprocess.run( + [sys.executable, "-m", "deadcode", "--help"], + capture_output=True, text=True, + cwd=str(Path(__file__).parent.parent / "src"), + ) + assert result.returncode == 0 + assert "DeadCode" in result.stdout + assert "scan" in result.stdout + assert "remove" in result.stdout + assert "stats" in result.stdout