**Replace main.py with module-based entry point and unify CLI execution**
Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled

* Remove legacy *main.py* and introduce *pkgmgr* module entry via *python -m pkgmgr*
* Add ***main**.py* as the canonical entry point delegating to the CLI
* Export *PYTHONPATH=src* in Makefile to ensure reliable imports in dev and CI
* Update setup scripts (venv & nix) to use module execution
* Refactor all E2E tests to execute the real module entry instead of file paths

This aligns pkgmgr with standard Python packaging practices and simplifies testing, setup, and execution across environments.

https://chatgpt.com/share/693c9056-716c-800f-b583-fc9245eab2b4
This commit is contained in:
Kevin Veen-Birkenbach
2025-12-12 22:59:46 +01:00
parent b40787ffc5
commit f5d428950e
20 changed files with 28 additions and 47 deletions

View File

@@ -27,7 +27,7 @@ class TestIntegrationBranchCommands(unittest.TestCase):
try:
# argv[0] is the program name; the rest are CLI arguments.
sys.argv = ["pkgmgr"] + list(extra_args)
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
finally:
sys.argv = original_argv

View File

@@ -24,7 +24,7 @@ def _run_pkgmgr_help(argv_tail: list[str]) -> str:
try:
with redirect_stdout(buffer), redirect_stderr(buffer):
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
except SystemExit as exc:
code = exc.code if isinstance(exc.code, int) else None
if code not in (0, None):

View File

@@ -53,7 +53,7 @@ class TestIntegrationChangelogCommands(unittest.TestCase):
sys.argv = ["pkgmgr", "changelog"] + list(extra_args)
try:
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
except SystemExit as exc:
code = exc.code if isinstance(exc.code, int) else str(exc.code)
if code != 0:

View File

@@ -47,7 +47,7 @@ class TestIntegrationCloneAllHttps(unittest.TestCase):
try:
# Execute main.py as if it was called from CLI.
# This will run the full clone pipeline inside the container.
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
except SystemExit as exc:
# Determine the exit code (int or string)
exit_code = exc.code

View File

@@ -34,7 +34,7 @@ def _run_pkgmgr_config(extra_args: list[str]) -> None:
sys.argv = ["pkgmgr"] + extra_args
try:
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
except SystemExit as exc:
code = exc.code if isinstance(exc.code, int) else str(exc.code)
if code != 0:

View File

@@ -139,7 +139,7 @@ class TestIntegrationInstalPKGMGRShallow(unittest.TestCase):
]
# Execute installation via main.py
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
# Debug: interactive shell test
pkgmgr_help_debug()

View File

@@ -27,7 +27,7 @@ class TestIntegrationListCommands(unittest.TestCase):
sys.argv = ["pkgmgr"] + args
try:
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
except SystemExit as exc:
code = exc.code if isinstance(exc.code, int) else str(exc.code)
if code != 0:

View File

@@ -44,7 +44,7 @@ class TestIntegrationMakeCommands(unittest.TestCase):
sys.argv = ["pkgmgr"] + extra_args
try:
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
except SystemExit as exc:
code = exc.code if isinstance(exc.code, int) else str(exc.code)
if code != 0:

View File

@@ -50,7 +50,7 @@ class TestIntegrationMirrorCommands(unittest.TestCase):
try:
with redirect_stdout(buffer), redirect_stderr(buffer):
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
except SystemExit as exc:
code = exc.code if isinstance(exc.code, int) else None
if code not in (0, None):

View File

@@ -50,7 +50,7 @@ class TestPathCommandsE2E(unittest.TestCase):
try:
# Capture stdout while running the CLI entry point.
with redirect_stdout(buffer):
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
except SystemExit as exc:
# Determine the exit code (int or string)
exit_code = exc.code

View File

@@ -27,7 +27,7 @@ class TestIntegrationProxyCommands(unittest.TestCase):
sys.argv = ["pkgmgr"] + args
try:
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
except SystemExit as exc:
code = exc.code if isinstance(exc.code, int) else str(exc.code)
if code != 0:

View File

@@ -44,7 +44,7 @@ class TestIntegrationReleaseCommand(unittest.TestCase):
try:
# argv[0] is the program name; the rest are CLI arguments.
sys.argv = ["pkgmgr"] + list(extra_args)
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
finally:
sys.argv = original_argv
@@ -152,7 +152,7 @@ class TestIntegrationReleaseCommand(unittest.TestCase):
# argparse will call sys.exit(), so we expect a SystemExit here.
with contextlib.redirect_stdout(buf), contextlib.redirect_stderr(buf):
with self.assertRaises(SystemExit) as cm:
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
finally:
sys.argv = original_argv

View File

@@ -55,7 +55,7 @@ class TestIntegrationToolsCommands(unittest.TestCase):
sys.argv = ["pkgmgr"] + extra_args
try:
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
except SystemExit as exc:
code = exc.code if isinstance(exc.code, int) else str(exc.code)
if code != 0:

View File

@@ -18,14 +18,6 @@ import sys
import unittest
from typing import List
# Resolve project root (the repo where main.py lives, e.g. /src)
PROJECT_ROOT = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "..")
)
MAIN_PATH = os.path.join(PROJECT_ROOT, "main.py")
def _run_main(argv: List[str]) -> None:
"""
Helper to run main.py with the given argv.
@@ -40,7 +32,7 @@ def _run_main(argv: List[str]) -> None:
try:
sys.argv = ["pkgmgr"] + argv
try:
runpy.run_path(MAIN_PATH, run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
except SystemExit as exc: # argparse uses this for --help
# SystemExit.code can be int, str or None; for our purposes:
code = exc.code

View File

@@ -130,7 +130,7 @@ class TestIntegrationVersionCommands(unittest.TestCase):
sys.argv = ["pkgmgr", "version"] + extra_args
try:
runpy.run_module("main", run_name="__main__")
runpy.run_module("pkgmgr", run_name="__main__")
except SystemExit as exc:
code = exc.code if isinstance(exc.code, int) else str(exc.code)
if code != 0: