# Repo corresponding to package in environment

**URL:** <https://discourse.julialang.org/t/repo-corresponding-to-package-in-environment/96791>\
**Category:** Package Management\
**Tags:** question\
**Created:** [March 29, 2023, 5:27pm UTC](https://discourse.julialang.org/t/repo-corresponding-to-package-in-environment/96791 "2023-03-29T17:27:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![airpmb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/airpmb/32/7826_2.png) [@airpmb](https://discourse.julialang.org/u/airpmb)\
**Post date:** [March 29, 2023, 5:27pm UTC](https://discourse.julialang.org/t/repo-corresponding-to-package-in-environment/96791/1 "2023-03-29T17:27:19Z")

</div>

Is there some way to go from the name of a package in the current environment, to the GitHub repo that it ultimately came from? I mean in the case of a package that is currently coming from a registry, not one that is explicitly specified as a repo in an `add` or `dev`.

Clearly Pkg at some point works this out when you do an `add` or `update`, and I wonder if it’s possible to hook into whatever it’s doing. If the API already has something for this I’ve missed it somehow.

The motivation is that I’d like to explore making some tooling to extract useful info from a given package’s repo, without priori knowing what that repo is.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [March 29, 2023, 6:39pm UTC](https://discourse.julialang.org/t/repo-corresponding-to-package-in-environment/96791/2 "2023-03-29T18:39:45Z")

</div>

Pkg doesn’t have a public API for this and I wouldn’t recommend depending on the internals since they tend to be a moving target. Instead you can use [GitHub - GunnarFarneback/RegistryInstances.jl: Access the information in installed Julia registries.](https://github.com/GunnarFarneback/RegistryInstances.jl), which basically is a snapshot of the registry functionality of Pkg. It’s no better documented than Pkg so you need to figure out some things yourself.

Some pointers along the way:

- `Base.active_project` can give you the path to the current environment.
- Use the `TOML` stdlib to read `Project.toml` / `Manifest.toml`.
- `RegistryInstances.reachable_registries()` loads your currently installed registries into memory.
- `RegistryInstances.registry_info(pkg)` extracts information about a package, including its repository.

---

<div class="post-metadata">

**Author:** ![airpmb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/airpmb/32/7826_2.png) [@airpmb](https://discourse.julialang.org/u/airpmb)\
**Post date:** [March 29, 2023, 7:50pm UTC](https://discourse.julialang.org/t/repo-corresponding-to-package-in-environment/96791/3 "2023-03-29T19:50:42Z")

</div>

Thanks! That’s very helpful:

```julia
using RegistryInstances
function package_repo(pkgname)
    rr = reachable_registries()
    for reg_instance in rr
        for pkg in reg_instance.pkgs
            if pkg.second.name == pkgname
                found = true
                ri = registry_info(pkg.second)
                return ri.repo
            end
        end
    end
    throw(ErrorException("Could not find package $pkgname"))
end

```

```julia
julia> package_repo("RegistryInstances")
"https://github.com/GunnarFarneback/RegistryInstances.jl.git"

```

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [March 29, 2023, 8:01pm UTC](https://discourse.julialang.org/t/repo-corresponding-to-package-in-environment/96791/4 "2023-03-29T20:01:46Z")

</div>

If you want to be thorough you should take the possibility of multiple packages with the same name into account. Then you need to look up the UUID from your environment and use that as key to the registry instances. Potentially you could also find the same package in multiple registries, possibly with different repo URLs.

If you don’t have a need to cover those possibilities, your function is fine.

---

<div class="post-metadata">

**Author:** ![airpmb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/airpmb/32/7826_2.png) [@airpmb](https://discourse.julialang.org/u/airpmb)\
**Post date:** [March 29, 2023, 11:07pm UTC](https://discourse.julialang.org/t/repo-corresponding-to-package-in-environment/96791/5 "2023-03-29T23:07:04Z")

</div>

Yep, makes sense. Also, in the meantime I stumbled on this which looks like it already has what I need: [GitHub - JuliaEcosystem/PackageAnalyzer.jl](https://github.com/JuliaEcosystem/PackageAnalyzer.jl)

---

<div class="post-metadata">

**Author:** ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)\
**Post date:** [March 29, 2023, 11:39pm UTC](https://discourse.julialang.org/t/repo-corresponding-to-package-in-environment/96791/6 "2023-03-29T23:39:01Z")

</div>

There is also the [pkg\_site](https://github.com/simonp0420/PkgOnlineHelp.jl#pkg_site) function from the `PkgOnlineHelp` package.
