Skip to content

Commit

Permalink
Merge pull request #14 from JuliaPluto/Add-external_package_names
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp authored Nov 12, 2024
2 parents 58bf766 + e21058d commit 352b212
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")

2 comments on commit 352b212

@fonsp
Copy link
Member Author

@fonsp fonsp commented on 352b212 Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/119237

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.2.0 -m "<description of version>" 352b21219c04588a1da47af4929b864df02e9883
git push origin v1.2.0

Please sign in to comment.