fix: make python -m tabcmd work reliably (#375)#411
Open
jacalata wants to merge 3 commits into
Open
Conversation
… unconditionally Removes the redundant `if __name__ == "__main__":` guard — Python only executes __main__.py when running as a module, so the guard was misleading and left a NameError trap if the ImportError path was hit. Adds subprocess-based tests for the `python -m tabcmd` entry point. Closes #375 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…__main__.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…r test - except Exception catches SyntaxError/OSError from broken installs, not just ImportError - e.__context__ only printed when present (was always None for top-level imports) - pip install suggestion now recommends --force-reinstall (tabcmd is already on sys.path) - test_import_error_exits_one: use sys.modules injection instead of CWD/path ordering - success tests: pass PYTHONPATH to ensure tabcmd is importable in subprocess Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
if __name__ == "__main__":guard (removed guard would callsys.exit()on anyimport tabcmd.__main__)sys.exit(1)in the import-failure handler so the process exits non-zero instead of crashing onmain()being undefinedexcept ImportErrortoexcept Exception— broken installs can also raiseSyntaxError,OSError(missing.mofiles),AttributeErrore.__context__conditional (was always printingNonefor top-level import failures)--force-reinstall(tabcmd is already onsys.pathwhen this fires)stderrtests/test_main.pywith subprocess-based tests; import-error test usessys.modulesinjection instead of fragile CWD/path ordering; success tests passPYTHONPATHexplicitlyTest plan
python -m pytest tests/test_main.py -v— 4 tests passpython -m pytest tests/ --ignore=tests/e2e— full suite passespython -m tabcmdexits 0python -m tabcmd --helpexits 0 and prints usage🤖 Generated with Claude Code