fix: run the module when the docsgpt command is not on PATH

Refusing to write the service units when `docsgpt` is not on PATH was wrong. A
package installed in a virtualenv is runnable whether or not its console script
is on PATH, and CI runs pytest as `python -m pytest`, where argv[0] is a module
file: the refusal failed thirteen native tests there.

The launcher now prefers the command on PATH, resolved to an absolute path
since PATH can hold relative entries, then an argv[0] that can be executed, and
otherwise this interpreter with `-m docsgpt`, which works wherever the package
is importable. `python -m docsgpt` became an entrypoint of its own and has a
test that runs it.
This commit is contained in:
Alex committed 2026-09-16 22:45:54 +01:00
1 parent f9f52e99f0
commit a96734da07
5 files changed
+53 -20

No files matched your search

+10
View File
@@ -34,6 +34,16 @@ class TestTopLevel:
subprocess.run([sys.executable, "-c", code], cwd=Path(__file__).resolve().parents[1], check=True)
class TestModuleEntrypoint:
def test_python_m_docsgpt_runs_the_cli(self):
"""`python -m docsgpt` is what a native service falls back to when the script is not on PATH."""
result = subprocess.run(
[sys.executable, "-m", "docsgpt", "--version"],
cwd=Path(__file__).resolve().parents[1], capture_output=True, text=True, check=True,
)
assert result.stdout.strip() == f"docsgpt {__version__}"
class TestHome:
@staticmethod
def _installed(monkeypatch, tmp_path):