# Package extension for data-specific (unregister) package to use - how to add the extension?

**URL:** <https://discourse.julialang.org/t/package-extension-for-data-specific-unregister-package-to-use-how-to-add-the-extension/114835>\
**Category:** General Usage\
**Created:** [May 28, 2024, 12:41pm UTC](https://discourse.julialang.org/t/package-extension-for-data-specific-unregister-package-to-use-how-to-add-the-extension/114835 "2024-05-28T12:41:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [May 28, 2024, 12:41pm UTC](https://discourse.julialang.org/t/package-extension-for-data-specific-unregister-package-to-use-how-to-add-the-extension/114835/1 "2024-05-28T12:41:23Z")

</div>

Package extensions are typically used when the user of a package may or may not already have a certain functionality-provided package installed in his own environment.  
But how can I use them instead as a conditional dependency of a certain package, depending on data ?

Let me explain:

I have a model `GenFSM` where at a certain point it needs to get the functionality of another package that is specified in the data (in the real application, this is an initialization of forest resources for the region specified in the settings).

So, I thought to use a Package extension for this (these) region-specific packages.

My code is as follows;

src/GenFSM.jl

```julia
module GenFSM
export run

function run()
    resource_init_regions = ["fr"] # loaded from scenario specific data
    for reg in resource_init_regions
        toimport = "GenFSM_resource_init_$reg" # name of the package dealing with the initialization for this region
        expr = Meta.parse("import $toimport")
        eval(expr)
        tocall = "resource_init_$reg"
        getfield(GenFSM, Symbol(tocall))()
    end
end

end # module GenFSM

```

ext/ResourceInitFrExt.jl:

```julia
"""
    ResourceInitFrExt

Extension module for initilising the Resource module for France
"""
module ResourceInitFrExt 

using GenFSM, GenFSM_resource_init_fr

function GenFSM.resource_init_fr()
    # Do the initialization by calling the init function in the package GenFSM_resources_fr
    println("hello")
end

end # module

```

GenFSM Project.toml:

```julia
[weakdeps]
GenFSM_resources_init_fr = "78598d3f-d65b-4630-9136-a3bfe5c9de2f"

[extensions]
ResourceInitFrExt = "GenFSM_resources_init_fr"

```

My questions:

a. Is this approach idiomatic, or there is a better approach to selectively load and use a package that is data-dependant ?  
b. Running the code above, I have the error:

```julia
ERROR: ArgumentError: Package GenFSM does not have GenFSM_resource_init_fr in its dependencies:
- You may have a partially installed environment. Try `Pkg.instantiate()`
  to ensure all packages in the environment are installed.
- Or, if you have GenFSM checked out for development and have
  added GenFSM_resource_init_fr as a dependency but haven't updated your primary
  environment's manifest file, try `Pkg.resolve()`.
- Otherwise you may need to report an issue with GenFSM

```

How can I add the (unregistered) package used in the extension to `GenFSM` ?  
If I add it with `add` it will be installed as a “normal” dependency…
