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 (114 lines) | stat: -rw-r--r-- 3,511 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
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python

"""
Install.py tool to download, unpack, and point to the Eigen library
used to automate the steps described in the README file in this dir
"""

from __future__ import print_function
import sys, os, glob, shutil, tarfile
from argparse import ArgumentParser

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

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

# settings

version = '3.4.0'
tarball = "eigen.tar.gz"

# known checksums for different Eigen versions. used to validate the download.
checksums = { \
              '3.4.0' : '4c527a9171d71a72a9d4186e65bea559', \
              '3.3.9' : '609286804b0f79be622ccf7f9ff2b660', \
              '3.3.7' : '9e30f67e8531477de4117506fe44669b' \
}


# help message

HELP = """
Syntax from src dir: make lib-smd args="-b"
                 or: make lib-smd args="-p /usr/include/eigen3"

Syntax from lib dir: python Install.py -b
                 or: python Install.py -p /usr/include/eigen3"
                 or: python Install.py -v 3.4.0 -b

Example:

make lib-smd args="-b"   # download/build in default lib/smd/eigen-eigen-*
make lib-smd args="-p /usr/include/eigen3" # use existing Eigen installation in /usr/include/eigen3
"""

pgroup = parser.add_mutually_exclusive_group()
pgroup.add_argument("-b", "--build", action="store_true",
                    help="download and build the Eigen3 library")
pgroup.add_argument("-p", "--path",
                    help="specify folder of existing Eigen installation")
parser.add_argument("-v", "--version", default=version,
                    help="set version of Eigen to download and build (default: %s)" % version)

args = parser.parse_args()

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

homepath = fullpath(".")
eigenpath = os.path.join(homepath, "eigen3")

buildflag = args.build
pathflag = args.path is not None
version = args.version

if pathflag:
  eigenpath = args.path
  if not os.path.isdir(eigenpath):
    sys.exit("Eigen path %s does not exist" % eigenpath)
  eigenpath = fullpath(eigenpath)

# download and unpack Eigen tarball
# use glob to find name of dir it unpacks to

if buildflag:
  print("Downloading Eigen ...")
  eigentar = os.path.join(homepath, tarball)
  url = "https://download.lammps.org/thirdparty/eigen-%s.tar.gz" %  version
  geturl(url, eigentar)

  # verify downloaded archive integrity via md5 checksum, if known.
  if version in checksums:
    print("checking version %s\n" % version)
    if not checkmd5sum(checksums[version], eigentar):
      sys.exit("Checksum for Eigen library does not match")


  print("Cleaning up old folders ...")
  edir = glob.glob(os.path.join(homepath, "eigen-*"))
  edir.append(eigenpath)
  for one in edir:
    if os.path.isdir(one):
      shutil.rmtree(one)

  print("Unpacking Eigen tarball ...")
  if tarfile.is_tarfile(eigentar):
    tgz = tarfile.open(eigentar)
    tgz.extractall(path=homepath)
    os.remove(eigentar)
  else:
    sys.exit("File %s is not a supported archive" % eigentar)
  edir = os.path.join(homepath, "eigen-%s" % version)
  os.rename(edir, eigenpath)

# create link in lib/smd to Eigen src dir

print("Creating link to Eigen include folder")
if os.path.isfile("includelink") or os.path.islink("includelink"):
  os.remove("includelink")
linkdir = eigenpath
os.symlink(linkdir, 'includelink')