Skip to content

Commit 76132f0

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

File tree

5 files changed

+511
-226
lines changed

5 files changed

+511
-226
lines changed

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

1028
with open('README.md', 'r', 'utf-8') as f:
1129
readme = f.read()
@@ -63,6 +81,9 @@
6381
},
6482
package_data={_PACKAEG_NAME: [os.path.join(_LICENSE_DIR, '*')]},
6583
include_package_data=True,
84+
cmdclass={
85+
'install': PostInstallCommand,
86+
},
6687
entry_points={
6788
"console_scripts": [
6889
"binary_analysis = fosslight_binary.cli:main",

src/fosslight_binary/__init__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2025 LG Electronics Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# Auto-install syft and grype on first import
7+
import logging
8+
import os
9+
10+
logger = logging.getLogger(__name__)
11+
12+
13+
def _auto_install_dependencies():
14+
"""Auto-install syft and grype if not available"""
15+
try:
16+
# Only try to install if we're not in a restricted environment
17+
if not os.environ.get('FOSSLIGHT_SKIP_AUTO_INSTALL'):
18+
# Use lazy import to avoid circular dependency during package installation
19+
from ._jar_analysis import ensure_syft_grype
20+
ensure_syft_grype()
21+
except Exception as ex:
22+
# Don't fail package import if auto-install fails
23+
logger.debug(f"Auto-install failed (this is not critical): {ex}")
24+
25+
26+
# Run auto-install on import
27+
_auto_install_dependencies()

0 commit comments

Comments
 (0)