Skip to content

fix: make python -m tabcmd work reliably (#375)#411

Open
jacalata wants to merge 3 commits into
developmentfrom
jac/fix-375-python-m-tabcmd
Open

fix: make python -m tabcmd work reliably (#375)#411
jacalata wants to merge 3 commits into
developmentfrom
jac/fix-375-python-m-tabcmd

Conversation

@jacalata

@jacalata jacalata commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes Add tabcmd/__main__.py so python -m tabcmd works reliably for installed users #375
  • Restores if __name__ == "__main__": guard (removed guard would call sys.exit() on any import tabcmd.__main__)
  • Adds sys.exit(1) in the import-failure handler so the process exits non-zero instead of crashing on main() being undefined
  • Broadens except ImportError to except Exception — broken installs can also raise SyntaxError, OSError (missing .mo files), AttributeError
  • Makes e.__context__ conditional (was always printing None for top-level import failures)
  • Improves error message to suggest --force-reinstall (tabcmd is already on sys.path when this fires)
  • Routes all diagnostic prints in the frozen-bundle path to stderr
  • Adds tests/test_main.py with subprocess-based tests; import-error test uses sys.modules injection instead of fragile CWD/path ordering; success tests pass PYTHONPATH explicitly

Test plan

  • python -m pytest tests/test_main.py -v — 4 tests pass
  • python -m pytest tests/ --ignore=tests/e2e — full suite passes
  • python -m tabcmd exits 0
  • python -m tabcmd --help exits 0 and prints usage
  • Broken install path: exits 1 with "Exception thrown importing tabcmd" on stderr

🤖 Generated with Claude Code

jacalata and others added 3 commits July 1, 2026 18:17
… 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>
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Coverage

Coverage Report
FileStmtsMissCoverMissing
tabcmd
   __main__.py121212 0%
   tabcmd.py151515 0%
   version.py622 67%
tabcmd/commands
   commands.py101010 0%
   constants.py771818 77%
   server.py1351818 87%
tabcmd/commands/auth
   session.py3814646 88%
tabcmd/commands/datasources_and_workbooks
   datasources_and_workbooks_command.py1571818 89%
   datasources_workbooks_views_url_parser.py14255 96%
   delete_command.py601616 73%
   export_command.py1202525 79%
   get_url_command.py1274747 63%
   publish_command.py1232828 77%
   runschedule_command.py2177 67%
tabcmd/commands/extracts
   create_extracts_command.py4288 81%
   decrypt_extracts_command.py2722 93%
   delete_extracts_command.py3766 84%
   encrypt_extracts_command.py2722 93%
   extracts.py2022 90%
   reencrypt_extracts_command.py2722 93%
   refresh_extracts_command.py481010 79%
tabcmd/commands/group
   create_group_command.py2955 83%
   delete_group_command.py2722 93%
tabcmd/commands/project
   create_project_command.py4688 83%
   delete_project_command.py3544 89%
   publish_samples_command.py3044 87%
tabcmd/commands/site
   create_site_command.py3455 85%
   delete_site_command.py2722 93%
   edit_site_command.py3822 95%
   list_command.py771212 84%
   list_sites_command.py2922 93%
tabcmd/commands/user
   add_users_command.py2955 83%
   create_site_users.py581111 81%
   create_users_command.py601010 83%
   delete_site_users_command.py4355 88%
   user_data.py2213131 86%
tabcmd/execution
   _version.py222 0%
   global_options.py12588 94%
   localize.py661111 83%
   logger_config.py5166 88%
   tabcmd_controller.py4277 83%
TOTAL283744184% 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant