Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • jakub.both/dune-common
  • samuel.burbulla/dune-common
  • patrick.jaap/dune-common
  • tobias.leibner/dune-common
  • alexander.mueller/dune-common
  • pipping/dune-common
  • Xinyun.Li/dune-common
  • felix.schindler/dune-common
  • simon.praetorius/dune-common
  • ani.anciaux-sedrakian/dune-common
  • henrik.stolzmann/dune-common
  • matthew.t.collins/dune-common
  • liam.keegan/dune-common
  • felix.mueller/dune-common
  • ansgar/dune-common
  • dominic/dune-common
  • lars.lubkoll/dune-common
  • exadune/dune-common
  • felix.gruber/dune-common
  • govind.sahai/dune-common
  • michael.sghaier/dune-common
  • core/dune-common
  • kilian.weishaupt/dune-common
  • markus.blatt/dune-common
  • joscha.podlesny/dune-common
  • tobias.meyer.andersen/dune-common
  • andreas.thune/dune-common
  • lars.bilke/dune-common
  • daniel.kienle/dune-common
  • lukas.renelt/dune-common
  • smuething/dune-common
  • stephan.hilb/dune-common
  • tkoch/dune-common
  • nils.dreier/dune-common
  • rene.milk/dune-common
  • lasse.hinrichsen/dune-common
  • yunus.sevinchan/dune-common
  • lisa_julia.nebel/dune-common
  • claus-justus.heine/dune-common
  • lorenzo.cerrone/dune-common
  • eduardo.bueno/dune-common
41 results
Show changes
[build-system]
requires = ['setuptools', 'wheel', 'scikit-build', 'cmake', 'ninja', 'requests', 'portalocker', 'numpy']
requires = ['setuptools', 'wheel', 'scikit-build', 'cmake', 'ninja', 'requests', 'portalocker', 'numpy', 'mpi4py']
build-backend = 'setuptools.build_meta'
......@@ -4,6 +4,7 @@ add_subdirectory(typeregistry)
add_python_targets(dune
__init__
__main__
create
packagemetadata
plotting
......
import sys, os
from argparse import Action, ArgumentParser
from .packagemetadata import get_dune_py_dir
def configure():
# force a reconfiguration of dune-py by deleting tagfile
tagfile = os.path.join(get_dune_py_dir(), ".noconfigure")
if os.path.exists(tagfile):
os.remove(tagfile)
if __name__ == '__main__':
parser = ArgumentParser(description='Execute DUNE commands', prog='dune')
parser.add_argument('command', choices=['configure'], help="Command to be executed")
args = parser.parse_args()
if args.command == 'configure':
print('Configure dune-py module')
configure()
......@@ -4,6 +4,7 @@ add_python_targets(common
compatibility
deprecated # deprecated 2.8
hashit
locking
module
pickle # deprecated 2.8
project
......
......@@ -3,7 +3,7 @@ import os
logger = logging.getLogger(__name__)
loglevel = None
loglevel = logging.INFO
try:
loglevel = getattr(logging, os.environ['DUNE_LOG_LEVEL'].upper())
except KeyError:
......@@ -11,16 +11,16 @@ except KeyError:
except AttributeError:
logger.warn('Invalid log level in environment variable DUNE_LOG_LEVEL')
logformat = os.environ.get('DUNE_LOG_FORMAT')
logformat = os.environ.get('DUNE_LOG_FORMAT', 'DUNE-%(levelname)s: %(message)s')
logging.basicConfig(format=logformat, level=loglevel)
try:
from mpi4py import MPI
if MPI.COMM_WORLD.Get_rank() == 0:
logger.info('MPI initialized successfully')
logger.debug('MPI initialized successfully')
except ImportError:
logger.info('mpi4py not found, MPI not initialized')
logger.debug('mpi4py not found, MPI not initialized')
from ._common import *
from .deprecated import DeprecatedObject
......
......@@ -27,6 +27,23 @@ def assertHave(identifier):
elif matches.__len__() > 1:
raise ConfigurationError(identifier + " found multiple times in dune-py's config.h")
def assertCMakeVariable(identifier,value,defaultFails):
'''check if a variable in CMakeCache.txt in dune-py is defined and equal to 'value'
'''
cache = os.path.join(dune.common.module.get_dune_py_dir(), "CMakeCache.txt")
identifier = identifier.lower().strip()
matches = [line.lower() for line in open(cache) if re.match('^[ ]*'+identifier+':+', line.lower()) is not None]
if not matches and defaultFails:
raise ConfigurationError(identifier + " default behavior is used in dune-py and that is not allowed")
elif len(matches) > 1:
raise ConfigurationError(identifier + " found multiple times in dune-py's config.h")
elif matches:
# check for bool on/off type variables:
bools = {True:["on","true","1"], False:["off","false","0"]}
if not [x for x in bools[value] if x in matches[0]]:
raise ConfigurationError(identifier + " dune-py wrongly configured wrt "+identifier)
def preprocessorAssert(tests):
'''perform preprocessore checks.
A list of checks can be provided each should contain a pair, the
......
try:
from portalocker import Lock as _Lock
from portalocker.constants import LOCK_EX, LOCK_SH
class Lock(_Lock):
def __init__(self, path, flags, *args, **kwargs):
_Lock.__init__(self,path,*args,flags=flags,timeout=None,**kwargs)
except ModuleNotFoundError:
import os
import fcntl
from fcntl import LOCK_EX, LOCK_SH
# file locking from fcntl
def lock_file(f, cmd=fcntl.LOCK_EX):
fcntl.flock(f, cmd)
return f
def unlock_file(f):
fcntl.flock(f, fcntl.LOCK_UN)
return f
# This file opener *must* be used in a "with" block.
class Lock:
# Open the file with arguments provided by user. Then acquire
# a lock on that file object (WARNING: Advisory locking).
def __init__(self, path, flags, *args, **kwargs):
# Open the file and acquire a lock on the file before operating
self.file = open(path, mode='w+', *args, **kwargs)
# Lock the opened file
self.file = lock_file(self.file, flags) # flags are either LOCK_EX or LOCK_SH
# Return the opened file object (knowing a lock has been obtained).
def __enter__(self, *args, **kwargs): return self.file
# Unlock the file and close the file object.
def __exit__(self, exc_type=None, exc_value=None, traceback=None):
# Flush to make sure all buffered contents are written to file.
self.file.flush()
os.fsync(self.file.fileno())
# Release the lock on the file.
self.file = unlock_file(self.file)
self.file.close()
# Handle exceptions that may have come up during execution, by
# default any exceptions are raised to the user.
return exc_type == None
......@@ -16,12 +16,12 @@ if __name__ == "dune.common.module":
from dune.common.utility import buffer_to_str
from dune.common import project
from dune.packagemetadata import Version, VersionRequirement,\
Description, cmakeFlags, cmakeArguments
Description, cmakeFlags, cmakeArguments, inVEnv, get_dune_py_dir
else:
from utility import buffer_to_str
import project
from packagemetadata import Version, VersionRequirement,\
Description, cmakeFlags, cmakeArguments
Description, cmakeFlags, cmakeArguments, inVEnv, get_dune_py_dir
logger = logging.getLogger(__name__)
......@@ -123,19 +123,23 @@ def resolve_order(deps):
return order
def pkg_config(pkg, var=None):
def pkg_config(pkg, var=None, paths=[]):
args = ['pkg-config', pkg]
if var is not None:
args += ['--variable=' + var]
pkgconfig = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
env = dict(os.environ)
env.update({'PKG_CONFIG_PATH': ':'.join(paths)})
pkgconfig = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
pkgconfig.wait()
prefix = pkgconfig.stdout.read()
if pkgconfig.returncode != 0:
raise KeyError('package ' + pkg + ' not found.')
return buffer_to_str(pkgconfig.stdout.read()).strip()
return buffer_to_str(prefix).strip()
def get_prefix(module):
return pkg_config(module, 'prefix')
paths = get_module_path("pkgconfig")
return pkg_config(module, var='prefix', paths=paths)
def is_installed(dir, module=None):
......@@ -154,9 +158,13 @@ def is_installed(dir, module=None):
if isinstance(module, Description):
module = module.name
try:
return dir == os.path.join(get_prefix(module), 'lib', 'dunecontrol', module)
prefix = get_prefix(module)
except KeyError:
return False
for l in ['lib','lib32','lib64']:
if os.path.realpath(dir) == os.path.realpath(os.path.join(prefix, l, 'dunecontrol', module)):
return True
return False
def get_cmake_command():
try:
......@@ -174,38 +182,42 @@ def get_local():
pass
return ''
def get_module_path():
path = []
def get_module_path(post="dunecontrol"):
path = ['.']
# try to guess modules path for unix systems
for l in ['lib','lib32','lib64']:
path = path + [p for p in [
os.path.join('usr','local',l,post),
os.path.join('usr',l,post),
os.path.join(get_local(),l,post),
]
if os.path.isdir(p)]
try:
path = path + [p for p in os.environ['DUNE_CONTROL_PATH'].split(':') if p and os.path.isdir(p)]
logger.debug('Module path [DUNE_CONTROL_PATH]: ' + ':'.join(path))
# return path
if post == 'dunecontrol':
logger.debug('Module path [DUNE_CONTROL_PATH]: ' + ':'.join(path))
except KeyError:
pass
# try to guess module path using pkg-config
try:
prefix = pkg_config('dune-common', 'prefix').strip()
path = path + [p for p in ['.', os.path.join(prefix, 'lib', 'dunecontrol')] if os.path.isdir(p)]
logger.debug('Module path [pkg-config]: ' + ':'.join(path))
# return path
pkg_config_path = [p for p in os.environ['PKG_CONFIG_PATH'].split(':') if p and os.path.isdir(p)]
if post == 'dunecontrol':
pkg_config_path = [os.path.join(p, '..', post) for p in pkg_config_path]
path = path + [p for p in pkg_config_path if os.path.isdir(p)]
except KeyError:
pass
# try to guess modules path for unix systems
path = path + [p for p in ['.',
'/usr/local/lib/dunecontrol',
'/usr/lib/dunecontrol',
os.path.join(get_local(),'lib','dunecontrol') ]
if os.path.isdir(p)]
# try to guess module path using pkg-config
try:
pkg_config_path = [p for p in os.environ['PKG_CONFIG_PATH'].split(':') if p and os.path.isdir(p)]
pkg_config_path = [os.path.join(p, '..', 'dunecontrol') for p in pkg_config_path]
path = path + [p for p in pkg_config_path if os.path.isdir(p)]
prefix = pkg_config('dune-common', 'prefix').strip()
path = path + [p for p in [ os.path.join(prefix, 'lib', post)] if os.path.isdir(p)]
path = path + [p for p in [ os.path.join(prefix, 'lib32', post)] if os.path.isdir(p)]
path = path + [p for p in [ os.path.join(prefix, 'lib64', post)] if os.path.isdir(p)]
if post == 'dunecontrol':
logger.debug('Module path [pkg-config]: ' + ':'.join(path))
except KeyError:
pass
logger.debug('Module path [guessed]: ' + ':'.join(path))
if post == 'dunecontrol':
logger.debug('Module path [guessed]: ' + ':'.join(path))
return path
......@@ -215,7 +227,7 @@ def select_modules(modules=None, module=None):
Args:
modules (optional): List of (description, dir) pairs
If not given, the find_modules(get_module_path()) is used
module (optional):
module (optional):
Returns:
pair of dictionaries mapping module name to unique description and directory respectively
......@@ -225,17 +237,20 @@ def select_modules(modules=None, module=None):
desc = {}
dir = {}
for d, p in modules:
p = os.path.realpath(p)
n = d.name
if n in dir:
if p == dir[n]: continue
if is_installed(dir[n], n):
if is_installed(p, n):
raise KeyError('Multiple installed versions for module \'' + n + '\' found.')
foundVersions = " In " + p + " and in " + dir[n]
raise KeyError('Multiple installed versions for module \'' + n + '\' found.'+foundVersions)
else:
desc[n], dir[n] = d, p
desc[n], dir[n] = d, p
else:
if not is_installed(p, n):
raise KeyError('Multiple source versions for module \'' + n + '\' found.')
foundVersions = " In " + p + " and in " + dir[n]
raise KeyError('Multiple source versions for module \'' + n + '\' found.'+foundVersions)
else:
desc[n], dir[n] = d, p
return (desc, dir)
......@@ -304,41 +319,6 @@ def build_module(builddir, build_args=None):
raise RuntimeError(buffer_to_str(stderr))
return buffer_to_str(stdout)
def inVEnv():
# If sys.real_prefix exists, this is a virtualenv set up with the virtualenv package
real_prefix = hasattr(sys, 'real_prefix')
if real_prefix:
return 1
# If a virtualenv is set up with pyvenv, we check for equality of base_prefix and prefix
if hasattr(sys, 'base_prefix'):
return (sys.prefix != sys.base_prefix)
# If none of the above conditions triggered, this is probably no virtualenv interpreter
return 0
def get_dune_py_dir():
try:
basedir = os.path.realpath( os.environ['DUNE_PY_DIR'] )
basedir = os.path.join(basedir,'dune-py')
return basedir
except KeyError:
pass
# test if in virtual env
if inVEnv():
virtualEnvPath = sys.prefix
return os.path.join(virtualEnvPath, '.cache', 'dune-py')
# generate in home directory
try:
home = expanduser("~")
return os.path.join(home, '.cache', 'dune-py')
except KeyError:
pass
raise RuntimeError('Unable to determine location for dune-py module. Please set the environment variable "DUNE_PY_DIR".')
def get_dune_py_version():
# change this version on the following events:
# - a release (major version numbers)
......@@ -379,7 +359,7 @@ def make_dune_py_module(dune_py_dir=None, deps=None):
deps = modules.keys()
description = Description(module='dune-py', version=get_dune_py_version(), maintainer='dune@lists.dune-project.org', depends=list(deps))
logger.debug('dune-py will depend on ' + ' '.join([m[0] + (' ' + str(c) if c else '') for m, c in description.depends]))
logger.debug('dune-py will depend on ' + ' '.join([m + (' ' + str(c) if c else '') for m, c in description.depends]))
project.make_project(dune_py_dir, description,
subdirs=[generated_dir_rel], is_dunepy=True)
else:
......@@ -390,9 +370,9 @@ def make_dune_py_module(dune_py_dir=None, deps=None):
logger.error('"' + dune_py_dir + '" contains version ' + str(description.version) + ' of the dune-py module, ' + str(get_dune_py_version()) + ' required.')
logger.error('If you upgraded dune-python, you can safely remove "' + dune_py_dir + '" and retry.')
raise RuntimeError('"' + dune_py_dir + '" contains a different version of the dune-py module.')
logger.info('Using dune-py module in ' + dune_py_dir)
logger.debug('Using dune-py module in ' + dune_py_dir)
def build_dune_py_module(dune_py_dir=None, cmake_args=None, build_args=None, builddir=None, deps=None):
def build_dune_py_module(dune_py_dir=None, cmake_args=None, build_args=None, builddir=None, deps=None, writetagfile=False):
if dune_py_dir is None:
dune_py_dir = get_dune_py_dir()
if cmake_args is None:
......@@ -416,12 +396,33 @@ def build_dune_py_module(dune_py_dir=None, cmake_args=None, build_args=None, bui
prefix = {}
for name, dir in dirs.items():
if is_installed(dir, name):
prefix[name] = get_prefix(name)
found = False
# switch prefix to location of name-config.cmake
for l in ['lib','lib32','lib64']:
substr = l + '/cmake'
newpath = dir.replace('lib/dunecontrol', substr)
for _, _, files in os.walk(newpath):
# if name-config.cmake is found
# then this is the correct folder
if name+'-config.cmake' in files:
found = True
prefix[name] = newpath
break
if found: break
assert found
# store new module path
else:
prefix[name] = default_build_dir(dir, name, builddir)
logger.info('Configuring dune-py module in ' + dune_py_dir)
output = configure_module(dune_py_dir, dune_py_dir, {d: prefix[d] for d in deps}, cmake_args)
output += build_module(dune_py_dir, build_args)
if writetagfile:
# set a tag file to avoid automatic reconfiguration in builder
tagfile = os.path.join(dune_py_dir, ".noconfigure")
f = open(tagfile, 'w')
f.close()
return output
def getCXXFlags():
......
......@@ -80,13 +80,6 @@ def make_project(dir, description, subdirs=None, enable_all_packages=True, is_du
cmake_content += ['', 'include(DuneMacros)', 'dune_project()']
if enable_all_packages:
cmake_content += ['dune_enable_all_packages()']
if is_dunepy:
cmake_content += ['',
'if( dune-uggrid_FOUND )',
' if( NOT BUILD_SHARED_LIBS )',
' message(SEND_ERROR "dune-uggrid found but shared libs disabled! Python bindings for UGGrid will only work with shared -DBUILD_SHARED_LIBS=ON")',
' endif()',
'endif()']
if subdirs is not None:
cmake_content += [''] + ['add_subdirectory("' + d + '")' for d in subdirs]
cmake_content += ['', 'finalize_dune_project(GENERATE_CONFIG_H_CMAKE)']
......
......@@ -36,7 +36,7 @@ for importer, modname, ispkg in pkgutil.iter_modules(package.__path__, prefix):
moduleRegistry = module.registry.items()
logMsg = logMsg + modname + " "
except AttributeError:
logger.debug('module ' + modname + ' does not provide a registry.')
logger.debug('Module ' + modname + ' does not provide a registry.')
continue
# combine all registries
......@@ -57,7 +57,7 @@ for importer, modname, ispkg in pkgutil.iter_modules(package.__path__, prefix):
_create_map.setdefault("view",{}).update(_create_map["grid"])
logMsg = logMsg + "]"
logger.info(logMsg)
logger.debug(logMsg)
############################################################################
def get(category=None,entry=None):
......
......@@ -12,13 +12,13 @@ env_save = os.environ.get('DUNE_SAVE_BUILD' , 'FALSE').upper()
builder = Builder( env_force in ('1', 'TRUE'), env_save )
def setNoDependencyCheck():
logger.info("Switching off dependency check - modules will always be compiled")
logger.debug("Switching off dependency check - modules will always be compiled")
builderModule.noDepCheck = True
def setDependencyCheck():
logger.info("Switching on dependency check")
logger.debug("Switching on dependency check")
builderModule.noDepCheck = False
def setFlags(flags="-g",noChecks=None):
logger.info("Using compile flags '"+flags+"'")
logger.debug("Using compile flags '"+flags+"'")
builderModule.cxxFlags = flags
if noChecks is True:
setNoDependencyCheck()
......@@ -28,7 +28,7 @@ def addToFlags(pre="",post="",noChecks=None):
setFlags(pre+" "+getCXXFlags()+" "+post,noChecks)
def unsetFlags(noChecks=None):
logger.info("Using compile flags from configuration of dune-py")
logger.debug("Using compile flags from configuration of dune-py")
builderModule.cxxFlags = None
if noChecks is True:
setNoDependencyCheck()
......
......@@ -5,49 +5,8 @@ import subprocess
import os
import sys
try:
from portalocker import Lock as _Lock
from portalocker.constants import LOCK_EX, LOCK_SH
class Lock(_Lock):
def __init__(self, path, flags, *args, **kwargs):
_Lock.__init__(self,path,*args,flags=flags,timeout=None,**kwargs)
except ModuleNotFoundError:
import fcntl
from fcntl import LOCK_EX, LOCK_SH
# file locking from fcntl
def lock_file(f, cmd=fcntl.LOCK_EX):
fcntl.flock(f, cmd)
return f
def unlock_file(f):
fcntl.flock(f, fcntl.LOCK_UN)
return f
# This file opener *must* be used in a "with" block.
class Lock:
# Open the file with arguments provided by user. Then acquire
# a lock on that file object (WARNING: Advisory locking).
def __init__(self, path, flags, *args, **kwargs):
# Open the file and acquire a lock on the file before operating
self.file = open(path, mode='w+', *args, **kwargs)
# Lock the opened file
self.file = lock_file(self.file, flags) # flags are either LOCK_EX or LOCK_SH
# Return the opened file object (knowing a lock has been obtained).
def __enter__(self, *args, **kwargs): return self.file
# Unlock the file and close the file object.
def __exit__(self, exc_type=None, exc_value=None, traceback=None):
# Flush to make sure all buffered contents are written to file.
self.file.flush()
os.fsync(self.file.fileno())
# Release the lock on the file.
self.file = unlock_file(self.file)
self.file.close()
# Handle exceptions that may have come up during execution, by
# default any exceptions are raised to the user.
return exc_type == None
from dune.common import comm
from dune.common.locking import Lock, LOCK_EX,LOCK_SH
from dune.common.utility import buffer_to_str, isString, reload_module
from dune.generator.exceptions import CompileError, ConfigurationError
import dune.common.module
......@@ -70,8 +29,10 @@ class Builder:
tagfile = os.path.join(self.dune_py_dir, ".noconfigure")
if not os.path.isfile(tagfile):
dune.common.module.build_dune_py_module(self.dune_py_dir)
# create .noconfigure to disable configuration for future calls
open(tagfile, 'a').close()
else:
logger.info('using pre configured dune-py module')
logger.debug('Using pre configured dune-py module')
comm.barrier()
self.build_args = dune.common.module.get_default_build_args()
......@@ -105,9 +66,8 @@ class Builder:
cmake_args += ["--"] + make_args
cmake = subprocess.Popen(cmake_args, cwd=self.generated_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = cmake.communicate()
logger.debug(buffer_to_str(stdout))
logger.debug("Compiler output: "+buffer_to_str(stdout))
if cmake.returncode > 0:
logger.error(buffer_to_str(stderr))
raise CompileError(buffer_to_str(stderr))
if self.savedOutput is not None:
out = buffer_to_str(stdout)
......@@ -142,35 +102,45 @@ class Builder:
# module must be generated so lock the source file
with Lock(os.path.join(self.dune_py_dir, 'lock-'+moduleName+'.lock'), flags=LOCK_EX):
sourceFileName = os.path.join(self.generated_dir, moduleName + ".cc")
if not os.path.isfile(sourceFileName):
logger.info("Loading " + pythonName + " (new)")
line = "dune_add_pybind11_module(NAME " + moduleName + " EXCLUDE_FROM_ALL)"
# first check if this line is already present in the CMakeLists file
# (possible if a previous script was stopped by user before module was compiled)
with open(os.path.join(self.generated_dir, "CMakeLists.txt"), 'r') as out:
found = line in out.read()
if not os.path.isfile(sourceFileName) or not found:
logger.info("Compiling " + pythonName)
code = str(source)
# the CMakeLists.txt needs changing and cmake rerun - lock folder
with open(os.path.join(sourceFileName), 'w') as out:
out.write(code)
line = "dune_add_pybind11_module(NAME " + moduleName + " EXCLUDE_FROM_ALL)"
# first check if this line is already present in the CMakeLists file
# (possible if a previous script was stopped by user before module was compiled)
with open(os.path.join(self.generated_dir, "CMakeLists.txt"), 'r') as out:
found = line in out.read()
if not found:
with open(os.path.join(self.generated_dir, "CMakeLists.txt"), 'a') as out:
out.write(line+"\n")
# update build system
self.compile()
logger.debug("Rebuilding module")
try:
self.compile()
except KeyboardInterrupt:
os.remove(os.path.join(sourceFileName))
raise
elif isString(source) and not source == open(os.path.join(sourceFileName), 'r').read():
logger.info("Loading " + pythonName + " (updated)")
logger.info("Compiling " + pythonName + " (updated)")
code = str(source)
with open(os.path.join(sourceFileName), 'w') as out:
out.write(code)
else:
logger.info("Loading " + pythonName)
logger.debug("Loading " + pythonName)
line = "dune_add_pybind11_module(NAME " + moduleName + " EXCLUDE_FROM_ALL)"
# the CMakeLists file should already include this line
with open(os.path.join(self.generated_dir, "CMakeLists.txt"), 'r') as out:
found = line in out.read()
assert found, "CMakeLists file does not contain an entry to build"+moduleName
# end of exclusive dune-py lock
# for compilation a shared lock is enough
with Lock(os.path.join(self.dune_py_dir, 'lock-module.lock'), flags=LOCK_SH):
# lock generated module
with Lock(os.path.join(self.dune_py_dir, 'lock-'+moduleName+'.lock'), flags=LOCK_EX):
logger.debug("Now compiling "+moduleName)
self.compile(moduleName)
## end if module is not None
......
......@@ -106,7 +106,7 @@ class Description:
data = kwargs.copy()
valid_entries = ['Module','Maintainer','Version','Maintainer',
'Depends','Suggests',
'Depends','Suggests','Python-Requires',
'Whitespace-Hook',
'Author','Description','URL']
......@@ -117,7 +117,7 @@ class Description:
line = line.strip()
if not line or line[ 0 ] == '#':
continue
m = re.search(r'^(\w+):(.*)', line)
m = re.search(r'^([a-zA-Z0-9-_]+):(.*)', line)
if m:
key = m.group(1)
val = m.group(2)
......@@ -265,13 +265,53 @@ def cmakeFlags():
]))
# test environment for additional flags
cmakeFlags = os.environ.get('DUNE_CMAKE_FLAGS')
if cmakeFlags is None:
cmakeFlags = os.environ.get('CMAKE_FLAGS')
# split cmakeFlags and add them to flags
if cmakeFlags is not None:
flags += shlex.split(cmakeFlags)
cmakeFlags = os.environ.get('CMAKE_FLAGS')
if cmakeFlags is not None:
flags += shlex.split(cmakeFlags)
return flags
def inVEnv():
# check whether we are in a anaconda environment
# were the checks based on prefix and base_prefix
# seem to fail
if "CONDA_DEFAULT_ENV" in os.environ:
return 1
# If sys.real_prefix exists, this is a virtualenv set up with the virtualenv package
real_prefix = hasattr(sys, 'real_prefix')
if real_prefix:
return 1
# If a virtualenv is set up with pyvenv, we check for equality of base_prefix and prefix
if hasattr(sys, 'base_prefix'):
return (sys.prefix != sys.base_prefix)
# If none of the above conditions triggered, this is probably no virtualenv interpreter
return 0
def get_dune_py_dir():
try:
basedir = os.path.realpath( os.environ['DUNE_PY_DIR'] )
basedir = os.path.join(basedir,'dune-py')
return basedir
except KeyError:
pass
# test if in virtual env
if inVEnv():
virtualEnvPath = sys.prefix
return os.path.join(virtualEnvPath, '.cache', 'dune-py')
# generate in home directory
try:
home = os.path.expanduser("~")
return os.path.join(home, '.cache', 'dune-py')
except KeyError:
pass
raise RuntimeError('Unable to determine location for dune-py module. Please set the environment variable "DUNE_PY_DIR".')
def metaData(version=None, dependencyCheck=True):
data = Data(version)
......@@ -334,4 +374,14 @@ def metaData(version=None, dependencyCheck=True):
"python_requires":'>=3.4',
})
from skbuild.command.build_py import build_py
class DunepyConfigure(build_py):
def run(self):
build_py.run(self)
subprocess.call([sys.executable, '-m', 'dune', 'configure'])
setupParams['cmdclass'] = {
'build_py': DunepyConfigure,
}
return data, setupParams