Skip to content

Commit

Permalink
Add external_package_names(topology)
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Nov 12, 2024
1 parent 58bf766 commit e21058d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "PlutoDependencyExplorer"
uuid = "72656b73-756c-7461-726b-72656b6b696b"
license = "MIT"
authors = ["Paul Berg <[email protected]>", "Fons van der Plas <[email protected]>"]
version = "1.1.0"
version = "1.2.0"

[deps]
ExpressionExplorer = "21656369-7473-754a-2065-74616d696c43"
Expand Down
3 changes: 2 additions & 1 deletion src/PlutoDependencyExplorer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ abstract type AbstractCell end
include("./data structures.jl")
include("./ExpressionExplorer.jl")
include("./Topology.jl")
include("./imports.jl")
include("./Errors.jl")
include("./TopologicalOrder.jl")
include("./topological_order.jl")
include("./TopologyUpdate.jl")

end
end
12 changes: 12 additions & 0 deletions src/imports.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ExpressionExplorer

"""
```julia
external_package_names(topology::NotebookTopology)::Set{Symbol}
```
Get the set of package names that are imported by any cell in the notebook. This considers all `using` and `import` calls.
"""
function ExpressionExplorer.external_package_names(topology::NotebookTopology)::Set{Symbol}
union!(Set{Symbol}(), ExpressionExplorer.external_package_names.(c.module_usings_imports for c in values(topology.codes))...)
end
30 changes: 30 additions & 0 deletions test/imports.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Test
import PlutoDependencyExplorer as PDE
import PlutoDependencyExplorer.ExpressionExplorer

@testset "external_package_names" begin
struct SimpleCell <: PDE.AbstractCell
code
end

notebook = SimpleCell.([
"using Plots, Example.Something"
"""begin
import .Yoooo
import Sick: nice
end"""
":(import Nonono)"
]);

empty_topology = PDE.NotebookTopology{SimpleCell}();

topology = PDE.updated_topology(
empty_topology,
notebook, notebook;
get_code_str = c -> c.code,
get_code_expr = c -> Meta.parse(c.code),
);

@test ExpressionExplorer.external_package_names(topology) == Set([:Plots, :Example, :Sick])

end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ using PlutoDependencyExplorer


include("./basic.jl")
include("./imports.jl")
include("./data structures.jl")
include("./pluto integration/run.jl")

0 comments on commit e21058d

Please sign in to comment.