Skip to content

Commit

Permalink
Drop ignore_namespace config
Browse files Browse the repository at this point in the history
- Insted going forward we'll be using aboutcode-org/scancode-toolkit#3102 to ignore private PURLs

Signed-off-by: Keshav Priyadarshi <[email protected]>
  • Loading branch information
keshav-space committed Jul 7, 2023
1 parent c2c4d1c commit 71da4e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 35 deletions.
43 changes: 10 additions & 33 deletions scanpipe/pipelines/populate_purldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,12 @@
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/nexB/scancode.io for support and download.

from django.db.models import Q

from scanpipe.models import posix_regex_to_django_regex_lookup
from scanpipe.pipelines import Pipeline
from scanpipe.pipes import purldb


class PopulatePurlDB(Pipeline):
"""
Populate PurlDB with project packages.
Ignore PURLs where namespace matches the pattern supplied
under ``ignored_namespace`` in scancode-config.yml.
"""
"""Populate PurlDB with project packages."""

@classmethod
def steps(cls):
Expand All @@ -42,39 +34,24 @@ def steps(cls):
cls.populate_purldb_discovereddependency,
)

@property
def ignored_namespaces(self):
return self.env.get("ignored_namespaces", [])

def populate_purldb_discoveredpackage(self):
"""Add DiscoveredPackage to PurlDB."""
feed_purldb(
package_object=self.project.discoveredpackages,
ignored_namespaces=self.ignored_namespaces,
logger=self.log,
)
packages = self.project.discoveredpackages.all()

self.log(f"Populating PurlDB with {len(packages):,d} DiscoveredPackage")
feed_purldb(packages=packages)

def populate_purldb_discovereddependency(self):
"""Add DiscoveredDependency to PurlDB."""
feed_purldb(
package_object=self.project.discovereddependencies,
ignored_namespaces=self.ignored_namespaces,
logger=self.log,
)
packages = self.project.discovereddependencies.all()

self.log(f"Populating PurlDB with {len(packages):,d} DiscoveredDependency")
feed_purldb(packages=packages)


def feed_purldb(package_object, ignored_namespaces, logger):
def feed_purldb(packages):
if not purldb.is_available():
raise Exception("PurlDB is not configured.")

combined_pattern = Q()
for pattern in ignored_namespaces:
combined_pattern |= Q(
namespace__regex=posix_regex_to_django_regex_lookup(pattern)
)

packages = package_object.exclude(combined_pattern)

logger(f"Populating PurlDB with {len(packages):,d} PURLs")
for purl in list(set(packages)):
purldb.index_package(purl)
4 changes: 2 additions & 2 deletions scanpipe/tests/test_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,5 +934,5 @@ def test_scanpipe_populate_purldb_pipeline_integration_test(
exitcode, out = pipeline.execute()
self.assertEqual(0, exitcode, msg=out)

self.assertIn("Populating PurlDB with 2 PURLs", run.log)
self.assertIn("Populating PurlDB with 4 PURLs", run.log)
self.assertIn("Populating PurlDB with 2 DiscoveredPackage", run.log)
self.assertIn("Populating PurlDB with 4 DiscoveredDependency", run.log)

0 comments on commit 71da4e7

Please sign in to comment.