File: install.py

package info (click to toggle)
lammps 0~20181211.gitad1b1897d%2Bdfsg1-1~bpo9%2B1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 318,868 kB
  • sloc: cpp: 729,569; python: 40,508; xml: 14,919; fortran: 12,142; ansic: 7,454; sh: 5,565; perl: 4,105; f90: 2,700; makefile: 2,114; objc: 238; lisp: 163; tcl: 61; csh: 16; awk: 14
file content (89 lines) | stat: -rw-r--r-- 2,630 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python

# copy LAMMPS src/liblammps.so and lammps.py to system dirs

from __future__ import print_function

instructions = """
Syntax: python install.py [-h] [pydir]
        pydir = target dir for lammps.py and liblammps.so
                default = Python site-packages dir
"""

import sys,os,shutil

if (len(sys.argv) > 1 and sys.argv[1] == "-h") or len(sys.argv) > 2:
  print(instructions)
  sys.exit()

if len(sys.argv) == 2: pydir = sys.argv[1]
else: pydir = ""

# copy lammps.py to pydir if it exists
# if pydir not specified, install in site-packages via distutils setup()

if pydir:
  if not os.path.isdir(pydir):
    print( "ERROR: pydir %s does not exist" % pydir)
    sys.exit()
  str = "cp ../python/lammps.py %s" % pydir
  print(str)
  try:
    shutil.copyfile("../python/lammps.py", os.path.join(pydir,'lammps.py') )
  except shutil.Error:
    pass # source and destination are identical

  str = "cp ../src/liblammps.so %s" % pydir
  print(str)
  try:
     shutil.copyfile("../src/liblammps.so", os.path.join(pydir,"liblammps.so") )
  except shutil.Error:
    pass # source and destination are identical
  sys.exit()
  
print("installing lammps.py in Python site-packages dir")

os.chdir('../python')                # in case invoked via make in src dir

# extract version string from header
fp = open('../src/version.h','r')
txt=fp.read().split('"')[1].split()
verstr=txt[0]+txt[1]+txt[2]
fp.close()

from distutils.core import setup
from distutils.sysconfig import get_python_lib
import site
tryuser=False

try:
  sys.argv = ["setup.py","install"]    # as if had run "python setup.py install"
  setup(name = "lammps",
        version = verstr,
        author = "Steve Plimpton",
        author_email = "sjplimp@sandia.gov",
        url = "http://lammps.sandia.gov",
        description = "LAMMPS molecular dynamics library",
        py_modules = ["lammps"],
        data_files = [(get_python_lib(), ["../src/liblammps.so"])])
except:
  tryuser=True
  print ("Installation into global site-packages dir failed.\nTrying user site dir %s now." % site.USER_SITE)


if tryuser:
  try:
    sys.argv = ["setup.py","install","--user"]    # as if had run "python setup.py install --user"
    setup(name = "lammps",
    version = verstr,
    author = "Steve Plimpton",
    author_email = "sjplimp@sandia.gov",
    url = "http://lammps.sandia.gov",
    description = "LAMMPS molecular dynamics library",
    py_modules = ["lammps"],
    data_files = [(site.USER_SITE, ["../src/liblammps.so"])])
  except: 
    print("Installation into user site package dir failed.\nGo to ../python and install manually.")