Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Curtis Vogt <[email protected]>
  • Loading branch information
palday and omus authored Jan 10, 2024
1 parent cb40924 commit 10fdd0b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,14 @@ end

# this function is available as of Julia 1.9
# https://github.com/JuliaLang/julia/pull/45607
# https://github.com/JuliaLang/julia/pull/45695
# https://github.com/JuliaLang/julia/pull/45861
# https://github.com/JuliaLang/julia/pull/46738
@static if !isdefined(Base, :pkgversion)
using TOML: parsefile
export pkgversion

const require_lock = isdefined(Base, :require_lock) ? Base.require_lock : Base.ReentrantLock()
const project_names = ("JuliaProject.toml", "Project.toml")

function locate_project_file(env::String)
Expand Down Expand Up @@ -430,8 +434,19 @@ end
"""
function pkgversion(m::Module)
path = pkgdir(m)
isnothing(path) && return nothing
return get_pkgversion_from_path(path)
path === nothing && return nothing
Base.@lock require_lock begin
v = get_pkgversion_from_path(path)
# https://github.com/JuliaLang/julia/pull/44318
@static if hasfield(Base.PkgOrigin, :version)

Check warning on line 441 in src/Compat.jl

View check run for this annotation

Codecov / codecov/patch

src/Compat.jl#L441

Added line #L441 was not covered by tests
pkgorigin = get(Base.pkgorigins, Base.PkgId(Base.moduleroot(m)), nothing)
# Cache the version
if pkgorigin !== nothing && pkgorigin.version === nothing
pkgorigin.version = v

Check warning on line 445 in src/Compat.jl

View check run for this annotation

Codecov / codecov/patch

src/Compat.jl#L445

Added line #L445 was not covered by tests
end
end
return v
end
end
end

Expand Down

0 comments on commit 10fdd0b

Please sign in to comment.