Skip to content

Fix dev-ing package locally when [sources] include a repo source#4370

Closed
IanButterworth wants to merge 1 commit intoJuliaLang:masterfrom
IanButterworth:ib/4368
Closed

Fix dev-ing package locally when [sources] include a repo source#4370
IanButterworth wants to merge 1 commit intoJuliaLang:masterfrom
IanButterworth:ib/4368

Conversation

@IanButterworth
Copy link
Copy Markdown
Member

Fixes #4368

cc. @topolarity

Comment thread src/project.jl
subdir = get(source, "subdir", nothing)::Union{String, Nothing}
if path !== nothing && url !== nothing
pkgerror("`path` and `url` are conflicting specifications")
# When both path and url are specified, path takes precedence (for dev operations)
Copy link
Copy Markdown
Member

@KristofferC KristofferC Aug 21, 2025

Choose a reason for hiding this comment

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

This doesn't look right to me, you want the thing entered from the Pkg input to take precedence, or? At least, I think this condition should still never be hit.

@KristofferC
Copy link
Copy Markdown
Member

KristofferC commented Aug 21, 2025

I think this should maybe be handled in this function

Pkg.jl/src/API.jl

Lines 196 to 247 in e15974a

function update_source_if_set(env, pkg)
project = env.project
source = get(project.sources, pkg.name, nothing)
if source !== nothing
if pkg.repo == GitRepo()
delete!(project.sources, pkg.name)
else
# This should probably not modify the dicts directly...
if pkg.repo.source !== nothing
source["url"] = pkg.repo.source
delete!(source, "path")
end
if pkg.repo.rev !== nothing
source["rev"] = pkg.repo.rev
delete!(source, "path")
end
if pkg.repo.subdir !== nothing
source["subdir"] = pkg.repo.subdir
end
if pkg.path !== nothing
source["path"] = pkg.path
delete!(source, "url")
delete!(source, "rev")
end
end
if pkg.subdir !== nothing
source["subdir"] = pkg.subdir
end
path, repo = get_path_repo(project, pkg.name)
if path !== nothing
pkg.path = path
end
if repo.source !== nothing
pkg.repo.source = repo.source
end
if repo.rev !== nothing
pkg.repo.rev = repo.rev
end
if repo.subdir !== nothing
pkg.repo.subdir = repo.subdir
end
end
# Packages in manifest should have their paths set to the path in the manifest
for (path, wproj) in env.workspace
if wproj.uuid == pkg.uuid
pkg.path = Types.relative_project_path(env.manifest_file, dirname(path))
break
end
end
return
end
.

Basically, we should override the .path/.repo field if we have a different input from the Pkg operation.

Also, I have some recollection that maybe this is fixed on master?

@IanButterworth
Copy link
Copy Markdown
Member Author

Also, I have some recollection that maybe this is fixed on master?

Seems so, actually..

% julia +nightly test_issue_4368.jl                 
  Activating project at `/private/var/folders/1z/jf841bdj73bdj3vk7kc7f_3w0000gn/T/jl_83rHVu/test_project`
   Resolving package versions using PRESERVE_TIERED_INSTALLED...
    Updating `/private/var/folders/1z/jf841bdj73bdj3vk7kc7f_3w0000gn/T/jl_83rHVu/test_project/Project.toml`
  [7876af07] + Example v0.5.4 `/var/folders/1z/jf841bdj73bdj3vk7kc7f_3w0000gn/T/jl_83rHVu/Example`
    Updating `/private/var/folders/1z/jf841bdj73bdj3vk7kc7f_3w0000gn/T/jl_83rHVu/test_project/Manifest.toml`
  [7876af07] + Example v0.5.4 `/var/folders/1z/jf841bdj73bdj3vk7kc7f_3w0000gn/T/jl_83rHVu/Example`
Test Summary:                             | Pass  Total  Time
Issue #4368: dev with existing url source |    1      1  2.9s
using Pkg
using Test

# Test for issue #4368: Cannot `] dev` package locally when `[sources]` include a repo source

@testset "Issue #4368: dev with existing url source" begin
    mktempdir() do temp_dir
        # Create a test project
        project_path = joinpath(temp_dir, "test_project")
        mkpath(project_path)
        
        # Create Project.toml with a source that has a URL
        project_toml = joinpath(project_path, "Project.toml")
        write(project_toml, """
        name = "TestProject"
        uuid = "12345678-1234-1234-1234-123456789abc"
        version = "0.1.0"
        
        [deps]
        Example = "7876af07-990d-54b4-ab0e-23690620f79a"
        
        [sources]
        Example = {url = "https://github.com/JuliaLang/Example.jl", rev="main"}
        """)
        
        # Create a local copy of the package to dev
        local_pkg_path = joinpath(temp_dir, "Example")
        mkpath(joinpath(local_pkg_path, "src"))
        write(joinpath(local_pkg_path, "Project.toml"), """
        name = "Example"
        uuid = "7876af07-990d-54b4-ab0e-23690620f79a"
        version = "0.5.4"
        """)
        write(joinpath(local_pkg_path, "src", "Example.jl"), """
        module Example
        greet() = print("Hello World!")
        end
        """)
        
        # Try to dev the local package - this should work without conflict error
        cd(project_path) do
            Pkg.activate(".")
            # The key test is that this doesn't throw "conflicting specifications" error
            Pkg.develop(path=local_pkg_path)
            
            # Verify the package was successfully added as a development dependency
            @test haskey(Pkg.project().dependencies, "Example")
        end
    end
end

@github-project-automation github-project-automation Bot moved this from In progress to Done in Pkg.jl Aug 21, 2025
@IanButterworth IanButterworth deleted the ib/4368 branch August 21, 2025 14:43
@KristofferC
Copy link
Copy Markdown
Member

KristofferC commented Aug 21, 2025

IIRC, #4225 fixed it. That part of the PR should be backported to 1.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Cannot ] dev package locally when [sources] include a repo source

2 participants