View Source Workspace.Graph (Workspace v0.1.2)

Workspace 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

Link to this function

affected(workspace, projects)

View Source
@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.

Link to this function

dependencies(workspace, project)

View Source
@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.

Link to this function

digraph(workspace_or_projects, opts \\ [])

View Source
@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
Link to this function

sink_projects(workspace_or_graph)

View Source
@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.

Link to this function

source_projects(workspace_or_graph)

View Source
@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.

Link to this function

subgraph(graph, project, proximity)

View Source
@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.

Link to this function

with_digraph(workspace, callback, opts \\ [])

View Source
@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