# About extension support

**URL:** <https://discourse.julialang.org/t/about-extension-support/93462>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [January 24, 2023, 3:00pm UTC](https://discourse.julialang.org/t/about-extension-support/93462 "2023-01-24T15:00:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rratic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rratic/32/24917_2.png) [@Rratic](https://discourse.julialang.org/u/Rratic)\
**Post date:** [January 24, 2023, 3:00pm UTC](https://discourse.julialang.org/t/about-extension-support/93462/1 "2023-01-24T15:00:00Z")

</div>

I’m developing a Julia package that supports extensions. Currently I need to know:

1. Where should I store extension data locally? Store as artifacts, store in scratchspaces or somewhere else?
2. For the code in extensions, should I write plain code and use `include` (with return value so that I can better manage) or wrap code in a module?
3. To manage the extensions, I guess I need something like the Julia-Package system (but obviously not the real one). How can I use `Pkg` to manage those things (extensions may use other extensions and real packages), or should I build a system myself?
4. Are there any known ways (maybe design a special architecture?) to smoothly ban/disable/remove the effect of loaded code (like vscode)?
5. If I’m going to pre-compile the main package and extensions (for standalone software release or something else), what do I need to notice in extension-architecture design to let this process smooth?

I know there are really a lot of complicated things, but you can answer the questions one by one or simply post your thoughts. Thanks for your help~

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 24, 2023, 3:05pm UTC](https://discourse.julialang.org/t/about-extension-support/93462/2 "2023-01-24T15:05:55Z")

</div>

> [@Rratic](#):
>
> To manage the extensions, I guess I need something like the Julia-Package system (but obviously not the real one). How can I use `Pkg` to manage those things (extensions may use other extensions and real packages), or should I build a system myself?

> [@Rratic](#):
>
> - Are there any known ways (maybe design a special architecture?) to smoothly ban/disable/remove the effect of loaded code (like vscode)?

Pkg.jl added this as a feature in v1.9. It’s documented here:

[https://pkgdocs.julialang.org/dev/creating-packages/#Weak-dependencies](https://pkgdocs.julialang.org/dev/creating-packages/#Weak-dependencies)

Here’s an example of using it in the wild:

> <https://github.com/SciML/DiffEqBase.jl/pull/856>

> [@Rratic](#):
>
> - For the code in extensions, should I write plain code and use `include` (with return value so that I can better manage) or wrap code in a module?

Extensions need to be modules.

> [@Rratic](#):
>
> If I’m going to pre-compile the main package and extensions (for standalone software release or something else), what do I need to notice in extension-architecture design to let this process smooth?

Using Pkg’s built-in extensions supports (parallel) precompilation.

> [@Rratic](#):
>
> - Where should I store extension data locally? Store as artifacts, store in scratchspaces or somewhere else?

For data artifacts, I would probably use DataDeps.jl?

---

<div class="post-metadata">

**Author:** ![Rratic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rratic/32/24917_2.png) [@Rratic](https://discourse.julialang.org/u/Rratic)\
**Post date:** [January 24, 2023, 3:07pm UTC](https://discourse.julialang.org/t/about-extension-support/93462/3 "2023-01-24T15:07:42Z")

</div>

Good to hear that. (sorry that I just noticed the new feature) I’m going to read it.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 24, 2023, 3:15pm UTC](https://discourse.julialang.org/t/about-extension-support/93462/4 "2023-01-24T15:15:12Z")

</div>

> [@Rratic](#):
>
> I’m developing a Julia package that supports extensions.

To be clear, what do you mean by “extensions?” It sounds like you might mean something different from the weak dependencies added in Julia 1.9?

---

<div class="post-metadata">

**Author:** ![Rratic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rratic/32/24917_2.png) [@Rratic](https://discourse.julialang.org/u/Rratic)\
**Post date:** [January 24, 2023, 3:31pm UTC](https://discourse.julialang.org/t/about-extension-support/93462/5 "2023-01-24T15:31:21Z")

</div>

Probably. Here “extension” includes

1. ability extension (I may use the julia-method-feature to override or add new features for the main package) (e.g. originally I can deal with markdown, extensions can enable me to deal with bbcode, or provide more markdown parsing features like more codeblock types)
2. data extension (e.g. supporting more themes or more languages)

I think the weak dependencies added in Julia 1.9 can do part of the work, but yes, there are a few things I must solve myself. If I can completely control the extension thing (when to load extension, call something like `ext1.initialize_setting(foo)`, etc) those can all be solved.

But I guess it’s not very likely to solve problem 4 if I choose to use this. But that’s not essential, only that it would be more user-friendly if it’s supported.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 24, 2023, 4:32pm UTC](https://discourse.julialang.org/t/about-extension-support/93462/6 "2023-01-24T16:32:39Z")

</div>

> [@Rratic](#):
>
> - ability extension (I may use the julia-method-feature to override or add new features for the main package) (e.g. originally I can deal with markdown, extensions can enable me to deal with bbcode, or provide more markdown parsing features like more codeblock types)
> - data extension (e.g. supporting more themes or more languages)

It sounds like what you want has potentially little to do with weak dependencies. Usually people can add external functionality to your package without any special dependency infrastructure in your package, via:

1. If you write generic code, people can pass new argument types to extend new behaviors.
2. If you write higher-order functions (that take functions as arguments), people can pass callback functions.
3. People can define new methods for your types, and/or new types for your methods, using multiple dispatch.

e.g. in your example of parsers, you could define some kind of `AbstractParser` interface for extending functionality — someone could define a new kind of parser in package `X` which uses _your_ package by defining a new `AbstractParser` type and passing it to your functions. Users who want the new functionality would use package `X` with your package. Your package, on the other hand, would not need _any_ dependency (weak or otherwise) on package `X`.

---

<div class="post-metadata">

**Author:** ![Rratic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rratic/32/24917_2.png) [@Rratic](https://discourse.julialang.org/u/Rratic)\
**Post date:** [January 25, 2023, 2:51am UTC](https://discourse.julialang.org/t/about-extension-support/93462/7 "2023-01-25T02:51:33Z")

</div>

Well, of course I have many ways of extending, but the core problem does lie in my original questions (in this case, question 3 and question 5). Turning to the new feature for help does partly solve them.  
Also note that there may be hundreds of extensions in the future and there might be something like paid extensions or what else, so I shouldn’t register them in `General`.

---

<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:** [January 25, 2023, 6:48am UTC](https://discourse.julialang.org/t/about-extension-support/93462/8 "2023-01-25T06:48:06Z")

</div>

> [@Rratic](#):
>
> Also note that there may be hundreds of extensions in the future and there might be something like paid extensions or what else, so I shouldn’t register them in `General`.

It sounds like you should look into the possibilities of making your own registry for these extensions.
