Skip to content

App support in Pkg #3772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions docs/src/apps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# [**?.** Apps](@id Apps)

!!! note
The app support in Pkg is currently considered experimental and some functionality and API may change.

Some inconveniences that can be encountered are:
- You need to manually make `~/.julia/bin` available on the PATH environment.
- The path to the julia executable used is the same as the one used to install the app. If this
julia installation gets removed, you might need to reinstall the app.
used by the app might not be found.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
used by the app might not be found.

- You can only have one app installed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One per package?


Apps are Julia packages that are intended to be run as a "standalone programs" (by e.g. typing the name of the app in the terminal possibly together with some arguments or flags/options).
This is in contrast to most Julia packages that are used as "libraries" and are loaded by other files or in the Julia REPL.

## Creating a Julia app

A Julia app is structured similar to a standard Julia library with the following additions:

- A `@main` entry point in the package module (see the Julia help on `@main` for details)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be [`@main`](@ref), or can this just be a link to that section in the docs?

- An `[app]` section in the `Project.toml` file listing the executable names that the package provides.

A very simple example of an app that prints the reversed input arguments would be:

```julia
# src/MyReverseApp.jl
module MyReverseApp

function (@main)(ARGS)
for arg in ARGS
print(stdout, reverse(arg), " ")
end
return
end

end # module
```

```toml
# Project.toml

# standard fields here

[apps]
reverse = {}
```
The empty table `{}` is to allow for giving metadata about the app but it is currently unused.

After installing this app one could run:

```
$ reverse some input string
emos tupni gnirts
```

directly in the terminal.

## Installing Julia apps

The installation of Julia apps are similar to installing julia libraries but instead of using e.g. `Pkg.add` or `pkg> add` one uses `Pkg.Apps.add` or `pkg> app add` (`develop` is also available).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The installation of Julia apps are similar to installing julia libraries but instead of using e.g. `Pkg.add` or `pkg> add` one uses `Pkg.Apps.add` or `pkg> app add` (`develop` is also available).
The installation of Julia apps are similar to installing julia libraries but instead of using e.g. `Pkg.add` or `pkg> add` one uses `Pkg.Apps.add` or `pkg> app add` (`pkg> app develop` is also available).

Or "develop rather than add is also..."

17 changes: 17 additions & 0 deletions ext/REPLExt/completions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,23 @@ function complete_add_dev(options, partial, i1, i2; hint::Bool)
return comps, idx, !isempty(comps)
end

# TODO: Move
import Pkg: Operations, Types, Apps
function complete_installed_apps(options, partial; hint)
manifest = try
Types.read_manifest(joinpath(Apps.app_env_folder(), "AppManifest.toml"))
catch err
err isa PkgError || rethrow()
return String[]
end
apps = String[]
for (uuid, entry) in manifest.deps
append!(apps, keys(entry.apps))
push!(apps, entry.name)
end
return unique!(apps)
end

########################
# COMPLETION INTERFACE #
########################
Expand Down
Loading
Loading