|
5 | 5 | from codecs import open |
6 | 6 | import os |
7 | 7 | import shutil |
| 8 | +import subprocess |
| 9 | +import sys |
8 | 10 | from setuptools import setup, find_packages |
| 11 | +from setuptools.command.install import install |
| 12 | + |
| 13 | + |
| 14 | +class PostInstallCommand(install): |
| 15 | + """Post-installation for installation mode.""" |
| 16 | + def run(self): |
| 17 | + install.run(self) |
| 18 | + |
| 19 | + # Skip auto-install if explicitly disabled |
| 20 | + if os.environ.get('FOSSLIGHT_SKIP_AUTO_INSTALL', '').lower() in ('1', 'true', 'yes'): |
| 21 | + print("Auto-install disabled by environment variable") |
| 22 | + return |
| 23 | + |
| 24 | + # Install syft and grype using standalone installer |
| 25 | + try: |
| 26 | + print("Installing syft and grype...") |
| 27 | + # Use standalone installer script - no package dependencies! |
| 28 | + script_path = os.path.join(os.path.dirname(__file__), 'install_tools.py') |
| 29 | + if os.path.exists(script_path): |
| 30 | + result = subprocess.run([sys.executable, script_path], |
| 31 | + capture_output=True, text=True) |
| 32 | + if result.returncode == 0: |
| 33 | + print("Syft and grype installation completed.") |
| 34 | + else: |
| 35 | + print(f"Warning: Tool installation failed: {result.stderr}") |
| 36 | + else: |
| 37 | + print("Warning: install_tools.py not found, skipping auto-install") |
| 38 | + except Exception as e: |
| 39 | + print(f"Warning: Failed to auto-install syft/grype: {e}") |
| 40 | + print("You can install them manually or they will be installed on first use.") |
| 41 | + |
9 | 42 |
|
10 | 43 | with open('README.md', 'r', 'utf-8') as f: |
11 | 44 | readme = f.read() |
|
63 | 96 | }, |
64 | 97 | package_data={_PACKAEG_NAME: [os.path.join(_LICENSE_DIR, '*')]}, |
65 | 98 | include_package_data=True, |
| 99 | + # Include install_tools.py in the package |
| 100 | + data_files=[ |
| 101 | + ('', ['install_tools.py']), |
| 102 | + ], |
| 103 | + cmdclass={ |
| 104 | + 'install': PostInstallCommand, |
| 105 | + }, |
66 | 106 | entry_points={ |
67 | 107 | "console_scripts": [ |
68 | 108 | "binary_analysis = fosslight_binary.cli:main", |
69 | 109 | "fosslight_bin = fosslight_binary.cli:main", |
70 | 110 | "fosslight_binary = fosslight_binary.cli:main", |
| 111 | + "fosslight_install_tools = fosslight_binary.install_cli:main", |
71 | 112 | ] |
72 | 113 | } |
73 | 114 | ) |
|
0 commit comments