Skip to content

Commit 9a866fa

Browse files
author
DevForge Engineer
committed
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
1 parent 0d46049 commit 9a866fa

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/deadcode/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Allow running deadcode as: python -m deadcode"""
2-
from deadcode.cli import main
2+
from deadcode.cli import cli
33

44
if __name__ == "__main__":
5-
main()
5+
cli()

tests/test_scanner.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77
from deadcode.cli import cli
88
from deadcode.scanner import DeadCodeScanner
9+
from pathlib import Path
910

1011

1112
@pytest.fixture
@@ -292,3 +293,18 @@ def test_stats_command(self, runner, sample_project):
292293
assert result.exit_code == 0
293294
assert "Files scanned" in result.output
294295
assert "Unused exports" in result.output
296+
297+
def test_main_module_entry_point(self, runner):
298+
"""Test that python -m deadcode works (__main__ entry point fix)."""
299+
import subprocess
300+
import sys
301+
result = subprocess.run(
302+
[sys.executable, "-m", "deadcode", "--help"],
303+
capture_output=True, text=True,
304+
cwd=str(Path(__file__).parent.parent / "src"),
305+
)
306+
assert result.returncode == 0
307+
assert "DeadCode" in result.stdout
308+
assert "scan" in result.stdout
309+
assert "remove" in result.stdout
310+
assert "stats" in result.stdout

0 commit comments

Comments
 (0)