Subversion Repositories slepc-dev

Rev

Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2490 Rev 2517
#!/usr/bin/env python
#!/usr/bin/env python
 
 
"""
"""
SLEPc: Scalable Library for Eigenvalue Problem Computations
SLEPc: Scalable Library for Eigenvalue Problem Computations
===========================================================
===========================================================
 
 
SLEPc is a software library for the solution of large scale sparse
SLEPc is a software library for the solution of large scale sparse
eigenvalue problems on parallel computers. It is an extension of PETSc
eigenvalue problems on parallel computers. It is an extension of PETSc
and can be used for either standard or generalized eigenproblems, with
and can be used for either standard or generalized eigenproblems, with
real or complex arithmetic. It can also be used for computing a
real or complex arithmetic. It can also be used for computing a
partial SVD of a large, sparse, rectangular matrix, and to solve
partial SVD of a large, sparse, rectangular matrix, and to solve
quadratic eigenvalue problems
quadratic eigenvalue problems
 
 
 
.. tip::
 
 
 
  You can also install `slepc-dev`_ with::
 
 
 
    $ pip install slepc==dev petsc==dev
 
 
 
  .. _petsc-dev: http://www.grycap.upv.es/slepc/
 
                 svn/trunk/#egg=slepc-dev
"""
"""
 
 
import sys, os
import sys, os
from distutils.core import setup
from distutils.core import setup
from distutils.util import get_platform
from distutils.util import get_platform
from distutils.spawn import find_executable
from distutils.spawn import find_executable
from distutils.command.build import build as _build
from distutils.command.build import build as _build
if 'setuptools' in sys.modules:
if 'setuptools' in sys.modules:
    from setuptools.command.install import install as _install
    from setuptools.command.install import install as _install
else:
else:
    from distutils.command.install import install as _install
    from distutils.command.install import install as _install
from distutils.command.sdist import sdist as _sdist
from distutils.command.sdist import sdist as _sdist
from distutils import log
from distutils import log
 
 
init_py = """\
init_py = """\
# Author:  SLEPc Team
# Author:  SLEPc Team
# Contact: slepc-maint@grycap.upv.es
# Contact: slepc-maint@grycap.upv.es
 
 
def get_slepc_dir():
def get_slepc_dir():
    import os
    import os
    return os.path.dirname(__file__)
    return os.path.dirname(__file__)
 
 
def get_config():
def get_config():
    conf = {}
    conf = {}
    conf['SLEPC_DIR'] = get_slepc_dir()
    conf['SLEPC_DIR'] = get_slepc_dir()
    return conf
    return conf
"""
"""
 
 
metadata = {
metadata = {
    'provides' : ['slepc'],
    'provides' : ['slepc'],
    'requires' : [],
    'requires' : [],
}
}
 
 
def bootstrap():
def bootstrap():
 
    from os.path import join, isdir, abspath
    # Set SLEPC_DIR
    # Set SLEPC_DIR
    SLEPC_DIR  = os.path.abspath(os.getcwd())
    SLEPC_DIR  = abspath(os.getcwd())
    os.environ['SLEPC_DIR']  = SLEPC_DIR
    os.environ['SLEPC_DIR']  = SLEPC_DIR
    if not os.environ.get('PETSC_DIR'):
    # Check PETSC_DIR/PETSC_ARCH
 
    PETSC_DIR  = os.environ.get('PETSC_DIR',  "")
 
    PETSC_ARCH = os.environ.get('PETSC_ARCH', "")
 
    if not (PETSC_DIR and isdir(PETSC_DIR)):
 
        PETSC_DIR = None
 
        try: del os.environ['PETSC_DIR']
 
        except KeyError: pass
 
        PETSC_ARCH = None
 
        try: del os.environ['PETSC_ARCH']
 
        except KeyError: pass
 
    elif not isdir(join(PETSC_DIR, PETSC_ARCH)):
 
        PETSC_ARCH = None
        try: del os.environ['PETSC_ARCH']
        try: del os.environ['PETSC_ARCH']
        except KeyError: pass
        except KeyError: pass
    # Generate package __init__.py file
    # Generate package __init__.py file
    from distutils.dir_util import mkpath
    from distutils.dir_util import mkpath
    pkgdir = os.path.join('config', 'pypi')
    pkgdir = os.path.join('config', 'pypi')
    pkgfile = os.path.join(pkgdir, '__init__.py')
    pkgfile = os.path.join(pkgdir, '__init__.py')
    if not os.path.exists(pkgdir):
    if not os.path.exists(pkgdir): mkpath(pkgdir)
        mkpath(pkgdir)
    fh = open(pkgfile, 'wt')
    if not os.path.exists(pkgfile):
    fh.write(init_py)
        open(pkgfile, 'wt').write(init_py)
    fh.close()
    if not os.environ.get('PETSC_DIR'):
    if ('setuptools' in sys.modules):
        if (('distribute' in sys.modules) or
        metadata['zip_safe'] = False
            ('setuptools' in sys.modules)):
        if not PETSC_DIR:
            metadata['install_requires']= ['petsc']
            metadata['install_requires']= ['petsc']
    if 'setuptools' in sys.modules:
 
        metadata['zip_safe'] = False
 
 
 
def get_petsc_dir():
def get_petsc_dir():
    PETSC_DIR = os.environ.get('PETSC_DIR')
    PETSC_DIR = os.environ.get('PETSC_DIR')
    if not PETSC_DIR:
    if PETSC_DIR: return PETSC_DIR
        try:
    try:
            import petsc
        import petsc
            PETSC_DIR = petsc.get_petsc_dir()
        PETSC_DIR = petsc.get_petsc_dir()
        except ImportError:
    except ImportError:
            log.warn("PETSC_DIR not specified")
        log.warn("PETSC_DIR not specified")
            PETSC_DIR = os.path.join(os.path.sep, 'usr', 'local', 'petsc')
        PETSC_DIR = os.path.join(os.path.sep, 'usr', 'local', 'petsc')
    return PETSC_DIR
    return PETSC_DIR
 
 
def get_petsc_arch():
def get_petsc_arch():
    PETSC_ARCH = os.environ.get('PETSC_ARCH') or 'installed-petsc'
    PETSC_ARCH = os.environ.get('PETSC_ARCH') or 'arch-installed-petsc'
    return PETSC_ARCH
    return PETSC_ARCH
 
 
def config(dry_run=False):
def config(dry_run=False):
    log.info('SLEPc: configure')
    log.info('SLEPc: configure')
    if dry_run: return
    if dry_run: return
    # PETSc
    # PETSc
    # Run SLEPc configure
    # Run SLEPc configure
    os.environ['PETSC_DIR'] = get_petsc_dir()
    os.environ['PETSC_DIR'] = get_petsc_dir()
    status = os.system(" ".join((
    status = os.system(" ".join((
            find_executable('python'),
            find_executable('python'),
            os.path.join('config', 'configure.py'),
            os.path.join('config', 'configure.py'),
            )))
            )))
    if status != 0: raise RuntimeError(status)
    if status != 0: raise RuntimeError(status)
 
 
def build(dry_run=False):
def build(dry_run=False):
    log.info('SLEPc: build')
    log.info('SLEPc: build')
    if dry_run: return
    if dry_run: return
    # Run SLEPc build
    # Run SLEPc build
    status = os.system(" ".join((
    status = os.system(" ".join((
            find_executable('make'),
            find_executable('make'),
            'PETSC_DIR='+get_petsc_dir(),
            'PETSC_DIR='+get_petsc_dir(),
            'PETSC_ARCH='+get_petsc_arch(),
            'PETSC_ARCH='+get_petsc_arch(),
            'all',
            'all',
            )))
            )))
    if status != 0: raise RuntimeError
    if status != 0: raise RuntimeError
 
 
def install(dest_dir, prefix=None, dry_run=False):
def install(dest_dir, prefix=None, dry_run=False):
    log.info('SLEPc: install')
    log.info('SLEPc: install')
    if dry_run: return
    if dry_run: return
    if prefix is None:
    if prefix is None:
        prefix = dest_dir
        prefix = dest_dir
    PETSC_ARCH = get_petsc_arch()
    PETSC_ARCH = get_petsc_arch()
    # Run SLEPc install
    # Run SLEPc install
    status = os.system(" ".join((
    status = os.system(" ".join((
            find_executable('make'),
            find_executable('make'),
            'PETSC_DIR='+get_petsc_dir(),
            'PETSC_DIR='+get_petsc_dir(),
            'PETSC_ARCH='+get_petsc_arch(),
            'PETSC_ARCH='+get_petsc_arch(),
            'SLEPC_INSTALL_DIR='+dest_dir,
            'SLEPC_DESTDIR='+dest_dir,
            'install',
            'install',
            )))
            )))
    if status != 0: raise RuntimeError
    if status != 0: raise RuntimeError
    slepcvariables = os.path.join(dest_dir, 'conf', 'slepcvariables')
    slepcvariables = os.path.join(dest_dir, 'conf', 'slepcvariables')
    open(slepcvariables, 'a').write('SLEPC_INSTALL_DIR=%s\n' % prefix)
    fh = open(slepcvariables, 'a')
 
    fh.write('SLEPC_DESTDIR=%s\n' % prefix)
 
    fh.close()
 
 
class context:
class context:
    def __init__(self):
    def __init__(self):
        self.sys_argv = sys.argv[:]
        self.sys_argv = sys.argv[:]
        self.wdir = os.getcwd()
        self.wdir = os.getcwd()
    def enter(self):
    def enter(self):
        del sys.argv[1:]
        del sys.argv[1:]
        pdir = os.environ['SLEPC_DIR']
        pdir = os.environ['SLEPC_DIR']
        os.chdir(pdir)
        os.chdir(pdir)
        return self
        return self
    def exit(self):
    def exit(self):
        sys.argv[:] = self.sys_argv
        sys.argv[:] = self.sys_argv
        os.chdir(self.wdir)
        os.chdir(self.wdir)
 
 
class cmd_build(_build):
class cmd_build(_build):
 
 
    def initialize_options(self):
    def initialize_options(self):
        _build.initialize_options(self)
        _build.initialize_options(self)
        PETSC_ARCH = os.environ.get('PETSC_ARCH', 'installed-petsc')
        PETSC_ARCH = os.environ.get('PETSC_ARCH', 'arch-installed-petsc')
        self.build_base = os.path.join(PETSC_ARCH, 'build-python')
        self.build_base = os.path.join(PETSC_ARCH, 'build-python')
 
 
    def run(self):
    def run(self):
        _build.run(self)
        _build.run(self)
        ctx = context().enter()
        ctx = context().enter()
        try:
        try:
            config(self.dry_run)
            config(self.dry_run)
            build(self.dry_run)
            build(self.dry_run)
        finally:
        finally:
            ctx.exit()
            ctx.exit()
 
 
class cmd_install(_install):
class cmd_install(_install):
 
 
    def initialize_options(self):
    def initialize_options(self):
        _install.initialize_options(self)
        _install.initialize_options(self)
        self.optimize = 1
        self.optimize = 1
 
 
    def run(self):
    def run(self):
        root_dir = self.install_platlib
        root_dir = self.install_platlib
        dest_dir = os.path.join(root_dir, 'slepc')
        dest_dir = os.path.join(root_dir, 'slepc')
        bdist_base = self.get_finalized_command('bdist').bdist_base
        bdist_base = self.get_finalized_command('bdist').bdist_base
        if dest_dir.startswith(bdist_base):
        if dest_dir.startswith(bdist_base):
            prefix = dest_dir[len(bdist_base)+1:]
            prefix = dest_dir[len(bdist_base)+1:]
            prefix = prefix[prefix.index(os.path.sep):]
            prefix = prefix[prefix.index(os.path.sep):]
        else:
        else:
            prefix = dest_dir
            prefix = dest_dir
        dest_dir = os.path.abspath(dest_dir)
        dest_dir = os.path.abspath(dest_dir)
        prefix   = os.path.abspath(prefix)
        prefix   = os.path.abspath(prefix)
        #
        #
        _install.run(self)
        _install.run(self)
        ctx = context().enter()
        ctx = context().enter()
        try:
        try:
            install(dest_dir, prefix, self.dry_run)
            install(dest_dir, prefix, self.dry_run)
        finally:
        finally:
            ctx.exit()
            ctx.exit()
 
 
class cmd_sdist(_sdist):
class cmd_sdist(_sdist):
 
 
    def initialize_options(self):
    def initialize_options(self):
        _sdist.initialize_options(self)
        _sdist.initialize_options(self)
        self.force_manifest = 1
        self.force_manifest = 1
        self.template = os.path.join('config', 'manifest.in')
        self.template = os.path.join('config', 'manifest.in')
 
 
def version():
def version():
    import re
    import re
    version_re = {
    version_re = {
        'major'  : re.compile(r"#define\s+SLEPC_VERSION_MAJOR\s+(\d+)"),
        'major'  : re.compile(r"#define\s+SLEPC_VERSION_MAJOR\s+(\d+)"),
        'minor'  : re.compile(r"#define\s+SLEPC_VERSION_MINOR\s+(\d+)"),
        'minor'  : re.compile(r"#define\s+SLEPC_VERSION_MINOR\s+(\d+)"),
        'micro'  : re.compile(r"#define\s+SLEPC_VERSION_SUBMINOR\s+(\d+)"),
        'micro'  : re.compile(r"#define\s+SLEPC_VERSION_SUBMINOR\s+(\d+)"),
        'patch'  : re.compile(r"#define\s+SLEPC_VERSION_PATCH\s+(\d+)"),
        'patch'  : re.compile(r"#define\s+SLEPC_VERSION_PATCH\s+(\d+)"),
        'release': re.compile(r"#define\s+SLEPC_VERSION_RELEASE\s+(\d+)"),
        'release': re.compile(r"#define\s+SLEPC_VERSION_RELEASE\s+(\d+)"),
        }
        }
    slepcversion_h = os.path.join('include','slepcversion.h')
    slepcversion_h = os.path.join('include','slepcversion.h')
    data = open(slepcversion_h, 'rt').read()
    data = open(slepcversion_h, 'rt').read()
    major = int(version_re['major'].search(data).groups()[0])
    major = int(version_re['major'].search(data).groups()[0])
    minor = int(version_re['minor'].search(data).groups()[0])
    minor = int(version_re['minor'].search(data).groups()[0])
    micro = int(version_re['micro'].search(data).groups()[0])
    micro = int(version_re['micro'].search(data).groups()[0])
    patch = int(version_re['patch'].search(data).groups()[0])
    patch = int(version_re['patch'].search(data).groups()[0])
    release = int(version_re['release'].search(data).groups()[0])
    release = int(version_re['release'].search(data).groups()[0])
    if release:
    if release:
        v = "%d.%d" % (major, minor)
        v = "%d.%d" % (major, minor)
        if micro > 0:
        if micro > 0:
            v += ".%d" % micro
            v += ".%d" % micro
        if patch > 0:
        if patch > 0:
            v += ".post%d" % patch
            v += ".post%d" % patch
    else:
    else:
        v = "%d.%d.dev%d" % (major, minor+1, 0)
        v = "%d.%d.dev%d" % (major, minor+1, 0)
    return v
    return v
 
 
def tarball():
def tarball():
    VERSION = version()
    VERSION = version()
    if '.dev' in VERSION:
    if '.dev' in VERSION:
        return None
        return None
    if '.post' not in VERSION:
    if '.post' not in VERSION:
        VERSION = VERSION + '.post0'
        VERSION = VERSION + '.post0'
    VERSION = VERSION.replace('.post', '-p')
    VERSION = VERSION.replace('.post', '-p')
    return ('http://www.grycap.upv.es/slepc/download/distrib/' +
    return ('http://www.grycap.upv.es/slepc/download/distrib/' +
            'slepc-%s.tgz' % VERSION)
            'slepc-%s.tar.gz' % VERSION)
 
 
description = __doc__.split('\n')[1:-1]; del description[1:3]
description = __doc__.split('\n')[1:-1]; del description[1:3]
classifiers = """
classifiers = """
License :: Public Domain
License :: Public Domain
Operating System :: POSIX
Operating System :: POSIX
Intended Audience :: Developers
Intended Audience :: Developers
Intended Audience :: Science/Research
Intended Audience :: Science/Research
Programming Language :: C
Programming Language :: C
Programming Language :: C++
Programming Language :: C++
Programming Language :: Fortran
Programming Language :: Fortran
Programming Language :: Python
Programming Language :: Python
Topic :: Scientific/Engineering
Topic :: Scientific/Engineering
Topic :: Software Development :: Libraries
Topic :: Software Development :: Libraries
"""
"""
 
 
bootstrap()
bootstrap()
setup(name='slepc',
setup(name='slepc',
      version=version(),
      version=version(),
      description=description.pop(0),
      description=description.pop(0),
      long_description='\n'.join(description),
      long_description='\n'.join(description),
      classifiers= classifiers.split('\n')[1:-1],
      classifiers= classifiers.split('\n')[1:-1],
      keywords = ['SLEPc','PETSc', 'MPI'],
      keywords = ['SLEPc','PETSc', 'MPI'],
      platforms=['POSIX'],
      platforms=['POSIX'],
      license='LGPL',
      license='LGPL',
 
 
      url='http://www.grycap.upv.es/slepc/',
      url='http://www.grycap.upv.es/slepc/',
      download_url=tarball(),
      download_url=tarball(),
 
 
      author='SLEPc Team',
      author='SLEPc Team',
      author_email='slepc-maint@grycap.upv.es',
      author_email='slepc-maint@grycap.upv.es',
      maintainer='Lisandro Dalcin',
      maintainer='Lisandro Dalcin',
      maintainer_email='dalcinl@gmail.com',
      maintainer_email='dalcinl@gmail.com',
 
 
      packages = ['slepc'],
      packages = ['slepc'],
      package_dir = {'slepc': 'config/pypi'},
      package_dir = {'slepc': 'config/pypi'},
      cmdclass={
      cmdclass={
        'build': cmd_build,
        'build': cmd_build,
        'install': cmd_install,
        'install': cmd_install,
        'sdist': cmd_sdist,
        'sdist': cmd_sdist,
        },
        },
      **metadata)
      **metadata)