Skip to content
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

[pull] main from fortran-lang:main #6

Merged
merged 1 commit into from Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pages/tutorial/index.md
Expand Up @@ -10,4 +10,5 @@ This section contains courses for learning about the usage and fpm at specific e
:::{toctree}
hello-fpm
dependencies
plugins
:::
99 changes: 99 additions & 0 deletions pages/tutorial/plugins.md
@@ -0,0 +1,99 @@
# Extending fpm with plugins

The Fortran package manager has a plugin system which allows to easily extend its functionality.
This tutorial will show how to install a plugin with fpm and use it.


## Registry search tool

The [fpm-search] project is a plugin to query the package registry.
Since it is built with fpm we can easily install it on our system with

[fpm-search]: https://github.com/brocolis/fpm-search

```{code-block} text
git clone https://github.com/brocolis/fpm-search
cd fpm-search
fpm install --profile release
```

This will install the ``fpm-search`` binary to ``~/.local/bin`` (or ``%APPDATA%\local\bin`` on Windows).

:::::{note}
Ensure that the installed binary is in the ``PATH``, *i.e.* run

```{code-block} text
which fpm-search
~/.local/bin/fpm-search
```

If no binary is found, add the directory to your path using

::::{tab-set}
:::{tab-item} Bash (Linux)

Default settings for the bash shell can be found in the ``.bashrc`` file in the home directory, to append to the ``PATH`` following the instructions below.

```{code-block} text
echo "export PATH=$PATH:$HOME/.local/bin" >> ~/.bashrc
. ~/.bashrc
```

Make sure to source your ``.bashrc`` after changing it, otherwise the change will not be applied to the current shell.
:::
:::{tab-item} Zsh (MacOS)

Default settings for the zsh shell can be found in the ``.zshrc`` file in the home directory, to append to the ``PATH`` use

```{code-block} text
echo "export PATH=$PATH:$HOME/.local/bin" >> ~/.zshrc
exec zsh
```

Make sure to restart zsh after changing the ``.zshrc`` it, otherwise the change will not be applied to the current shell.
:::
:::{tab-item} CMD (Windows)

The ``PATH`` variable can be modified using the pathman program from the cmd prompt

```{code-block} text
pathman /au %APPDATA%\local\bin
```
:::
::::
:::::

Now with a working installation we can invoke our new plugin from fpm.

```{code-block} text
❯ fpm search
Downloading registry ... https://github.com/fortran-lang/fpm-registry/raw/master/index.json
...
```

Note that we use ``fpm search`` rather than ``fpm-search`` in the command.
To find a package for building a command-line interface we can now type

```{code-block} text
❯ fpm search commandline
M_CLI : Unix-style commandline parsing using a prototype command and NAMELIST (STD:f2008)
M_CLI2 : Unix-style commandline parsing using a prototype command
```

To use one of the packages in our manifest we can generate the necessary dependency line by running

```{code-block} text
❯ fpm search --toml M_CLI2
M_CLI2 = { git = "https://github.com/urbanjost/M_CLI2" }
```

Adding this line to a package manifest allows to depend on the respective project.

:::{admonition} Summary
:class: tip
In this tutorial you learned how to

- installing an fpm plugin
- use the fpm-search plugin to query the registry
- generate a dependency entry from a query result
:::