使用插件扩展fpm
内容
使用插件扩展fpm¶
Fortran包管理器有一个插件系统,可以轻松扩展其功能。本教程将展示如何使用fpm安装插件并使用它。
注册表搜索工具¶
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
git clone https://github.com/urbanjost/fpm-search
cd fpm-search
fpm install --profile release
这会将二进制文件fpm-search安装到~/.local/bin(或在Windows上的%APPDATA%\local\bin)。
备注
确保安装的二进制文件位于环境路径(PATH)中,即运行:
which fpm-search
~/.local/bin/fpm-search
如果未找到二进制文件,请使用:
bash shell的默认设置可以在主目录的.bashrc中找到,根据以下说明以附加到环境路径(PATH):
echo 'export PATH=$PATH:$HOME/.local/bin' >> ~/.bashrc
. ~/.bashrc
确保在更改.bashrc后载入它,否则更改将不会应用于当前shell。
zsh shell的默认设置可以在主目录的.zshrc文件中找到,以附加到环境路径(PATH)使用:
echo 'export PATH=$PATH:$HOME/.local/bin' >> ~/.zshrc
exec zsh
确保在更改.zshrc后重新启动zsh,否则更改将不会应用于当前shell。
可以使用cmd提示符中的路径程序修改变量PATH:
pathman /au %APPDATA%\local\bin
现在,通过之前的安装工作,我们可以从fpm调用我们的新插件。
❯ fpm search
Downloading registry ... https://github.com/fortran-lang/fpm-registry/raw/master/index.json
...
请注意,我们使用fpm search而不是在命令中使用fpm-search。要查找用于构建命令行界面的包,我们现在可以键入:
❯ 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
要使用清单中的某个包,我们可以通过以下方式生成必要的依赖关系行:
❯ fpm search --toml M_CLI2
M_CLI2 = { git = "https://github.com/urbanjost/M_CLI2" }
将此行添加到包清单以允许依赖于相应的项目。
总结
在本教程中,你学习了如何
安装fpm插件;
使用fpm搜索插件查询注册表;
根据查询结果生成依赖项条目。