Skip to content

Commit 2aa4fce

Browse files
committed
Fix .jar analysis via Syft & Grype
1 parent 10b0aec commit 2aa4fce

File tree

6 files changed

+481
-228
lines changed

6 files changed

+481
-228
lines changed

.reuse/dep5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ License: Apache-2.0
5757
Files: .bumpversion.cfg
5858
Copyright: 2021 LG Electronics
5959
License: Apache-2.0
60+
61+
Files: src/fosslight_binary/__init__.py
62+
Copyright:
63+
License: Apache-2.0

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ pytz
99
XlsxWriter
1010
PyYAML
1111
fosslight_util>=2.1.13
12-
dependency-check

setup.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66
import os
77
import shutil
88
from setuptools import setup, find_packages
9+
from setuptools.command.install import install
10+
11+
class PostInstallCommand(install):
12+
"""Post-installation for installation mode."""
13+
def run(self):
14+
install.run(self)
15+
# Install syft and grype after package installation
16+
try:
17+
from src.fosslight_binary._jar_analysis import ensure_syft_grype
18+
print("Installing syft and grype...")
19+
ensure_syft_grype()
20+
print("Syft and grype installation completed.")
21+
except Exception as e:
22+
print(f"Warning: Failed to auto-install syft/grype: {e}")
23+
print("You can install them manually or they will be installed on first use.")
924

1025
with open('README.md', 'r', 'utf-8') as f:
1126
readme = f.read()
@@ -63,6 +78,9 @@
6378
},
6479
package_data={_PACKAEG_NAME: [os.path.join(_LICENSE_DIR, '*')]},
6580
include_package_data=True,
81+
cmdclass={
82+
'install': PostInstallCommand,
83+
},
6684
entry_points={
6785
"console_scripts": [
6886
"binary_analysis = fosslight_binary.cli:main",

src/fosslight_binary/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Auto-install syft and grype on first import
2+
import logging
3+
import os
4+
5+
logger = logging.getLogger(__name__)
6+
7+
def _auto_install_dependencies():
8+
"""Auto-install syft and grype if not available"""
9+
try:
10+
from ._jar_analysis import ensure_syft_grype
11+
# Only try to install if we're not in a restricted environment
12+
if not os.environ.get('FOSSLIGHT_SKIP_AUTO_INSTALL'):
13+
ensure_syft_grype()
14+
except Exception as ex:
15+
# Don't fail package import if auto-install fails
16+
logger.debug(f"Auto-install failed (this is not critical): {ex}")
17+
18+
# Run auto-install on import
19+
_auto_install_dependencies()

0 commit comments

Comments
 (0)