File: petscdir.py

package info (click to toggle)
petsc 3.23.1%2Bdfsg1-1exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 515,576 kB
  • sloc: ansic: 751,607; cpp: 51,542; python: 38,598; f90: 17,352; javascript: 3,493; makefile: 3,157; sh: 1,502; xml: 619; objc: 445; java: 13; csh: 1
file content (77 lines) | stat: -rw-r--r-- 3,261 bytes parent folder | download | duplicates (3)
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
import config.base
import os
import re

class Configure(config.base.Configure):
  def __init__(self, framework):
    config.base.Configure.__init__(self, framework)
    self.headerPrefix = 'PETSC'
    self.substPrefix  = 'PETSC'
    return

  def __str1__(self):
    if hasattr(self, 'dir'):
      return '  PETSC_DIR: '+str(self.dir)+'\n'
    return ''

  def setupHelp(self, help):
    import nargs
    help.addArgument('PETSc', '-PETSC_DIR=<root-dir>',                        nargs.Arg(None, None, 'The root directory of the PETSc installation'))
    return

  def configureDirectories(self):
    '''Checks PETSC_DIR and sets if not set'''
    if 'PETSC_DIR' in self.framework.argDB:
      self.dir = os.path.normpath(self.framework.argDB['PETSC_DIR'])
      msg1 = 'The configure option'
      msg2 = ''
    elif 'PETSC_DIR' in os.environ:
      self.dir = os.path.normpath(os.environ['PETSC_DIR'])
      msg1 = 'The environmental variable'
      msg2 = 'export'
    else:
      self.dir = os.getcwd()
      msg1 = ''
      msg2 = ''

    if self.dir == 'pwd':
      raise RuntimeError('{0} PETSC_DIR=pwd is incorrect. You need to use back quotes around the pwd - i.e: {1} PETSC_DIR=`pwd`'.format(msg1, msg2))
    elif self.dir.find(' ') > -1:
      raise RuntimeError('{0} PETSC_DIR="{1}" has spaces in it; this is not allowed. Change the directory with PETSc to not have spaces in it'.format(msg1, self.dir))
    elif not os.path.isabs(self.dir):
      raise RuntimeError('{0} PETSC_DIR={1} is a relative path. Use absolute path - i.e: {2} PETSC_DIR={3}'.format(msg1, self.dir, msg2, os.path.abspath(self.dir)))
    elif not os.path.isdir(self.dir):
      raise RuntimeError('{0} PETSC_DIR={1} is not a directory'.format(msg1, self.dir))
    elif os.path.realpath(self.dir) != os.path.realpath(os.getcwd()):
      raise RuntimeError('{0} PETSC_DIR={1} MUST be the current directory {2}'.format(msg1, self.dir, os.getcwd()))

    self.version  = 'Unknown'
    versionHeader = os.path.join(self.dir, 'include', 'petscversion.h')
    versionInfo = []
    if os.path.exists(versionHeader):
      f = open(versionHeader)
      for line in f:
        if line.find('define PETSC_VERSION') >= 0:
          versionInfo.append(line[:-1])
      f.close()
    else:
      raise RuntimeError('Invalid PETSc directory '+str(self.dir)+'. Could not locate '+versionHeader)
    self.versionRelease = True if versionInfo[0].split(' ')[-1] == '1' else False
    if self.versionRelease:
      self.version = '.'.join([line.split(' ')[-1] for line in versionInfo[1:4]])
    else:
      self.version = '.'.join([line.split(' ')[-1] for line in versionInfo[1:3]])
      self.version += '.99'
    self.logPrint('PETSC_VERSION_RELEASE of 1 indicates the code is from a release branch or a branch created from a release branch.')
    self.logPrint('Version Information:')
    for line in versionInfo:
      self.logPrint(line)
    dirs = self.argDB['with-executables-search-path']
    if not isinstance(dirs, list): dirs = dirs.split(os.path.pathsep)
    dirs.append(os.path.join(self.dir, 'lib','petsc','bin', 'win32fe'))
    self.framework.argDB['with-executables-search-path'] = dirs
    return

  def configure(self):
    self.executeTest(self.configureDirectories)
    return