github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/pkg/cataloger/python/cataloger.go (about)

     1  /*
     2  Package python provides a concrete Cataloger implementation relating to packages within the Python language ecosystem.
     3  */
     4  package python
     5  
     6  import (
     7  	"github.com/anchore/syft/syft/pkg"
     8  	"github.com/anchore/syft/syft/pkg/cataloger/generic"
     9  )
    10  
    11  const eggInfoGlob = "**/*.egg-info"
    12  
    13  type CatalogerConfig struct {
    14  	GuessUnpinnedRequirements bool `yaml:"guess-unpinned-requirements" json:"guess-unpinned-requirements" mapstructure:"guess-unpinned-requirements"`
    15  }
    16  
    17  func DefaultCatalogerConfig() CatalogerConfig {
    18  	return CatalogerConfig{
    19  		GuessUnpinnedRequirements: false,
    20  	}
    21  }
    22  
    23  // NewPackageCataloger returns a new cataloger for python packages referenced from poetry lock files, requirements.txt files, and setup.py files.
    24  func NewPackageCataloger(cfg CatalogerConfig) *generic.Cataloger {
    25  	rqp := newRequirementsParser(cfg)
    26  	return generic.NewCataloger("python-package-cataloger").
    27  		WithParserByGlobs(rqp.parseRequirementsTxt, "**/*requirements*.txt").
    28  		WithParserByGlobs(parsePoetryLock, "**/poetry.lock").
    29  		WithParserByGlobs(parsePipfileLock, "**/Pipfile.lock").
    30  		WithParserByGlobs(parseSetup, "**/setup.py")
    31  }
    32  
    33  // NewInstalledPackageCataloger returns a new cataloger for python packages within egg or wheel installation directories.
    34  func NewInstalledPackageCataloger() pkg.Cataloger {
    35  	return generic.NewCataloger("python-installed-package-cataloger").
    36  		WithParserByGlobs(
    37  			parseWheelOrEgg,
    38  			eggInfoGlob,
    39  			"**/*dist-info/METADATA",
    40  			"**/*egg-info/PKG-INFO",
    41  			"**/*DIST-INFO/METADATA",
    42  			"**/*EGG-INFO/PKG-INFO",
    43  		)
    44  }