# Canonical way to check if a project is a package?

**URL:** <https://discourse.julialang.org/t/canonical-way-to-check-if-a-project-is-a-package/90827>\
**Category:** Package Management\
**Tags:** package, pkg, project\
**Created:** [November 25, 2022, 8:14pm UTC](https://discourse.julialang.org/t/canonical-way-to-check-if-a-project-is-a-package/90827 "2022-11-25T20:14:52Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [November 25, 2022, 9:20pm UTC](https://discourse.julialang.org/t/canonical-way-to-check-if-a-project-is-a-package/90827/2 "2022-11-25T21:20:10Z")

</div>

This is quite possibly too naive a thought but:

> [@grahamas](#):
>
> I need to make sure that file defines a module with the same name

Could you try activating the `Project.toml` for that given project or package (let’s say the name is `YourPackage`) and then run the following snippet:

```julia
try 
    using YourPackage
    using Pkg

    pkg_name = "YourPackage"
    m = Pkg.Operations.Context().env.manifest

    v_key = findfirst(v->v.name == pkg_name, m)
    if isnothing(v_key)
        error("Version not found! Is this a valid Julia package?")
    else
        v = m[v_key].version
        println("Package version is $v")
     end
catch e
    println("$e: Is this a valid Julia package?")
end

```

This solution was inspired by a stack overflow post here: [julia - Determine version of a specific package - Stack Overflow](https://stackoverflow.com/questions/25635508/determine-version-of-a-specific-package)

It does assume a manifest exists for the environment however so that may derail this solution potentially. To my understanding, this would at least solve b), for a) maybe see this discourse post for more: [How to test if package is installed - #4 by Tamas\_Papp](https://discourse.julialang.org/t/how-to-test-if-package-is-installed/3508/4) and this one: [Test for existence of a variable - #39 by Tamas\_Papp](https://discourse.julialang.org/t/test-for-existence-of-a-variable/42845/39) for c) I would say that the checks may have to be up to more how you structure or want to administrate your local registry… I would say that could be sufficient personally, but I haven’t run a registry myself yet. 😛

---

_[View the full topic](https://discourse.julialang.org/t/canonical-way-to-check-if-a-project-is-a-package/90827)._
