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

**URL:** <https://discourse.julialang.org/t/pkg-projects-is-it-possible-to-subsititute-packages-in-a-project/16460>\
**Category:** General Usage\
**Created:** [October 17, 2018, 7:01pm UTC](https://discourse.julialang.org/t/pkg-projects-is-it-possible-to-subsititute-packages-in-a-project/16460 "2018-10-17T19:01:21Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![galenlynch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galenlynch/32/17947_2.png) [@galenlynch](https://discourse.julialang.org/u/galenlynch)\
**Post date:** [October 17, 2018, 7:01pm UTC](https://discourse.julialang.org/t/pkg-projects-is-it-possible-to-subsititute-packages-in-a-project/16460/1 "2018-10-17T19:01:21Z")

</div>

I am trying to deploy my code on a bunch of other machines using a [project](https://docs.julialang.org/en/v1/stdlib/Pkg/index.html#Creating-your-own-projects-1). 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 `develop`ing 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?

---

<div class="post-metadata">

**Author:** ![adamslc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamslc/32/3452_2.png) [@adamslc](https://discourse.julialang.org/u/adamslc)\
**Post date:** [October 17, 2018, 7:16pm UTC](https://discourse.julialang.org/t/pkg-projects-is-it-possible-to-subsititute-packages-in-a-project/16460/2 "2018-10-17T19:16:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![galenlynch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galenlynch/32/17947_2.png) [@galenlynch](https://discourse.julialang.org/u/galenlynch)\
**Post date:** [October 17, 2018, 7:25pm UTC](https://discourse.julialang.org/t/pkg-projects-is-it-possible-to-subsititute-packages-in-a-project/16460/3 "2018-10-17T19:25:16Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![galenlynch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galenlynch/32/17947_2.png) [@galenlynch](https://discourse.julialang.org/u/galenlynch)\
**Post date:** [October 17, 2018, 7:36pm UTC](https://discourse.julialang.org/t/pkg-projects-is-it-possible-to-subsititute-packages-in-a-project/16460/4 "2018-10-17T19:36:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zgornel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zgornel/32/217487_2.png) [@zgornel](https://discourse.julialang.org/u/zgornel)\
**Post date:** [October 17, 2018, 7:44pm UTC](https://discourse.julialang.org/t/pkg-projects-is-it-possible-to-subsititute-packages-in-a-project/16460/5 "2018-10-17T19:44:51Z")

</div>

> [@galenlynch](#):
>
> 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 `develop` ing the package

Yes; use in in Pkg mode:

> add [https://github.com/your\_username/DSP.jl#your\_branch](https://github.com/your_username/DSP.jl#your_branch)

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).

---

<div class="post-metadata">

**Author:** ![galenlynch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galenlynch/32/17947_2.png) [@galenlynch](https://discourse.julialang.org/u/galenlynch)\
**Post date:** [October 17, 2018, 7:49pm UTC](https://discourse.julialang.org/t/pkg-projects-is-it-possible-to-subsititute-packages-in-a-project/16460/6 "2018-10-17T19:49:41Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![zgornel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zgornel/32/217487_2.png) [@zgornel](https://discourse.julialang.org/u/zgornel)\
**Post date:** [October 17, 2018, 8:19pm UTC](https://discourse.julialang.org/t/pkg-projects-is-it-possible-to-subsititute-packages-in-a-project/16460/7 "2018-10-17T20:19:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![galenlynch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galenlynch/32/17947_2.png) [@galenlynch](https://discourse.julialang.org/u/galenlynch)\
**Post date:** [October 17, 2018, 8:56pm UTC](https://discourse.julialang.org/t/pkg-projects-is-it-possible-to-subsititute-packages-in-a-project/16460/8 "2018-10-17T20:56:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [October 17, 2018, 8:59pm UTC](https://discourse.julialang.org/t/pkg-projects-is-it-possible-to-subsititute-packages-in-a-project/16460/9 "2018-10-17T20:59:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![galenlynch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galenlynch/32/17947_2.png) [@galenlynch](https://discourse.julialang.org/u/galenlynch)\
**Post date:** [October 17, 2018, 9:13pm UTC](https://discourse.julialang.org/t/pkg-projects-is-it-possible-to-subsititute-packages-in-a-project/16460/10 "2018-10-17T21:13:39Z")

</div>

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`:

```julia
(GLEphys) pkg> free DSP
 Resolving package versions...
  Updating `~/.julia/environments/GLEphys/Project.toml`
  [717857b8] ↓ DSP v0.5.1+ #my-changes (git@bitbucket.org:feelab/dsp.jl.git) ⇒ v0.5.1
  Updating `~/.julia/environments/GLEphys/Manifest.toml`
  [717857b8] ↓ DSP v0.5.1+ #my-changes (git@bitbucket.org:feelab/dsp.jl.git) ⇒ 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.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [October 17, 2018, 9:40pm UTC](https://discourse.julialang.org/t/pkg-projects-is-it-possible-to-subsititute-packages-in-a-project/16460/11 "2018-10-17T21:40:59Z")

</div>

> [@galenlynch](#):
>
> FWIW adding the package with the spoofed UUID sees to work well with `free` :

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?

---

<div class="post-metadata">

**Author:** ![galenlynch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galenlynch/32/17947_2.png) [@galenlynch](https://discourse.julialang.org/u/galenlynch)\
**Post date:** [October 17, 2018, 10:11pm UTC](https://discourse.julialang.org/t/pkg-projects-is-it-possible-to-subsititute-packages-in-a-project/16460/12 "2018-10-17T22:11:46Z")

</div>

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.
