dependency

package
v0.1.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package dependency a way to get all dependencies of a single package or application.

Dependencies are resolved with the help of so called "Resolver". Resolver are responsible to resolve the dependencies. They know where to find all dependencies and what are the next steps are.

Resolvers need information about single packages like the name or the url. For this the repository.Client are there. The repository.Client are the clients to connect to the end service and to retrieve the necessary information. Typically a repository.Client is a API client for services like Packagist (for PHP) or PyPI (Python).

Resolvers stream their results of the resolution via a channel back to the caller.

When we talk about dependencies we normally talking about a tree. As an example the PHP package symfony/console:

symfony/console
|- symfony/polyfill-mbstring
|- symfony/debug
	|- psr/log

Every package has n sub dependencies. The result stream will not return a tree. It will return a list of packages. And this algorithm is not stable. Means: The order of the package can be different each time. The caller code must be able to handle it.

Checkout the examples on how to use a resolver in combination with a repository.Client.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComposerResolver

type ComposerResolver struct {
	// contains filtered or unexported fields
}

ComposerResolver is an implementation of Resolver for Composer (PHP)

Example
u := "https://packagist.org/"
packageName := "symfony/console"
numOfWorker := 3

// Create a new package
p, err := NewPackage(packageName, "")
if err != nil {
	panic(err)
}

// Create a packagist client (PHP)
packagistClient, err := repository.NewPackagist(u, nil)
if err != nil {
	panic(err)
}

// Create a composer resolver and inject the packagist client
resolver, err := NewComposerResolver(numOfWorker, packagistClient)
if err != nil {
	panic(err)
}

results := resolver.GetResultStream()
go resolver.Resolve([]*Package{p})

dependencies := []string{}
// Finally we collect all the results of the work.
for v := range results {
	dependencies = append(dependencies, v.Package.Name)
}

fmt.Printf("%d dependencies found for package \"%s\" on %s", len(dependencies), p.Name, u)
Output:

4 dependencies found for package "symfony/console" on https://packagist.org/

func (*ComposerResolver) GetResultStream

func (d *ComposerResolver) GetResultStream() <-chan *Result

GetResultStream will return the channel for results. During the process of resolving dependencies, this channel will be filled with the results. Those can be processed next to the resolve process.

func (*ComposerResolver) Resolve

func (d *ComposerResolver) Resolve(packageList []*Package)

Resolve will start of the dependency resolver process.

type Package

type Package struct {
	// Name is the name of the package (e.g. "twig/twig" or "symfony/console")
	Name       string
	Repository *url.URL
}

Package represents a single package. This can be seen as the main unit of perseus.

func NewPackage

func NewPackage(name, repository string) (*Package, error)

NewPackage will create a new Package

type Resolver

type Resolver interface {
	Resolve(packageList []*Package)
	GetResultStream() <-chan *Result
}

Resolver is an interface to resolve package dependencies

func NewComposerResolver

func NewComposerResolver(numOfWorker int, p repository.Client) (Resolver, error)

NewComposerResolver will create a new instance of a Resolver. Standard implementation is the ComposerResolver.

type Result

type Result struct {
	Package *Package
	Error   error
}

Result reflects a result of a dependency resolver process.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL