跳转至

spack

自定义

配置文件

~/.spack/config.yaml 主要配置安装目录,同时去掉了目录中的编译器和哈希后缀。

~/.spack/config.yaml
config:
  install_tree:
    root: $spack/opt/spack
    projections:
      all: "{name}/{version}"
  module_roots:
    tcl:   $spack/modules   # Tcl
~/.spack/modules.yaml 主要配置 modulefile 文件,同时去掉了 modulefile 文件中的编译器和哈希后缀。
~/.spack/modules.yaml
modules:
  default:
    arch_folder: false
    tcl:          
      hash_length: 0                    # 可选:去掉哈希
      naming_scheme: '{name}/{version}'

自定义 repo

$ spack repo create my-repo myrepo
$ spack repo add my-repo/spack_repo/myrepo

$ tree my-repo
my-repo
└── spack_repo
    └── myrepo
        ├── packages
        └── repo.yaml

# 查看repo
$ spack repo list

Autotools

spack create -N myrepo -t autotools -n clustalw /home/username/package/spack/pkg/clustalw_2.1.tar.gz

生成软件安装模板代码 my-repo/spack_repo/myrep/packages/clustalw/package.py

其中 -N 指定 repo,-t 指定编译模板,这里使用的 autotools

根据软件安装的实际步骤修改 package.py 代码,clustalw 是经典的三步安装法 configure->make->make install。需要用 sha256sum 计算安装包的哈希值填入代码中。

spack external find gmake cmake 使用系统的 make gcc 和 cmake。

~/.spack/packages.yaml
packages:
  gmake:
    externals:
    - spec: gmake@4.3
      prefix: /usr
    buildable: false
  cmake:
    externals:
    - spec: cmake@3.22.0
      prefix: /usr
    buildable: false
  gcc:
    externals:
    - spec: gcc@10.3.1 languages:='c,c++,fortran'
      prefix: /usr
      extra_attributes:
        compilers:
          c: /usr/bin/gcc
          cxx: /usr/bin/g++
          fortran: /usr/bin/gfortran
    buildable: false

使用 AutotoolsPackage 包,更多选项见 autotoolspackage

package.py
from spack_repo.builtin.build_systems.generic import Package

from spack.package import *

class Clustalw(AutotoolsPackage):
    """ClustalW: multiple sequence alignment program for DNA/protein."""

    homepage = "http://www.clustal.org/clustal2/"
    url = "file:///home/username/spack/pkg/clustalw_2.1.tar.gz"

    version("2.1", sha256='e052059b87abfd8c9e695c280bfba86a65899138c82abccd5b00478a80f49486')

使用 Package

package.py
from spack_repo.builtin.build_systems.generic import Package

from spack.package import *

class Clustalw(Package):
    """ClustalW: multiple sequence alignment program for DNA/protein."""

    homepage = "http://www.clustal.org/clustal2/"
    url = "file:///home/username/spack/pkg/clustalw_2.1.tar.gz"

    version("2.1", sha256='e052059b87abfd8c9e695c280bfba86a65899138c82abccd5b00478a80f49486')

    depends_on('gmake', type='build')

    def install(self, spec, prefix):
        configure('--prefix={0}'.format(prefix))   # ./configure --prefix=$prefix
        make()
        make("install")

make

hifiasm 有 Makefile 文件,可以直接 make 安装。

package.py
from spack_repo.builtin.build_systems.generic import Package

from spack.package import *

class Hifiasm(Package):
    homepage = "https://github.com/hifiasm/hifiasm"
    url      = "file:///home/username/spack/pkg/hifiasm_0.25.0.tar.gz"

    version("0.25.0", sha256="51633138865207a9d41630da9377d46e4921ad4fc5facaa1740ceccae8611f1f")

    depends_on('gmake', type='build')

    def install(self, spec, prefix):
        make()
        # 把可执行文件拷到 prefix.bin
        mkdirp(prefix.bin)
        install('hifiasm', prefix.bin)

cmake

spack create -b -N myrepo -t cmake -n bamtools /home/username/spack/pkg/bamtools-2.5.2.tar.gz

生成软件安装模板代码 my-repo/spack_repo/myrep/packages/bamtools/package.py

其中 -N 指定 repo,-t 指定编译模板,这里使用的 cmake

根据软件安装的实际步骤修改 package.py 代码。需要用 sha256sum 计算安装包的哈希值填入代码中。

from spack_repo.builtin.build_systems.cmake import CMakePackage

from spack.package import *


class Bamtools(CMakePackage):
    """FIXME: Put a proper description of your package here."""

    homepage = "https://www.example.com"

    license("UNKNOWN", checked_by="github_user1")

    version("2.5.2", sha256="4d8b84bd07b673d0ed41031348f10ca98dd6fa6a4460f9b9668d6f1d4084dfc8", url = "file:///home/username/spack/pkg/bamtools-2.5.2.tar.gz")

    # FIXME: Add dependencies if required.
    # depends_on("foo")

    def cmake_args(self):
        # FIXME: Add arguments other than
        # FIXME: CMAKE_INSTALL_PREFIX and CMAKE_BUILD_TYPE
        # FIXME: If not needed delete this function
        args = []
        return args

预编译软件

部分软件已经有预编译好的版本,可直接拷贝至安装目录,如 ncbi-blast、hisat2 等。

以blast为例,

spack create -b -N myrepo -t generic -n blast /home/username/spack/pkg/ncbi-blast-2.16.0+-x64-linux.tar.gz

更改后的 package.py 如下。

from spack_repo.builtin.build_systems.generic import Package

from spack.package import *


class Blast(Package):
    """FIXME: Put a proper description of your package here."""

    homepage = "https://blast.ncbi.nlm.nih.gov/"

    version("2.16.0", sha256 = "b0b13098c901d23b324ad1700e7471bb7408a7f7f517d74d5faad711be76e8f4", url ="file:///home/username/spack/pkg/ncbi-blast-2.16.0+-x64-linux.tar.gz")

    # FIXME: Add dependencies if required.
    # depends_on("foo")

    def install(self, spec, prefix):
        #make()
        #make("install")
        install_tree("bin", prefix.bin)

以 hisat2 为例,挑选部分编译好的二进制文件和脚本目录拷贝至安装目录。

spack create -b -N myrepo -t generic -n hisat2 /home/username/spack/pkg/hisat2-2.2.1-Linux_x86_64.zip

from spack_repo.builtin.build_systems.generic import Package

from spack.package import *

class Hisat2(Package):
    """FIXME: Put a proper description of your package here."""

    homepage = "https://daehwankimlab.github.io/hisat2/"

    # FIXME: Add proper versions here.
    version("2.2.1", sha256 = "ae53af930729787a126944f7db34d4065c06f589c4fb05f4cfa9a348cacd5cb4", url = "file:///home/username/spack/pkg/hisat2-2.2.1-Linux_x86_64.zip")

    # FIXME: Add dependencies if required.
    # depends_on("foo")

    def install(self, spec, prefix):
        # FIXME: Unknown build system
        #make()
        #make("install")
        install_tree("example", prefix.example)
        install_tree("scripts", prefix.scripts)

        mkdirp(prefix.bin)
        install("hisat2", prefix.bin)
        install("hisat2-align-s", prefix.bin)
        install("hisat2-align-l", prefix.bin)
        install("hisat2-build", prefix.bin)
        install("hisat2-build-s", prefix.bin)
        install("hisat2-build-l", prefix.bin)
        install("hisat2-inspect", prefix.bin)
        install("hisat2-inspect-s", prefix.bin)
        install("hisat2-inspect-l", prefix.bin)
        install("hisat2-repeat", prefix.bin)
        install("*.py", prefix.bin)

python

以 htseq 为例

bin/spack create -b -N myrepo -t python -n htseq

from spack_repo.builtin.build_systems.python import PythonPackage

from spack.package import *


class PyHtseq(PythonPackage):
    """FIXME: Put a proper description of your package here."""

    homepage = "https://pypi.org/project/HTSeq/"

    pypi = "HTSeq/htseq-2.0.9.tar.gz"
    license("UNKNOWN", checked_by="github_user1")

    # FIXME: Add proper versions here.
    version("2.0.9", sha256 = "3bbec23f033d35f40ab33a40c2b5c43f75e382c424b804c099dea635b52c2b12")
    depends_on("python@3.9", type=("build", "run"))

    # FIXME: Add additional dependencies if required.
    # depends_on("py-foo", type=("build", "run"))

    def config_settings(self, spec, prefix):
        settings = {}
        return settings

    def install(self, spec, prefix):
        pip = which('pip', required=True)
        # ① 只装 binary,不回落源码;② 禁用 deps 避免重复
        pip('install',
            '--no-deps',                    # 依赖由 Spack 负责
            '--only-binary', ':all:',       # 强制 wheel
            '--prefix', prefix,
            'numpy==1.22.2','pysam')        # 下载好的 wheel


        pip('install',
            '--no-deps',                    # 依赖由 Spack 负责
            '--only-binary', ':all:',       # 强制 wheel
            '--prefix', prefix,
            self.stage.archive_file)        # 下载好的 wheel

    def setup_run_environment(self, env):
        # 把依赖也加入同一 PYTHONPATH
        for dep in ('py-numpy', 'py-pandas', 'py-pysam', 'py-matplotlib'):
            env.prepend_path('PYTHONPATH',
                             join_path(self.spec[dep].prefix,
                                       'lib/python{0}/site-packages'.format(
                                           self.spec['python'].version.up_to(2))))
本文阅读量  次
本站总访问量  次