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: do not use double constructor for PackageSpec #2477

Merged
merged 2 commits into from
Apr 10, 2021
Merged

Conversation

00vareladavid
Copy link
Contributor

Fix #2282

I admit that messing with the constructor was a thoroughly terrible idea. The check could be circumvented anyway by manually setting the fields after the constructor call. The checking should be done inside the API.

@KristofferC
Copy link
Member

KristofferC commented Apr 1, 2021

Could the handle_package_input! be added around here instead

ret = $f(ctx, pkgs; kwargs...)
? And then it is used for everything?

@00vareladavid 00vareladavid changed the title [WIP] Refactor: do not use double constructor for PackageSpec Refactor: do not use double constructor for PackageSpec Apr 1, 2021
@00vareladavid
Copy link
Contributor Author

There is something weird going on with the artifacts tests. It was giving some bad input to Pkg.add. I adjusted them to what I thought was the most likely intention, but I do not really understand those tests yet.

@00vareladavid
Copy link
Contributor Author

Perhaps @staticfloat (or anyone who knows those tests) could take a quick look. I'm almost certain it was just a matter of git initing the test packages, but there was a mismatch between some UUIDs that I'm not so sure about.

@@ -1,5 +1,5 @@
name = "ArtifactOverrideLoading"
uuid = "9f5278ee-142d-5d9a-9723-c4aebaa272e1"
uuid = "7b879065-7f74-5fa4-bdd5-9b7a15df8941"
Copy link
Member

Choose a reason for hiding this comment

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

Why did you need to change the UUID here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it to the value of aol_uuid because that was the value explicitly given here:

uuid=aol_uuid,
. If they are not the same value, Pkg will error out.

Copy link
Member

Choose a reason for hiding this comment

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

huh, why wasn't this erroring before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a misuse of the API here. API calls were supposed to be made with Pkg.PackageSpec, not Pkg.Types.PackageSpec. This is needlessly confusing, which is why this PR removes the second constructor.

Copy link
Member

Choose a reason for hiding this comment

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

Right, I'm specifically interested in why this having the wrong UUID didn't cause an issue before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because Pkg.PackageSpec did some pre-processing, which was circumvented by using Pkg.Types.PackageSpec. In particular, Pkg.PackageSpec automatically sets repo.source, while Pkg.Types.PackageSpec does not. So the package was in some undefined state which just happened to appear like it was tracking a path when it was written to the manifest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it seems like the intention was that they were supposed to be the same UUID? That is the only thing I was not sure of.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, they definitely should have matched

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, thanks. I think this slight adjustment was all that was necessary

add_this_pkg()
Pkg.add(Pkg.Types.PackageSpec(
name="ArtifactInstallation",
uuid=Base.UUID("02111abe-2050-1119-117e-b30112b5bdc4"),
path=joinpath(project_path, "ArtifactInstallation"),
path=path,
Copy link
Member

Choose a reason for hiding this comment

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

What were the errors you were seeing? I'm not sure why git_init_package() would have any different behavior here from copy_test_package()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reviewing. Pkg.add requires the package to be git version controlled because it always clones (it doesn't track the path directly like Pkg.develop does).

@00vareladavid 00vareladavid merged commit b9d1296 into master Apr 10, 2021
@00vareladavid 00vareladavid deleted the dv/2282 branch April 10, 2021 17:50
@DilumAluthge
Copy link
Member

DilumAluthge commented Jun 2, 2021

It looks like this PR made a breaking change in the public API:

On Julia 1.6.1:

julia> import Pkg

julia> Pkg.PackageSpec(; name = "Example", uuid = "7876af07-990d-54b4-ab0e-23690620f79a")
PackageSpec(
 name = Example
 uuid = 7876af07-990d-54b4-ab0e-23690620f79a
 version = *
)

On Julia master:

julia> import Pkg

julia> Pkg.PackageSpec(; name = "Example", uuid = "7876af07-990d-54b4-ab0e-23690620f79a")
ERROR: MethodError: Cannot `convert` an object of type String to an object of type Base.UUID
Closest candidates are:
 convert(::Type{T}, ::T) where T at essentials.jl:228
 Base.UUID(::AbstractString) at uuid.jl:87
 Base.UUID(::Any) at uuid.jl:9
Stacktrace:
 [1] convert(#unused#::Type{Union{Nothing, Base.UUID}}, x::String)
  @ Base ./some.jl:36
 [2] Pkg.Types.PackageSpec(name::String, uuid::String, version::Pkg.Versions.VersionSpec, tree_hash::Nothing, repo::Pkg.Types.GitRepo, path::Nothing, pinned::Bool, url::Nothing, rev::Nothing, subdir::Nothing)
  @ Pkg.Types ~/dev/repos/JuliaLang/julia/usr/share/julia/stdlib/v1.7/Pkg/src/Types.jl:92
 [3] Pkg.Types.PackageSpec(; name::String, uuid::String, version::Pkg.Versions.VersionSpec, tree_hash::Nothing, repo::Pkg.Types.GitRepo, path::Nothing, pinned::Bool, url::Nothing, rev::Nothing, subdir::Nothing)
  @ Pkg.Types ./util.jl:471
 [4] top-level scope
  @ REPL[1]:1

Is this easy to fix? Or should we revert this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The double constructor PackageSpec is very confusing
4 participants