Workspace.Graph (Workspace v0.2.1)
View SourceWorkspace path dependencies graph and helper utilities
Internal graph representation
Each graph node is an internal struct, holding the project name, the type of the project (e.g. workspace or external dependency) and an arbitrary set of metadata.
By default :workspace
dependencies will always be included in the graph. On the
other hand :external
dependencies will be included only if the :external
option is set to true
during graph's construction.
Usage
This module provides with_digraph/3
and digraph/2
for constructing the
workspace graph from a workspace, and a set of helper utilities operating
on a graph.
workspace = Workspace.new!("/path/to/workspace")
# construct the graph, including external dependencies
graph = Workspace.Graph.digraph(workspace, external: true)
# get graph leaves
Workspace.Graph.sink_projects(graph)
Summary
Functions
Get the affected workspace's projects given the changed projects
Returns the direct dependencies of the given project
Generates a graph of the given workspace.
Return the sink projects of the workspace
Return the source projects of the workspace
Returns a subgraph around the given project
and all nodes within the given proximity
.
Runs the given callback
on the workspace's graph
Types
@type vertices() :: [:digraph.vertex()]
Functions
@spec affected(workspace :: Workspace.State.t(), projects :: [atom()]) :: [atom()]
Get the affected workspace's projects given the changed projects
Notice that the project names are returned, you can use Workspace.project/2
to map them back into projects.
@spec dependencies(workspace :: Workspace.State.t(), project :: atom()) :: [atom()]
Returns the direct dependencies of the given project
The direct dependencies are the path dependencies that are defined in the
project
' s mix.exs
.
@spec digraph( workspace_or_projects :: Workspace.State.t() | [Workspace.Project.t()], opts :: keyword() ) :: :digraph.graph()
Generates a graph of the given workspace.
Notice that you need to manually delete the graph. Prefer instead
with_digraph/3
.
Options
:external
- if set external dependencies will be included as well:exclude
- if set the specified workspace projects will not be included in the graph
@spec sink_projects(workspace_or_graph :: Workspace.State.t() | :digraph.graph()) :: [ atom() ]
Return the sink projects of the workspace
Notice that the project names are returned, you can use Workspace.project/2
to map them back into projects.
@spec source_projects(workspace_or_graph :: Workspace.State.t() | :digraph.graph()) :: [atom()]
Return the source projects of the workspace
The input can be either a Workspace
struct or the workspace graph. In case of a
Workspace
a temporary graph will be constructed.
Notice that the project names are returned, you can use Workspace.project/2
to map them back into projects.
@spec subgraph( graph :: :digraph.graph(), project :: atom(), proximity :: pos_integer() ) :: :digraph.graph()
Returns a subgraph around the given project
and all nodes within the given proximity
.
@spec with_digraph( workspace :: Workspace.State.t(), callback :: (:digraph.graph() -> result), opts :: keyword() ) :: result when result: term()
Runs the given callback
on the workspace's graph
callback
should be a function expecting as input a :digraph.graph()
. For
supported options check digraph/2