mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
* feat/init-pip-cmd * feat: Add PyPi resolver * test: Add tests for pypi and pypi_resolver * refactor: unify package dependency resolution and improve PyPI version handling using registry adapter * chore: remove unused file Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> * feat: add Python dependency parsing with extras support * refactor(deps): Improve PyPI dependency resolution and add custom resolver support * chore: remove extra file * fix: improve dependency resolution and package deduplication * chore: remove extra print statement * chore: typo fix * feat: support PyPi package extras * test: add test for pypi dependency parse function * fix: remove overwritten of parsedCmd * chore: remove extra print statement * chore: typo fix * feat: support PyPi package extras * test: add test for pypi dependency parse function * fix: remove overwritten of parsedCmd * refactor: enhance code readability & remove extra code * chore: remove extra code * Update cmd/npm/npm.go Co-authored-by: Omkar Phansopkar <omkarphansopkar@gmail.com> Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> * Update cmd/npm/pnpm.go Co-authored-by: Omkar Phansopkar <omkarphansopkar@gmail.com> Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> * Update cmd/pypi/pip.go Co-authored-by: Omkar Phansopkar <omkarphansopkar@gmail.com> Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> --------- Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> Co-authored-by: Omkar Phansopkar <omkarphansopkar@gmail.com>
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package packagemanager
|
|
|
|
import (
|
|
"context"
|
|
|
|
packagev1 "buf.build/gen/go/safedep/api/protocolbuffers/go/safedep/messages/package/v1"
|
|
)
|
|
|
|
type Command struct {
|
|
Exe string
|
|
Args []string
|
|
}
|
|
|
|
type PackageInstallTarget struct {
|
|
PackageVersion *packagev1.PackageVersion
|
|
|
|
// Extras specifies additional features to be installed with a Python package
|
|
// Example: "django[mysql,redis]" has Extras as ["mysql", "redis"]
|
|
// Currently only specific to Python packages
|
|
Extras []string
|
|
}
|
|
|
|
func (pit *PackageInstallTarget) HasVersion() bool {
|
|
return pit.PackageVersion != nil && pit.PackageVersion.GetVersion() != ""
|
|
}
|
|
|
|
type ParsedCommand struct {
|
|
// Original command
|
|
Command Command
|
|
|
|
// Parsed install target if this is an install command
|
|
InstallTargets []*PackageInstallTarget
|
|
}
|
|
|
|
func (pc *ParsedCommand) HasInstallTarget() bool {
|
|
return len(pc.InstallTargets) > 0
|
|
}
|
|
|
|
// PackageManager is the contract for implementing a package manager
|
|
type PackageManager interface {
|
|
// Name of the package manager implementation
|
|
Name() string
|
|
|
|
// ParseCommand parses the command and returns a parsed command
|
|
// specific to the package manager implementation
|
|
ParseCommand(args []string) (*ParsedCommand, error)
|
|
}
|
|
|
|
// PackageResolver is the contract for resolving package info
|
|
type PackageResolver interface {
|
|
// ResolveLatestVersion resolves the latest version for a given package
|
|
ResolveLatestVersion(context.Context, *packagev1.Package) (*packagev1.PackageVersion, error)
|
|
|
|
// ResolveDependencies resolves the dependencies for a given package version
|
|
// It returns a flattened list of all the dependencies based on implementation
|
|
// specific config. The version resolution is based on minimum version selection
|
|
// for a given version range.
|
|
ResolveDependencies(context.Context, *packagev1.PackageVersion) ([]*packagev1.PackageVersion, error)
|
|
}
|