ethanolivertroy_obsidian-ma.../python/check_install.py
Ethan Troy d6fa068498
Rewrite plugin v2: fix shell injection, modularize, add features (ENG-533)
## Summary
- **Security**: Replaced shell injection-vulnerable `exec()` calls with `spawn()` using argument arrays and `shell: false`, bundling Python wrapper scripts that use `argparse`
- **Architecture**: Decomposed monolithic 735-line `main.ts` into 12 focused modules across `src/` and `python/`
- **Features**: Added image extraction from PDFs, plugin arguments editor, context menu conversion, batch progress indicators, setup wizard, and Unicode support via `PYTHONUTF8=1`
- **Compatibility**: Reverted minAppVersion to 0.15.0, python3 fallback for macOS/Linux

Closes ENG-533
2026-02-17 01:08:20 -05:00

63 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""Check Python environment and installed packages.
Usage:
python check_install.py --check markitdown
python check_install.py --check all
Output (JSON to stdout):
{"python_version": "3.11.5", "packages": {"markitdown": {"installed": true, "version": "0.1.3"}}}
"""
import argparse
import json
import sys
def check_package(name: str) -> dict:
"""Check if a Python package is installed and return its version."""
try:
from importlib.metadata import version, PackageNotFoundError
try:
ver = version(name)
return {"installed": True, "version": ver}
except PackageNotFoundError:
return {"installed": False, "version": None}
except ImportError:
# Python < 3.8 fallback
try:
import pkg_resources
ver = pkg_resources.get_distribution(name).version
return {"installed": True, "version": ver}
except Exception:
return {"installed": False, "version": None}
def main():
parser = argparse.ArgumentParser(description="Check Python package installations")
parser.add_argument(
"--check",
required=True,
help="Package to check: 'markitdown' or 'all'",
)
args = parser.parse_args()
packages_to_check = []
if args.check == "all":
packages_to_check = ["markitdown"]
else:
packages_to_check = [args.check]
result = {
"python_version": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
"packages": {},
}
for pkg in packages_to_check:
result["packages"][pkg] = check_package(pkg)
print(json.dumps(result))
if __name__ == "__main__":
main()