Skip to content

Commit 0c19b10

Browse files
authored
Add tutorial on plugins (#36)
1 parent 8bde3bb commit 0c19b10

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

pages/tutorial/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ This section contains courses for learning about the usage and fpm at specific e
1010
:::{toctree}
1111
hello-fpm
1212
dependencies
13+
plugins
1314
:::

pages/tutorial/plugins.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Extending fpm with plugins
2+
3+
The Fortran package manager has a plugin system which allows to easily extend its functionality.
4+
This tutorial will show how to install a plugin with fpm and use it.
5+
6+
7+
## Registry search tool
8+
9+
The [fpm-search] project is a plugin to query the package registry.
10+
Since it is built with fpm we can easily install it on our system with
11+
12+
[fpm-search]: https://github.com/brocolis/fpm-search
13+
14+
```{code-block} text
15+
git clone https://github.com/brocolis/fpm-search
16+
cd fpm-search
17+
fpm install --profile release
18+
```
19+
20+
This will install the ``fpm-search`` binary to ``~/.local/bin`` (or ``%APPDATA%\local\bin`` on Windows).
21+
22+
:::::{note}
23+
Ensure that the installed binary is in the ``PATH``, *i.e.* run
24+
25+
```{code-block} text
26+
which fpm-search
27+
~/.local/bin/fpm-search
28+
```
29+
30+
If no binary is found, add the directory to your path using
31+
32+
::::{tab-set}
33+
:::{tab-item} Bash (Linux)
34+
35+
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.
36+
37+
```{code-block} text
38+
echo "export PATH=$PATH:$HOME/.local/bin" >> ~/.bashrc
39+
. ~/.bashrc
40+
```
41+
42+
Make sure to source your ``.bashrc`` after changing it, otherwise the change will not be applied to the current shell.
43+
:::
44+
:::{tab-item} Zsh (MacOS)
45+
46+
Default settings for the zsh shell can be found in the ``.zshrc`` file in the home directory, to append to the ``PATH`` use
47+
48+
```{code-block} text
49+
echo "export PATH=$PATH:$HOME/.local/bin" >> ~/.zshrc
50+
exec zsh
51+
```
52+
53+
Make sure to restart zsh after changing the ``.zshrc`` it, otherwise the change will not be applied to the current shell.
54+
:::
55+
:::{tab-item} CMD (Windows)
56+
57+
The ``PATH`` variable can be modified using the pathman program from the cmd prompt
58+
59+
```{code-block} text
60+
pathman /au %APPDATA%\local\bin
61+
```
62+
:::
63+
::::
64+
:::::
65+
66+
Now with a working installation we can invoke our new plugin from fpm.
67+
68+
```{code-block} text
69+
❯ fpm search
70+
Downloading registry ... https://github.com/fortran-lang/fpm-registry/raw/master/index.json
71+
...
72+
```
73+
74+
Note that we use ``fpm search`` rather than ``fpm-search`` in the command.
75+
To find a package for building a command-line interface we can now type
76+
77+
```{code-block} text
78+
❯ fpm search commandline
79+
M_CLI : Unix-style commandline parsing using a prototype command and NAMELIST (STD:f2008)
80+
M_CLI2 : Unix-style commandline parsing using a prototype command
81+
```
82+
83+
To use one of the packages in our manifest we can generate the necessary dependency line by running
84+
85+
```{code-block} text
86+
❯ fpm search --toml M_CLI2
87+
M_CLI2 = { git = "https://github.com/urbanjost/M_CLI2" }
88+
```
89+
90+
Adding this line to a package manifest allows to depend on the respective project.
91+
92+
:::{admonition} Summary
93+
:class: tip
94+
In this tutorial you learned how to
95+
96+
- installing an fpm plugin
97+
- use the fpm-search plugin to query the registry
98+
- generate a dependency entry from a query result
99+
:::

0 commit comments

Comments
 (0)