File: Install.py

package info (click to toggle)
lammps 20220106.git7586adbb6a%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 348,064 kB
  • sloc: cpp: 831,421; python: 24,896; xml: 14,949; f90: 10,845; ansic: 7,967; sh: 4,226; perl: 4,064; fortran: 2,424; makefile: 1,501; objc: 238; lisp: 163; csh: 16; awk: 14; tcl: 6
file content (105 lines) | stat: -rw-r--r-- 3,322 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# TODO#!/usr/bin/env python

"""
Install.py tool to download, compile, and setup the pace library
used to automate the steps described in the README file in this dir
"""

from __future__ import print_function
import sys, subprocess
from argparse import ArgumentParser

sys.path.append('..')
from install_helpers import fullpath, geturl, checkmd5sum

# settings

thisdir = fullpath('.')
version = 'v.2021.4.9'

# known checksums for different PACE versions. used to validate the download.
checksums = { \
        'v.2021.2.3.upd2' : '8fd1162724d349b930e474927197f20d',
        'v.2021.4.9'      : '4db54962fbd6adcf8c18d46e1798ceb5',
        }


parser = ArgumentParser(prog='Install.py',
                        description="LAMMPS library build wrapper script")


# help message

HELP = """
Syntax from src dir: make lib-pace args="-b"
                 or: make lib-pace args="-b -v version"
Syntax from lib dir: python Install.py -b
                 or: python Install.py -b -v version

Examples:

make lib-pace args="-b" # install default version of PACE lib
make lib-pace args="-b -v version" # install specified version of PACE lib


"""

pgroup = parser.add_mutually_exclusive_group()
pgroup.add_argument("-b", "--build", action="store_true",
                    help="download and build base PACE  library")
parser.add_argument("-v", "--version", default=version, choices=checksums.keys(),
                    help="set version of PACE library to download and build (default: %s)" % version)
parser.add_argument("-vv", "--verbose", action="store_true",
                    help="be more verbose about is happening while this script runs")

args = parser.parse_args()

# print help message and exit, if neither build nor path options are given
if not args.build:
  parser.print_help()
  sys.exit(HELP)

buildflag = args.build

verboseflag = args.verbose
version = args.version


archive_extension = "tar.gz"
url = "https://github.com/ICAMS/lammps-user-pace/archive/refs/tags/%s.%s" % (version, archive_extension)
unarchived_folder_name = "lammps-user-pace-%s"%(version)

# download PACE tarball, unpack, build PACE
if buildflag:

  # download entire tarball

  print("Downloading pace tarball ...")
  archive_filename = "%s.%s" % (version, archive_extension)
  download_filename = "%s/%s" % (thisdir, archive_filename)
  print("Downloading from ",url," to ",download_filename, end=" ")
  geturl(url, download_filename)
  print(" done")

  # verify downloaded archive integrity via md5 checksum, if known.
  if version in checksums:
    if not checkmd5sum(checksums[version], archive_filename):
      sys.exit("Checksum for pace library does not match")

  print("Unpacking pace tarball ...")
  src_folder = thisdir+"/src"
  cmd = 'cd "%s"; rm -rf "%s"; tar -xvf %s; mv %s %s' % (thisdir, src_folder, archive_filename, unarchived_folder_name, src_folder)
  subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)

  # build
  print("Building libpace ...")
  cmd = 'make lib -j2'
  txt = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
  if verboseflag:
    print(txt.decode("UTF-8"))

#   remove source files

  print("Removing pace build files and archive ...")
  cmd = 'rm %s; make clean-build' % (download_filename)
  subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)