Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and test Pkg.test #1427

Merged
merged 13 commits into from
Dec 9, 2019
8 changes: 7 additions & 1 deletion src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ function dependencies(ctx::Context)::Dict{UUID, PackageInfo}
pkgs = Operations.load_all_deps(ctx)
return Dict(pkg.uuid => Operations.package_info(ctx, pkg) for pkg in pkgs)
end
dependencies(fn::Function, uuid::UUID) = fn(dependencies()[uuid])
function dependencies(fn::Function, uuid::UUID)
dep = get(dependencies(), uuid, nothing)
if dep === nothing
Copy link
Member

Choose a reason for hiding this comment

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

I guess you could write this as

dep = get(dependencies, uuid) do
    pkgerror("depenendency with UUID `$uuid` does not exist")
end

But I am not sure this is preferable even.

pkgerror("depenendency with UUID `$uuid` does not exist")
end
fn(dep)
end

project() = project(Context())
function project(ctx::Context)::ProjectInfo
Expand Down
210 changes: 146 additions & 64 deletions src/Operations.jl

Large diffs are not rendered by default.

55 changes: 10 additions & 45 deletions src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -394,43 +394,6 @@ end

is_stdlib(ctx::Context, uuid::UUID) = uuid in keys(ctx.stdlibs)

# target === nothing : main dependencies
# target === "*" : main + all extras
# target === "name" : named target deps
function deps_names(project::Project, target::Union{Nothing,String}=nothing)::Vector{String}
deps = collect(keys(project.deps))
if target === nothing
x = String[]
elseif target == "*"
x = collect(keys(project.extras))
else
x = haskey(project.targets, target) ?
collect(values(project.targets[target])) :
String[]
end
return sort!(union!(deps, x))
end

function get_deps(project::Project, target::Union{Nothing,String}=nothing)
names = deps_names(project, target)
deps = filter(((dep, _),) -> dep in names, project.deps)
extras = project.extras
for name in names
haskey(deps, name) && continue
haskey(extras, name) ||
pkgerror("target `$target` has unlisted dependency `$name`")
deps[name] = extras[name]
end
return deps
end
get_deps(env::EnvCache, target::Union{Nothing,String}=nothing) =
get_deps(env.project, target)

function project_compatibility(ctx::Context, name::String)
compat = get(ctx.env.project.compat, name, nothing)
return compat === nothing ? VersionSpec() : VersionSpec(semver_spec(compat))
end

function write_env_usage(source_file::AbstractString, usage_filepath::AbstractString)
!ispath(logdir()) && mkpath(logdir())
usage_file = joinpath(logdir(), usage_filepath)
Expand All @@ -448,15 +411,17 @@ function write_env_usage(source_file::AbstractString, usage_filepath::AbstractSt
close(io)
end

function read_package(f::String)
_throw_package_err(x) = pkgerror("expected a `$x` entry in project file at $(abspath(f))")

project = read_project(f)
project.name === nothing && _throw_package_err("name")
project.uuid === nothing && _throw_package_err("uuid")
function read_package(path::String)
project = read_project(path)
if project.name === nothing
pkgerror("expected a `name` entry in project file at `$(abspath(path))`")
end
if project.uuid === nothing
pkgerror("expected a `uuid` entry in project file at `$(abspath(path))`")
end
name = project.name
if !isfile(joinpath(dirname(f), "src", "$name.jl"))
pkgerror("expected the file `src/$name.jl` to exist for package $name at $(dirname(f))")
if !isfile(joinpath(dirname(path), "src", "$name.jl"))
pkgerror("expected the file `src/$name.jl` to exist for package `$name` at `$(dirname(path))`")
end
return project
end
Expand Down
Loading