Skip to content

Commit 9b9f5cd

Browse files
committed
Rework API to be around name, uuid rather than unexported Base.PkgId
1 parent f2d1eec commit 9b9f5cd

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

Project.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
33
authors = ["Tim Holy <[email protected]>"]
44
version = "0.1.0"
55

6+
[deps]
7+
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
8+
69
[extras]
10+
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
711
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
812

913
[targets]
10-
test = ["Test"]
14+
test = ["Test", "ColorTypes"]

src/CodeTracking.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module CodeTracking
22

33
using Base: PkgId
44
using Core: LineInfoNode
5+
using UUIDs
56

67
export PkgFiles
78
export whereis, definition, pkgfiles
@@ -81,11 +82,20 @@ end
8182
definition(method::Method) = definition(method, Expr)
8283

8384
"""
84-
info = pkgfiles(id::PkgId)
85+
info = pkgfiles(name::AbstractString)
86+
info = pkgfiles(name::AbstractString, uuid::UUID)
8587
86-
Return a [`PkgFiles`](@ref) structure with information about the files that define package `id`.
87-
Returns `nothing` if `id` has not been loaded.
88+
Return a [`PkgFiles`](@ref) structure with information about the files that define the package
89+
specified by `name` and `uuid`.
90+
Returns `nothing` if this package has not been loaded.
8891
"""
92+
pkgfiles(name::AbstractString, uuid::UUID) = pkgfiles(PkgId(uuid, name))
93+
function pkgfiles(name::AbstractString)
94+
project = Base.active_project()
95+
uuid = Base.project_deps_get(project, name)
96+
uuid == false && error("no package ", name, " recognized")
97+
return pkgfiles(name, uuid)
98+
end
8999
pkgfiles(id::PkgId) = get(_pkgfiles, id, nothing)
90100

91101
"""

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using CodeTracking
22
using Test
3+
# Note: ColorTypes needs to be installed, but note the absence of `using`
34

45
include("script.jl")
56

@@ -28,4 +29,7 @@ include("script.jl")
2829
show(io, info)
2930
str = String(take!(io))
3031
@test startswith(str, "PkgFiles(CodeTracking [da1fd8a2-8d9e-5ec2-8556-3022fb5608a2]):\n basedir:")
32+
33+
@test pkgfiles("ColorTypes") === nothing
34+
@test_throws ErrorException pkgfiles("NotAPkg")
3135
end

0 commit comments

Comments
 (0)