# Convert REQUIRE to Project.toml and Manifest.toml

**URL:** https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775
**Category:** New to Julia
**Tags:** packages
**Created:** [November 20, 2018, 2:25pm UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775 "2018-11-20T14:25:32Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![armstrtw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/armstrtw/32/5978_2.png) [@armstrtw](https://discourse.julialang.org/u/armstrtw)
#### Post date: [November 20, 2018, 2:25pm UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/1 "2018-11-20T14:25:32Z")

</div>

Is there a standard process or function that allows one to upgrade old packages using the REQUIRE file to the new package format using Project.toml and Manifest.toml ?

Apologies if I missed this documentation online.

---

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [November 21, 2018, 12:12am UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/2 "2018-11-21T00:12:04Z")

</div>

This is what I do:

1. Steal the format from an existing Project.toml, e.g. [https://github.com/JuliaLang/Pkg.jl/blob/master/Project.toml](https://github.com/JuliaLang/Pkg.jl/blob/master/Project.toml), and create your own Project.toml in your repository.
2. You probably only need “name” and “uuid” in the top section, so you can delete the rest or change it for your package if you want.
3. Replace the package name there with your package name.
4. Get a uuid for your package using `using Pkg; Pkg.METADATA_compatible_uuid(pkg_name)` where `pkg_name` is the name of your package as a `String` without `.jl` (watch your spelling!).
5. Replace the uuid in the Project.toml and delete the list of deps there, keeping the header. Save the file!
6. `cd` into the repository of the package, most likely in your `.julia/dev/pkg_name` folder.
7. In a Julia session, run `]activate .`
8. Open the REQUIRE file in another window.
9. Run `]add dep_name` for all your dependencies in the REQUIRE file. This will automatically update the Project.toml and Manifest.toml, creating the latter if it doesn’t exit.
10. You may want to add an extra `[compat]` section as shown in [Pkg · The Julia Language](https://docs.julialang.org/en/v1/stdlib/Pkg/index.html#Compatibility-1) to support certain versions of packages or Julia.
11. Add your test dependencies as well and then copy the test deps’ lines from the Project.toml file’s `[deps]` section to the `[extras]` section, and list the package names in the `[targets]` section as shown in [https://github.com/KristofferC/JuAFEM.jl/blob/master/Project.toml](https://github.com/KristofferC/JuAFEM.jl/blob/master/Project.toml).

And now you should be having Project.toml and Manifest.toml files in your repo. Apparently, you still need to keep your REQUIRE files there for registered packages. Anyways after doing the above, you can close that Julia session and open a new one in the default `v1.0` environment, and pretend like none of this had to happen. Hopefully, some expert can correct me if I got something off.

---

<div class="post-metadata">

### Author: ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)
#### Post date: [November 21, 2018, 8:41am UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/3 "2018-11-21T08:41:03Z")

</div>

Here is my quick-and-dirty Julia function to automate a similar workflow:

```julia
"""
    generate_project_toml([name::String])

Generate Project.toml file for the existing current project at `\$PWD`.
It activates the generated Project.toml and then adds packages based on
REQUIRE file.
"""
function generate_project_toml(name::AbstractString = guess_project_name())
    if isfile("Project.toml")
        error("Project.toml exists.")
    end

    if !isfile("REQUIRE")
        error("REQUIRE file not found.")
    end
    deps = read_require("REQUIRE")

    pkg = Base.identify_package(name)
    project_toml = """
    name = $(repr(name))
    uuid = "$(pkg.uuid)"
    """
    write("Project.toml", project_toml)

    @info "Activating \$PWD (to run `Pkg.add`)"
    Pkg.activate(pwd())
    Pkg.add(deps)
end

"""
    guess_project_name() :: String

Guess project name using Git. It works even in worktree repository.
"""
function guess_project_name()
    path = abspath(rstrip(read(`git rev-parse --git-dir`, String)))
    prev = ""
    while path != prev
        if basename(path) == ".git"
            return basename(dirname(path))
        end
        prev, path = path, dirname(path)
    end
    error("Project not found")
end

function read_require(path)
    deps = String[]
    for line in readlines(path)
        name, = split(line)
        if name == "julia"
            continue
        end
        push!(deps, name)
    end
    return deps
end

```

---

<div class="post-metadata">

### Author: ![dehann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dehann/32/2003_2.png) [@dehann](https://discourse.julialang.org/u/dehann)
#### Post date: [February 11, 2019, 4:04pm UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/4 "2019-02-11T16:04:54Z")

</div>

I used tkf’s functions (thanks!), but had to ask for more help to resolve “core” package dependency issues including LinearAlgebra, Statistics, Random, Test, etc. Maybe it has already been mentioned somewhere but I missed it. Turns out the fix is easy and just noting it here for documentation’s sake:

Start Julia with working directory in the project repo, for example `cd ~/.julia/dev/MyPkg`. After running `generate_project_toml("MyPkg")` here, open the package manager `]`; then type `activate .`. This should show `(MyPkg) pkg>`, and now add the missing packages such as `add LinearAlgebra Statistics ...`. This will append to the `deps` section in Project.toml and resolve issues you might discover in Travis.

Aside: make sure the `MyPkg/.travis.yml` file is also updated to the newer `script:` format:

> <https://github.com/JuliaLang/Pkg.jl/blob/e8414f1a2409b31a0b10859894ec0cbe11f2a85d/.travis.yml#L32>

---

<div class="post-metadata">

### Author: ![Wikunia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wikunia/32/2180_2.png) [@Wikunia](https://discourse.julialang.org/u/Wikunia)
#### Post date: [April 18, 2019, 2:24pm UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/5 "2019-04-18T14:24:12Z")

</div>

Can you specify on point 10? I can’t find anything about `[compat]` in that link

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [April 18, 2019, 2:25pm UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/6 "2019-04-18T14:25:21Z")

</div>

[https://julialang.github.io/Pkg.jl/v1/compatibility/](https://julialang.github.io/Pkg.jl/v1/compatibility/)

---

<div class="post-metadata">

### Author: ![arumugamav](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arumugamav/32/7654_2.png) [@arumugamav](https://discourse.julialang.org/u/arumugamav)
#### Post date: [July 30, 2019, 4:34am UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/7 "2019-07-30T04:34:12Z")

</div>

Please guide me in constructing site Project.toml from packages, Project.toml!

---

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [July 30, 2019, 11:22am UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/8 "2019-07-30T11:22:28Z")

</div>

This is how I did it:

> [@Switching package registration systems soon](https://discourse.julialang.org/t/switching-package-registration-systems-soon/22677/106):
>
> Here’s a script that can generate a project file for a package with a REQUIRE file: [https://github.com/JuliaLang/Pkg.jl/pull/1133/files](https://github.com/JuliaLang/Pkg.jl/pull/1133/files) You call it with ARGS as directories where packages live. If the first argument is -f then it will overwrite existing Project.toml files, otherwise it will refuse to do so. It generates a [compat] section that approximates the bounds in the REQUIRE file as closely as possible, but unfortunately since the [compat] section doesn’t support version ranges this tra…

---

<div class="post-metadata">

### Author: ![arumugamav](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arumugamav/32/7654_2.png) [@arumugamav](https://discourse.julialang.org/u/arumugamav)
#### Post date: [August 1, 2019, 4:36am UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/9 "2019-08-01T04:36:25Z")

</div>

Thanks!  
I already have Project.toml in my package folders.  
(ie. /opt/julia/julia-1.1.0/share/julia/stdlib/v1.1/\<PACKAGE\_NAME\>/Project.toml files are there)  
But I don’t have user level/host level Project.toml and Manifest.toml (ie.“/opt/julia/julia-1.1.0/share/julia/stdlib/v1.1/Project.toml” or /home/ava/.julia/)

May I request your guidance to construct consolidated single Project.toml and Manifest.toml at host level!

---

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [August 1, 2019, 10:50am UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/10 "2019-08-01T10:50:29Z")

</div>

Not sure I understand exactly what you’re looking for, but if you mean getting them for your global environment, it’s as simple as `] add OhMyREPL` (or whatever packages you want). Alternatively,

```julia
julia> using Pkg

julia> Pkg.add("OhMyREPL")

```

See [here](https://docs.julialang.org/en/v1/stdlib/Pkg/) and [here](https://julialang.github.io/Pkg.jl/v1/).

---

<div class="post-metadata">

### Author: ![arumugamav](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arumugamav/32/7654_2.png) [@arumugamav](https://discourse.julialang.org/u/arumugamav)
#### Post date: [August 2, 2019, 4:59am UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/11 "2019-08-02T04:59:50Z")

</div>

Thanks!

It is observed that output of  
pkg\>status  
…  
[34da2185] Compat v1.4.0  
[31c24e10] Distributions v0.16.4  
[2fe49d83] Expectations v1.0.2  
[28b8d3ca] GR v0.36.0  
[7073ff75] IJulia v1.14.1  
[43edad99] InstantiateFromURL v0.1.0  
[a98d9a8b] Interpolations v0.11.0  
[d96e819e] Parameters v0.10.2  
[91a5bcdd] Plots v0.21.0  
[fcd29c91] QuantEcon v0.15.0  
[295af30f] Revise v0.7.13

What is the 8 character alpha-numeric string preceding package name and how it is arrived?

---

<div class="post-metadata">

### Author: ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)
#### Post date: [August 2, 2019, 6:01am UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/12 "2019-08-02T06:01:09Z")

</div>

It’s the first part of the [UUID](https://de.wikipedia.org/wiki/Universally_Unique_Identifier) of a package, see [the Pkg.jl documentation](https://julialang.github.io/Pkg.jl/v1/glossary/# **8.** -Glossary-1) for more information. Parameters.jl, for example, has the UUID `d96e819e-fc66-5662-9728-84c9c7592b0a` ([Project.toml)](https://github.com/JuliaRegistries/General/blob/master/P/Parameters/Package.toml).

You can find a package’s UUID by looking it up in the [general registry](https://github.com/JuliaRegistries/General). To generate a UUID, you can use

```julia
julia> using Pkg

julia> Pkg.METADATA_compatible_uuid("MyPackage.jl")
UUID("7bec01f6-6e58-5d42-b8c7-b05f3435ceef")

```

---

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [August 2, 2019, 11:18am UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/13 "2019-08-02T11:18:09Z")

</div>

Alternatively, if you don’t need your package to work on julia prior to v1.0:

```julia
julia> using UUIDs

julia> uuid4()

```

---

<div class="post-metadata">

### Author: ![astadmistry](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/astadmistry/32/17299_2.png) [@astadmistry](https://discourse.julialang.org/u/astadmistry)
#### Post date: [September 3, 2020, 2:22am UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/14 "2020-09-03T02:22:38Z")

</div>

I have updated the script to work with Julia 1.5  
When I ran the script, I was getting:

ERROR: LoadError: type Nothing has no field uuid

```julia
import Pkg
import Base: SHA1
using SHA, UUIDs

function uuid5(namespace::UUID, key::String)
    data = [reinterpret(UInt8, [namespace.value]); codeunits(key)]
    u = reinterpret(UInt128, sha1(data)[1:16])[1]
    u &= 0xffffffffffff0fff3fffffffffffffff
    u |= 0x00000000000050008000000000000000
    return UUID(u)
end

uuid5(namespace::UUID, key::AbstractString) = uuid5(namespace, String(key))

const uuid_dns = UUID(0x6ba7b810_9dad_11d1_80b4_00c04fd430c8)
const uuid_julia_project = uuid5(uuid_dns, "julialang.org")
const uuid_package = uuid5(uuid_julia_project, "package")

"""
    generate_project_toml([name::String])

Generate Project.toml file for the existing current project at `\$PWD`.
It activates the generated Project.toml and then adds packages based on
REQUIRE file.
"""
function generate_project_toml(name::AbstractString = guess_project_name())
    pkg_UUID = uuid5(uuid_package, name)
    if isfile("Project.toml")
        error("Project.toml exists.")
    end

    if !isfile("REQUIRE")
        error("REQUIRE file not found.")
    end
    deps = read_require("REQUIRE")

    pkg = Base.identify_package(name)
    project_toml = """
    name = $(repr(name))
    uuid = "$(pkg_UUID)"
    """
    write("Project.toml", project_toml)

    @info "Activating \$PWD (to run `Pkg.add`)"
    Pkg.activate(pwd())
    Pkg.add(deps)
end

"""
    guess_project_name() :: String

Guess project name using Git. It works even in worktree repository.
"""
function guess_project_name()
    path = abspath(rstrip(read(`git rev-parse --git-dir`, String)))
    prev = ""
    while path != prev
        if basename(path) == ".git"
            return basename(dirname(path))[1:end-3]
        end
        prev, path = path, dirname(path)
    end
    error("Project not found")
end

function read_require(path)
    deps = String[]
    for line in readlines(path)
        name, = split(line)
        if name == "julia"
            continue
        end
        push!(deps, name)
    end
    return deps
end

```

[Github gist of above script](https://gist.github.com/astadmistry/cbaba31771a8b20bed4ca163cf65061a)

REF:  
[`https://github.com/JuliaLang/Pkg.jl/commit/34ec22f5405ffc7f8f25a4b4f7178e887f718051`](https://github.com/JuliaLang/Pkg.jl/commit/34ec22f5405ffc7f8f25a4b4f7178e887f718051)  
[`https://github.com/JuliaLang/Pkg.jl/blob/34ec22f5405ffc7f8f25a4b4f7178e887f718051/src/Types.jl`](https://github.com/JuliaLang/Pkg.jl/blob/34ec22f5405ffc7f8f25a4b4f7178e887f718051/src/Types.jl)  
[`https://github.com/JuliaLang/Pkg.jl/search?p=1&q=gen_project.jl&type=Issues`](https://github.com/JuliaLang/Pkg.jl/search?p=1&q=gen_project.jl&type=Issues)

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [September 3, 2020, 9:00am UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/15 "2020-09-03T09:00:23Z")

</div>

Scripts like the above rely on internals and will inevitably break over time.

Given that it is 2 years past the release of Julia 1.0, generating the `Project.toml` with a series of `pkg> add`s for the odd package that has not been ported yet may be the best approach.

---

<div class="post-metadata">

### Author: ![astadmistry](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/astadmistry/32/17299_2.png) [@astadmistry](https://discourse.julialang.org/u/astadmistry)
#### Post date: [September 16, 2020, 2:20pm UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/16 "2020-09-16T14:20:04Z")

</div>

The above script is…

> [@Tamas\_Papp](#):
>
> generating the `Project.toml` with a series of `pkg> add` s for the odd package that has not been ported

as seen on [line 48](https://gist.github.com/astadmistry/cbaba31771a8b20bed4ca163cf65061a#file-gen_project-jl-L48)

The vast majority of the script is to produce a UUID which is backwards compatible for versions of julia prior to v1.0

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [September 18, 2020, 8:29am UTC](https://discourse.julialang.org/t/convert-require-to-project-toml-and-manifest-toml/17775/17 "2020-09-18T08:29:06Z")

</div>

Sorry, I don’t understand what you want to convey here. My point was that even if the script no longer works (for whatever reason), generating a project file manually is a reasonable alternative, especially since it is only rarely needed these days as the majority of maintained packages did it already.

Also, keep in mind that [for the General registry, you need `[compat]` bounds](https://github.com/JuliaRegistries/General#automatic-merging-of-pull-requests) in any case, which need to be given some thought.

The bottom line is that reviving packages that missed the transition to Julia 1.0 may be tricky to automate at this point, but at the same time it is still fairly easy to do it manually.
