Pkg projects: Is it possible to subsititute packages in a project?

I am trying to deploy my code on a bunch of other machines using a project. My code depends on a pull request that I’ve made against DSP.jl, but has not been merged. I would like all code that depends on DSP.jl to instead use the code in the pull request. While I can figure out how to do this by developing the package locally, and then checking out my branch, I haven’t been able to substitute the official package repository with my own only using the project file.

Is it possibe to add a package using Pkg, while changing the URL that will be used to download it?

The Project.toml does not record any information about where it found the packages, although there is an open issue for this. You could also include Manifest.toml, and things might work better.

@adamslc Yeah I’m also using the Manifest.toml to add my code to other machines, but I didn’t know how to arrange for DSP.jl to use my repository instead of the official one. Just adding the url by itself would make a new entry in Project.toml with a different UUID.

I think I figured it out…?

julia> using Pkg
julia> ps = PackageSpec(
    name = "DSP", 
    uuid = "717857b8-e6f2-59f4-9121-6e50c889abd2", # UUID for DSP.jl in General Registry
    url = "", # My fork's URL
    rev = "my-changes" # The branch I want to use
PackageSpec(name=DSP, uuid=717857b8-e6f2-59f4-9121-6e50c889abd2, url/path="", rev=my-changes)
julia> Pkg.add(ps)
  Updating registry at `~/.julia/registries/Galen`
  Updating git-repo ``
  Updating registry at `~/.julia/registries/General`
  Updating git-repo ``
  Updating git-repo ``
 Resolving package versions...
  Updating `~/.julia/environments/GLEphys/Project.toml`
  [717857b8] + DSP v0.5.1+ #my-changes (
  Updating `~/.julia/environments/GLEphys/Manifest.toml`
  [717857b8] ↑ DSP v0.5.1 ⇒ v0.5.1+ #my-changes (

Yeah that seems to work: copying the Project.toml and Manifest.toml to another machine and instantiating the project downloads code from my branch instead of the official one.

Yes; use in in Pkg mode:


It will keep tracking that branch. Make sure to distribute the Project.toml file to all local machines that use your branch (it does not have to be uploaded remotely).

@zgornel It seems like that gives my branch a new UUID, so other packages depending on DSP.jl would not use my branch. At least that’s what I was seeing when I tried that. You have to also spoof the UUID for it to work as intended.

Indeed. Unless the new branch is explicitly used in other packages i.e. added in Project.toml I do not think it is possible to use it.

I think I figured out how to do it in the post above. If you add a package using PackageSpec with the branch and URL of your choosing, while also specifying the UUID of the original package that is used by dependent packages, then dependent packages will use the new branch.

Once that PR gets merged though, you’re going to have to set the old URL as the location of the package again, to properly receive updates from upstream again. I’m almost certain there’s a better way to do this, but I’m not able to check thoroughly at the moment (maybe dev that fork with the branch instead and free once the PR is merged?).

Or just wait for the branch to be merged.

I was hoping to avoid having to dev the package, go in to the dev folder, add my remote, and checkout the branch.

FWIW adding the package with the spoofed UUID sees to work well with free:

(GLEphys) pkg> free DSP
 Resolving package versions...
  Updating `~/.julia/environments/GLEphys/Project.toml`
  [717857b8] ↓ DSP v0.5.1+ #my-changes ( ⇒ v0.5.1
  Updating `~/.julia/environments/GLEphys/Manifest.toml`
  [717857b8] ↓ DSP v0.5.1+ #my-changes ( ⇒ v0.5.1

The PR has been sitting for months, I need to run analyses using a bunch of computers sooner rather than later, and can’t wait months longer.

It works insofar you’re no longer tracking that specific branch of your fork but the master of your fork - as I understand, you’d want to revert back to the original package git source once that PR is merged, which is why I suggested dev and subsequent free in the first place.

I haven’t checked your PR, but have you tried bumping it, in case the author missed it?

Yes I would like to revert back to the original package URL once the PR is merged. I can’t really tell what the impact of free is after I add the package with a different URL… in fact I realize that I don’t know which folder under the package directory is being used by my project.

I have tried bumping, but things are just slow in open source projects.