Skip to content

Commit

Permalink
Fix tests and latent bug around public symbols vs base exports (#96)
Browse files Browse the repository at this point in the history
* add failing test

* fix test

* Update test/runtests.jl

* fix

* bugfix
  • Loading branch information
ericphanson authored Jan 30, 2025
1 parent 28843cf commit cf97b9f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ExplicitImports"
uuid = "7d51a73a-1435-4ff3-83d9-f097790105c7"
authors = ["Eric P. Hanson"]
version = "1.10.1"
version = "1.10.2"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
10 changes: 9 additions & 1 deletion src/find_implicit_imports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ function find_implicit_imports(mod::Module; skip=(mod, Base, Core))
push!(es, e)
end
end
mod_lookup[name] = (; source, exporters=es)
# if there are no matches (empty `es`), we will skip it
# This seemed to happen for `tryparse` in `Pkg.Types` which resolves to `Base.tryparse`
# and does not match `TOML.tryparse` which was the only candidate to compare to
# (since we want to skip `Base.tryparse` as `Base` is in `skip`)
# If there are no matches, such as in this case, we don't want to count it
# as an implicit import, since it is probably only from a module in `skip`.
if !isempty(es)
mod_lookup[name] = (; source, exporters=es)
end
end
end
return mod_lookup
Expand Down
16 changes: 16 additions & 0 deletions test/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,19 @@ using UUIDs

v = UUID[]
end

module ModWithTryparse
using Main: @public

@public tryparse
function tryparse()
return 1
end
end
# https://github.com/ericphanson/ExplicitImports.jl/issues/88
module Mod88

using ..ModWithTryparse

tryparse
end
8 changes: 8 additions & 0 deletions test/public_compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
macro public_or_export(symbol::Symbol)
return esc(Expr(:public, symbol))
end
macro public(symbol::Symbol)
return esc(Expr(:public, symbol))
end

else
macro public_or_export(symbol::Symbol)
return esc(Expr(:export, symbol))
end
macro public(symbol::Symbol)
return nothing
end

end
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,11 @@ end
@test contains(str, "• qr")
end

@testset "Handle public symbols with same name as exported Base symbols (#88)" begin
statements = using_statement.(explicit_imports_nonrecursive(Mod88, "examples.jl"))
@test statements == ["using .ModWithTryparse: ModWithTryparse"]

end
@testset "Don't skip source modules (#29)" begin
# In this case `UUID` is defined in Base but exported in UUIDs
ret = ExplicitImports.find_implicit_imports(Mod29)[:UUID]
Expand Down

2 comments on commit cf97b9f

@ericphanson
Copy link
Owner Author

Choose a reason for hiding this comment

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

@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/124054

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.10.2 -m "<description of version>" cf97b9f1607b6ebe388d68b677c90fc093591f93
git push origin v1.10.2

Please sign in to comment.