graph

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package graph provides dependency resolution for AUR packages. It is not very optimized, but it should work (hopefully).

Usage

First, you have to create a graph:

pkgs, err := aur.ReadAll(list)
if err != nil {
   return err
}
g, err := graph.NewGraph()
if err != nil {
   return err
}

Once you have a graph, you can then get the ordered dependency list with the following function:

graph.Dependencies(g)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllNodesBottomUp

func AllNodesBottomUp(g graph.Directed) []graph.Node

AllNodesBottomUp returns for all roots the nodes bottom-up.

func Dependencies

func Dependencies(g *Graph) (pacman.Packages, aur.Packages, []string)

Dependencies returns a list of all dependencies in the graph, those in repositories, those from AUR, and those unknown.

func NodesBottomUp

func NodesBottomUp(g graph.Directed, root graph.Node) []graph.Node

NodesBottomUp returns the subtree from the bottom levels upwards to the root. The nodes may appear multiple times however.

func Roots

func Roots(g graph.Directed) []graph.Node

Roots returns all the root nodes for a directed graph.

Types

type Edge

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

Edge implements the graph.Edge interface.

func (*Edge) From

func (e *Edge) From() graph.Node

From returns the node that has the dependency.

func (*Edge) IsFromAUR

func (e *Edge) IsFromAUR() bool

IsFromAUR returns true if the dependency needs to be fetched from AUR.

func (*Edge) String

func (e *Edge) String() string

func (*Edge) To

func (e *Edge) To() graph.Node

To returns the depdency that the from node has.

func (*Edge) Weight

func (e *Edge) Weight() float64

Weight returns zero, because depdencies are not weighted.

type Factory

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

A Factory creates a dependency graph given a set of packages.

It can perform AUR calls to resolve dependencies and it can truncate dependencies so that they are not resolved beyond packages available in repositories. This reduces the dependency list

func NewFactory

func NewFactory(ignoreRepos ...string) (*Factory, error)

NewFactory returns a new dependency graph, ignoring repositories given in `ignore`.

Note that it makes a difference between dependencies that are in AUR, and those availabe in the repositories. Ignoring repositories effectively "demotes" any packages available in them back to AUR.

Any package that is in the dependency graph that is not from AUR is treated as a leaf in the graph, since we assume that pacman can resolve those dependencies.

func (*Factory) NewGraph

func (f *Factory) NewGraph(pkgs aur.Packages) (*Graph, error)

NewGraph returns a dependency graph of the given AUR packages. Extra packages may be pulled into the graph to properly build the dependency graph.

func (*Factory) NumRequestsAUR

func (f *Factory) NumRequestsAUR() int

NumRequestsAUR returns the number of requests made to AUR.

func (*Factory) SetDependencyFunc

func (f *Factory) SetDependencyFunc(fn func(pacman.AnyPackage) []string)

SetDependencyFunc controls which dependency list is used. By default, make and install dependencies are included.

func (*Factory) SetNoUnknown

func (f *Factory) SetNoUnknown(yes bool)

SetNoUnknown controls whether unknown packages (i.e., not on AUR) are injected into the graph. If this is set to true, NewGraph will fail if any unknown packages are found.

func (*Factory) SetSkipInstalled

func (f *Factory) SetSkipInstalled(yes bool)

SetSkipInstalled controls whether installed packages are disregarded from the dependency tree.

func (*Factory) SetTruncate

func (f *Factory) SetTruncate(yes bool)

SetTruncate controls whether packages available in a repository are not further investigated.

type Graph

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

Graph implements graph.Graph.

func NewGraph

func NewGraph() *Graph

NewGraph returns a new graph.

func (*Graph) AddEdgeFromTo

func (g *Graph) AddEdgeFromTo(u, v graph.Node)

AddEdgeFromTo adds an edge betwewen the two nodes.

func (*Graph) AddNode

func (g *Graph) AddNode(v graph.Node)

AddNode adds the node and initializes data structures but does nothing else.

func (*Graph) Edge

func (g *Graph) Edge(u, v graph.Node) graph.Edge

Edge returns the edge from u to v if such an edge exists and nil otherwise. The node v must be directly reachable from u as defined by the From method.

func (*Graph) From

func (g *Graph) From(v graph.Node) []graph.Node

From returns all nodes that can be reached directly from the given node.

func (*Graph) Has

func (g *Graph) Has(n graph.Node) bool

Has returns whether the node exists within the graph.

func (*Graph) HasEdgeBetween

func (g *Graph) HasEdgeBetween(u, v graph.Node) bool

HasEdgeBetween returns whether an edge exists between nodes u and v without considering direction.

func (*Graph) HasEdgeFromTo

func (g *Graph) HasEdgeFromTo(u, v graph.Node) bool

HasEdgeFromTo returns whether an edge exists in the graph from u to v.

func (*Graph) HasName

func (g *Graph) HasName(name string) bool

HasName returns whether the package with the given name exists within the graph.

func (*Graph) NewNode

func (g *Graph) NewNode(pkg pacman.AnyPackage) *Node

NewNode returns a new node.

func (*Graph) NewNodeID

func (g *Graph) NewNodeID() int

NewNodeID returns a unique ID for a new node.

func (*Graph) NodeWithName

func (g *Graph) NodeWithName(name string) *Node

NodeWithName returns the node with the given name, or nil.

func (*Graph) Nodes

func (g *Graph) Nodes() []graph.Node

Nodes returns all the nodes in the graph.

func (*Graph) To

func (g *Graph) To(v graph.Node) []graph.Node

To returns all nodes that can reach directly to the given node.

type Node

type Node struct {
	pacman.AnyPackage
	// contains filtered or unexported fields
}

Node implements graph.Node.

func (*Node) AllDepends

func (n *Node) AllDepends() []string

AllDepends returns a (newly created) string slice of the installation and make dependencies of this package.

func (*Node) ID

func (n *Node) ID() int

ID returns the unique (within the graph) ID of the node.

func (*Node) IsFromAUR

func (n *Node) IsFromAUR() bool

IsFromAUR returns whether the node comes from AUR.

func (*Node) NumAllDepends

func (n *Node) NumAllDepends() int

NumDepends returns the number of make and installation dependencies the package has.

func (*Node) String

func (n *Node) String() string

Jump to

Keyboard shortcuts

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