Skip to content

Commit

Permalink
Reorganize Internals [close #75]
Browse files Browse the repository at this point in the history
there's different modules now, it's nice.
Also reorganize test along with it.

and add test/activate_standalone.jl
  • Loading branch information
tfiers committed Jan 13, 2023
1 parent 89403c6 commit c11c7f3
Show file tree
Hide file tree
Showing 38 changed files with 531 additions and 279 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/docs/build/
/docs/src-mod/
/docs/localdev/Manifest.toml
/test/standalone/Manifest.toml
5 changes: 3 additions & 2 deletions docs/src/bg/related-work.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ Also has `dependencies(pkg)` and `direct_dependencies(pkg)` functions.

#### [Graphviz.jl]

Bundles the graphviz binaries (including `dot`) (via [JuliaBinaryWrappers/Graphviz_jll][Graphviz_jll]), and provides access in Julia to graphviz's C API.
Bundles the graphviz binaries (including `dot`) (via [JuliaBinaryWrappers/Graphviz_jll][Graphviz_jll]),
and provides access in Julia to graphviz's C API.
Provides the `@dot_str` macro to render dot strings in a notebook.

#### [GraphvizDotLang.jl]

Recent package, under active development at the time of writing. A beautiful package to
generate and render dot-strings. Uses Julia's piping syntax. Had I discovered this
package before writing PkgGraph, I might have used it as a dependency. (Replacing things
like [`PkgGraph.Internals.to_dot_str`](@ref)).
like [`PkgGraph.to_dot_str`](@ref)).


[PkgDependency.jl]: https://github.com/peng1999/PkgDependency.jl
Expand Down
2 changes: 1 addition & 1 deletion docs/src/ref/end-user.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ PkgGraph.create

These are keyword arguments that can be used with [`PkgGraph.open`](@ref) and
[`PkgGraph.create`](@ref).\
(They are also fields to [`PkgGraph.Internals.Options`](@ref)).
(They are also fields to [`PkgGraph.Options`](@ref)).

#### `jll`
Whether to include binary 'JLL' dependencies in the graph
Expand Down
6 changes: 1 addition & 5 deletions docs/src/ref/internals.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@

```@meta
CurrentModule = PkgGraph.Internals
CurrentModule = PkgGraph
```

# Internals

```@docs
Internals
```

## Creating a dependency graph

```@docs
Expand Down
28 changes: 20 additions & 8 deletions src/PkgGraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@ Use [`PkgGraph.open`](@ref) to view the graph in the browser,
or [`PkgGraph.create`](@ref) to generate an image locally.
(Note that these functions are not exported).
See [`PkgGraph.Internals`](@ref) for more functions.
"""
module PkgGraph

using TOML
using EzXML
using URIs: escapeuri
include("internals/Internals.jl")

include("modules/DepGraph.jl")
using .DepGraph

include("modules/LoadTime.jl")
using .LoadTime

include("modules/DotString.jl")
using .DotString

include("modules/SVG.jl")
using .SVG


using DefaultApplication
using .Internals
include("enduser.jl")
using URIs: escapeuri
using Base: @kwdef
include("includes/dotcommand.jl")
include("includes/webapps.jl")
include("includes/options.jl")
include("includes/enduser.jl")

# No package exports (no namespace pollution)


end # module
File renamed without changes.
2 changes: 1 addition & 1 deletion src/enduser.jl → src/includes/enduser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function create(pkgname, dir=tempdir(); fmt=:png, bg=bg(fmt), open=true, dryrun=
if !is_dot_available() && !dryrun
error("`dot` program not found on `PATH`. Get it at https://graphviz.org/download/")
end
dotstr = to_dot_str(pkgname, Options(; kw...))
dotstr = to_dot_str(pkgname, Options(; bg, kw...))
imgpath = output_path(pkgname, dir, fmt)
if !dryrun
create_dot_image(dotstr, fmt, imgpath)
Expand Down
4 changes: 2 additions & 2 deletions src/internals/options.jl → src/includes/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ See [Settings](@ref) for available properties.
bg = "transparent"
end

depgraph(pkg, o::Options) =
DepGraph.depgraph(pkg, o::Options) =
depgraph(pkg; o.jll, o.stdlib)

to_dot_str(pkg, o::Options) =
DotString.to_dot_str(pkg, o::Options) =
to_dot_str(
depgraph(pkg, o);
o.style,
Expand Down
2 changes: 1 addition & 1 deletion src/internals/webapps.jl → src/includes/webapps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const webapps = [
@doc(
"""
A list of websites that can render Graphviz dot-formatted
strings. Used by [`Internals.url`](@ref).
strings. Used by [`url`](@ref).
Note that these are 'base URLs', to which url-encoded
dot-strings can be directly appended.
Expand Down
63 changes: 0 additions & 63 deletions src/internals/Internals.jl

This file was deleted.

32 changes: 32 additions & 0 deletions src/modules/DepGraph.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module DepGraph

using Pkg
using TOML
using UUIDs
using Base: active_project

include("DepGraph/stdlib.jl")
export STDLIB,
STDLIB_NAMES

include("DepGraph/project.jl")

include("DepGraph/registry.jl")

include("DepGraph/main.jl")
export depgraph,
should_be_included,
is_jll,
is_in_stdlib,
STDLIB

include("DepGraph/graphsjl.jl")
export vertices,
node_index,
adjacency_matrix,
as_graphsjl_input,
as_int_pairs,
EdgeList,
Edge

end
10 changes: 5 additions & 5 deletions src/internals/graphsjl.jl → src/modules/DepGraph/graphsjl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ Extract the unique nodes from the given list of edges.
## Example:
```jldoctest
julia> using PkgGraph.Internals
julia> using PkgGraph
julia> edges = depgraph(:Test);
julia> edges = PkgGraph.depgraph(:Test);
julia> vertices(edges)
julia> PkgGraph.vertices(edges)
8-element Vector{String}:
"Test"
"InteractiveUtils"
Expand Down Expand Up @@ -65,11 +65,11 @@ This is useful because Graphs.jl requires vertices to be integers.
## Example:
```jldoctest
julia> using PkgGraph.Internals
julia> using PkgGraph
julia> edges = ["A"=>"B", "B"=>"C"];
julia> node = node_index(edges);
julia> node = PkgGraph.node_index(edges);
julia> node("C")
3
Expand Down
4 changes: 2 additions & 2 deletions src/internals/depgraph.jl → src/modules/DepGraph/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ filtered out from the result by setting `jll` and `stdlib` to `false`.
## Example:
```jldoctest
julia> using PkgGraph.Internals
julia> using PkgGraph
julia> depgraph(:Test)
julia> PkgGraph.depgraph(:Test)
8-element Vector{Pair{String, String}}:
"Test" => "InteractiveUtils"
"InteractiveUtils" => "Markdown"
Expand Down
4 changes: 2 additions & 2 deletions src/internals/project.jl → src/modules/DepGraph/project.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ packages would share the same name.
## Example:
```jldoctest; filter = r" => .*\$"m
julia> using PkgGraph.Internals
julia> using PkgGraph
julia> packages = packages_in_active_manifest();
julia> packages = PkgGraph.packages_in_active_manifest();
julia> only(packages["PkgGraph"])
Dict{String, Any} with 4 entries:
Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 10 additions & 3 deletions src/internals/dot.jl → src/modules/DotString.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

module DotString

export to_dot_str,
default_style

"""
to_dot_str(
edges;
Expand Down Expand Up @@ -35,9 +40,9 @@ julia> edges = [:A => :B, "yes" => "no"];
julia> style = ["node [color=\\"red\\"]"];
julia> using PkgGraph.Internals
julia> using PkgGraph
julia> to_dot_str(edges; style, bg=:blue, indent=2) |> println
julia> PkgGraph.to_dot_str(edges; style, bg=:blue, indent=2) |> println
digraph {
bgcolor = "blue"
node [fillcolor="white", fontcolor="black", color="black"]
Expand All @@ -49,7 +54,7 @@ digraph {
julia> emptymsg="(empty graph)";
julia> to_dot_str([]; emptymsg, mode=:dark, style=[]) |> println
julia> PkgGraph.to_dot_str([]; emptymsg, mode=:dark, style=[]) |> println
digraph {
bgcolor = "transparent"
node [fillcolor="black", fontcolor="white", color="white"]
Expand Down Expand Up @@ -108,3 +113,5 @@ colourschemes() = Dict(
:light => colouring(paper="white", ink="black"),
:dark => colouring(paper="black", ink="white"),
)

end
2 changes: 1 addition & 1 deletion src/internals/loadtime.jl → src/modules/LoadTime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function time_imports(pkg)
loadtimes = parse_timeimports(output)
return loadtimes
end
r


timeimports_code(pkgname) =
"using InteractiveUtils; @time_imports using $pkgname"
Expand Down
2 changes: 2 additions & 0 deletions src/internals/SVG.jl → src/modules/SVG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module SVG

using EzXML

export add_darkmode

"""
add_darkmode(path, out = path)
Expand Down
Loading

0 comments on commit c11c7f3

Please sign in to comment.