1515from fetchcode .package_versions import SUPPORTED_ECOSYSTEMS as FETCHCODE_SUPPORTED_ECOSYSTEMS
1616from fetchcode .package_versions import versions
1717from packageurl import PackageURL
18- from univers .version_range import RANGE_CLASS_BY_SCHEMES
1918
2019from vulnerabilities .models import Package
2120from vulnerabilities .pipelines import VulnerableCodePipeline
@@ -55,7 +54,7 @@ def detect_and_flag_ghost_packages(logger=None):
5554 ghost_package_count = 0
5655 progress = LoopProgress (total_iterations = distinct_packages_count , logger = logger )
5756 for type_namespace_name , packages in progress .iter (grouped_packages ):
58- ghost_package_count += flag_ghost_package (
57+ ghost_package_count += flag_ghost_packages (
5958 base_purl = PackageURL (* type_namespace_name ),
6059 packages = packages ,
6160 logger = logger ,
@@ -65,25 +64,21 @@ def detect_and_flag_ghost_packages(logger=None):
6564 logger (f"Successfully flagged { ghost_package_count :,d} ghost Packages" )
6665
6766
68- def flag_ghost_package (base_purl , packages , logger = None ):
67+ def flag_ghost_packages (base_purl , packages , logger = None ):
6968 """
7069 Check if `packages` are available upstream.
7170 If not, update `is_ghost` to `True`.
7271 Return the number of packages flagged as ghost.
7372 """
74- if not base_purl .type in RANGE_CLASS_BY_SCHEMES :
75- return 0
76-
7773 known_versions = get_versions (purl = base_purl , logger = logger )
7874 # Skip if encounter error while fetching known versions
7975 if known_versions is None :
8076 return 0
8177
8278 ghost_packages = 0
83- version_class = RANGE_CLASS_BY_SCHEMES [base_purl .type ].version_class
8479 for pkg in packages :
8580 pkg .is_ghost = False
86- if version_class ( pkg .version ) not in known_versions :
81+ if pkg .version . lstrip ( "vV" ) not in known_versions :
8782 pkg .is_ghost = True
8883 ghost_packages += 1
8984
@@ -96,10 +91,8 @@ def flag_ghost_package(base_purl, packages, logger=None):
9691
9792def get_versions (purl , logger = None ):
9893 """Return set of known versions for the given purl."""
99- version_class = RANGE_CLASS_BY_SCHEMES [purl .type ].version_class
100-
10194 try :
102- return {version_class ( v .value ) for v in versions (str (purl ))}
95+ return {v .value . lstrip ( "vV" ) for v in versions (str (purl ))}
10396 except Exception as e :
10497 if logger :
10598 logger (
0 commit comments