damask.Environment reads from os.environ; python module is packaging-ready

This commit is contained in:
Philip Eisenlohr 2020-01-13 17:26:40 -05:00
parent edbee3a419
commit 86f27df0b2
18 changed files with 119 additions and 173 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
*.hdf5 *.hdf5
*.bak *.bak
*~ *~
.DS_Store
bin bin
PRIVATE PRIVATE
build build

View File

@ -4,7 +4,7 @@ SHELL = /bin/sh
######################################################################################## ########################################################################################
DAMASK_ROOT = $(shell python -c "import os,sys; print(os.path.normpath(os.path.realpath(os.path.expanduser('$(pwd)'))))") DAMASK_ROOT = $(shell python -c "import os,sys; print(os.path.normpath(os.path.realpath(os.path.expanduser('$(pwd)'))))")
.PHONY: all .PHONY: all
all: grid mesh python processing all: grid mesh processing
.PHONY: grid .PHONY: grid
grid: build/grid grid: build/grid
@ -35,8 +35,3 @@ clean:
.PHONY: processing .PHONY: processing
processing: processing:
@./installation/symlink_Processing.py ${MAKEFLAGS} @./installation/symlink_Processing.py ${MAKEFLAGS}
.PHONY: python
python:
@pip install --user ./python

@ -1 +1 @@
Subproject commit 036faecca39b46fd2328597ca858cbb04e37f79a Subproject commit 12de3e01e3dfa407a724b6aeca51c78e9981b80d

View File

11
env/DAMASK.csh vendored
View File

@ -2,15 +2,14 @@
# usage: source DAMASK_env.csh # usage: source DAMASK_env.csh
set CALLED=($_) set CALLED=($_)
set DIRNAME=`dirname $CALLED[2]` set ENV_ROOT=`dirname $CALLED[2]`
set DAMASK_ROOT=`python -c "import os,sys; print(os.path.realpath(os.path.expanduser(sys.argv[1])))" $DIRNAME"/../"` set DAMASK_ROOT=`python -c "import os,sys; print(os.path.realpath(os.path.expanduser(sys.argv[1])))" $ENV_ROOT"/../"`
source $DAMASK_ROOT/CONFIG source $ENV_ROOT/CONFIG
set path = ($DAMASK_ROOT/bin $path) set path = ($DAMASK_ROOT/bin $path)
set SOLVER=`which DAMASK_spectral` set SOLVER=`which DAMASK_spectral`
set PROCESSING=`which postResults`
if ( "x$DAMASK_NUM_THREADS" == "x" ) then if ( "x$DAMASK_NUM_THREADS" == "x" ) then
set DAMASK_NUM_THREADS=1 set DAMASK_NUM_THREADS=1
endif endif
@ -32,7 +31,6 @@ if ( $?prompt ) then
echo Using environment with ... echo Using environment with ...
echo "DAMASK $DAMASK_ROOT" echo "DAMASK $DAMASK_ROOT"
echo "Grid Solver $SOLVER" echo "Grid Solver $SOLVER"
echo "Post Processing $PROCESSING"
if ( $?PETSC_DIR) then if ( $?PETSC_DIR) then
echo "PETSc location $PETSC_DIR" echo "PETSc location $PETSC_DIR"
endif endif
@ -52,3 +50,6 @@ if ( ! $?PYTHONPATH ) then
else else
setenv PYTHONPATH $DAMASK_ROOT/python:$PYTHONPATH setenv PYTHONPATH $DAMASK_ROOT/python:$PYTHONPATH
endif endif
setenv MSC_ROOT
setenv ABAQUS_VERSION
setenv MARC_VERSION

22
env/DAMASK.sh vendored
View File

@ -10,14 +10,14 @@ function blink {
} }
if [ "$OSTYPE" == "linux-gnu" ] || [ "$OSTYPE" == 'linux' ]; then if [ "$OSTYPE" == "linux-gnu" ] || [ "$OSTYPE" == 'linux' ]; then
DAMASK_ROOT=$(dirname $BASH_SOURCE) ENV_ROOT=$(dirname $BASH_SOURCE)
else else
[[ "${BASH_SOURCE::1}" == "/" ]] && BASE="" || BASE="$(pwd)/" [[ "${BASH_SOURCE::1}" == "/" ]] && BASE="" || BASE="$(pwd)/"
STAT=$(stat "$(dirname $BASE$BASH_SOURCE)") STAT=$(stat "$(dirname $BASE$BASH_SOURCE)")
DAMASK_ROOT=${STAT##* } ENV_ROOT=${STAT##* }
fi fi
DAMASK_ROOT=$(canonicalPath "$DAMASK_ROOT/../") DAMASK_ROOT=$(canonicalPath "$ENV_ROOT/../")
# shorthand command to change to DAMASK_ROOT directory # shorthand command to change to DAMASK_ROOT directory
@ -27,7 +27,7 @@ eval "function DAMASK_root() { cd $DAMASK_ROOT; }"
set() { set() {
export $1$2$3 export $1$2$3
} }
source $DAMASK_ROOT/CONFIG source $ENV_ROOT/CONFIG
unset -f set unset -f set
# add BRANCH if DAMASK_ROOT is a git repository # add BRANCH if DAMASK_ROOT is a git repository
@ -38,9 +38,6 @@ PATH=${DAMASK_ROOT}/bin:$PATH
SOLVER=$(type -p DAMASK_spectral || true 2>/dev/null) SOLVER=$(type -p DAMASK_spectral || true 2>/dev/null)
[ "x$SOLVER" == "x" ] && SOLVER=$(blink 'Not found!') [ "x$SOLVER" == "x" ] && SOLVER=$(blink 'Not found!')
PROCESSING=$(type -p postResults || true 2>/dev/null)
[ "x$PROCESSING" == "x" ] && PROCESSING=$(blink 'Not found!')
[ "x$DAMASK_NUM_THREADS" == "x" ] && DAMASK_NUM_THREADS=1 [ "x$DAMASK_NUM_THREADS" == "x" ] && DAMASK_NUM_THREADS=1
# currently, there is no information that unlimited stack size causes problems # currently, there is no information that unlimited stack size causes problems
@ -60,7 +57,6 @@ if [ ! -z "$PS1" ]; then
echo Using environment with ... echo Using environment with ...
echo "DAMASK $DAMASK_ROOT $BRANCH" echo "DAMASK $DAMASK_ROOT $BRANCH"
echo "Grid Solver $SOLVER" echo "Grid Solver $SOLVER"
echo "Post Processing $PROCESSING"
if [ "x$PETSC_DIR" != "x" ]; then if [ "x$PETSC_DIR" != "x" ]; then
echo -n "PETSc location " echo -n "PETSc location "
[ -d $PETSC_DIR ] && echo $PETSC_DIR || blink $PETSC_DIR [ -d $PETSC_DIR ] && echo $PETSC_DIR || blink $PETSC_DIR
@ -93,12 +89,8 @@ fi
export DAMASK_NUM_THREADS export DAMASK_NUM_THREADS
export PYTHONPATH=$DAMASK_ROOT/python:$PYTHONPATH export PYTHONPATH=$DAMASK_ROOT/python:$PYTHONPATH
for var in BASE STAT SOLVER PROCESSING BRANCH; do for var in BASE STAT SOLVER BRANCH; do
unset "${var}" unset "${var}"
done done
for var in DAMASK MSC; do unset "ENV_ROOT"
unset "${var}_ROOT" unset "DAMASK_ROOT"
done
for var in ABAQUS MARC; do
unset "${var}_VERSION"
done

17
env/DAMASK.zsh vendored
View File

@ -9,6 +9,7 @@ function blink {
echo -e "\033[2;5m$1\033[0m" echo -e "\033[2;5m$1\033[0m"
} }
ENV_ROOT=$(canonicalPath "${0:a:h}")
DAMASK_ROOT=$(canonicalPath "${0:a:h}'/..") DAMASK_ROOT=$(canonicalPath "${0:a:h}'/..")
# shorthand command to change to DAMASK_ROOT directory # shorthand command to change to DAMASK_ROOT directory
@ -18,7 +19,7 @@ eval "function DAMASK_root() { cd $DAMASK_ROOT; }"
set() { set() {
export $1$2$3 export $1$2$3
} }
source $DAMASK_ROOT/CONFIG source $ENV_ROOT/CONFIG
unset -f set unset -f set
# add BRANCH if DAMASK_ROOT is a git repository # add BRANCH if DAMASK_ROOT is a git repository
@ -29,9 +30,6 @@ PATH=${DAMASK_ROOT}/bin:$PATH
SOLVER=$(which DAMASK_spectral || true 2>/dev/null) SOLVER=$(which DAMASK_spectral || true 2>/dev/null)
[[ "x$SOLVER" == "x" ]] && SOLVER=$(blink 'Not found!') [[ "x$SOLVER" == "x" ]] && SOLVER=$(blink 'Not found!')
PROCESSING=$(which postResults || true 2>/dev/null)
[[ "x$PROCESSING" == "x" ]] && PROCESSING=$(blink 'Not found!')
[[ "x$DAMASK_NUM_THREADS" == "x" ]] && DAMASK_NUM_THREADS=1 [[ "x$DAMASK_NUM_THREADS" == "x" ]] && DAMASK_NUM_THREADS=1
# currently, there is no information that unlimited stack size causes problems # currently, there is no information that unlimited stack size causes problems
@ -51,7 +49,6 @@ if [ ! -z "$PS1" ]; then
echo "Using environment with ..." echo "Using environment with ..."
echo "DAMASK $DAMASK_ROOT $BRANCH" echo "DAMASK $DAMASK_ROOT $BRANCH"
echo "Grid Solver $SOLVER" echo "Grid Solver $SOLVER"
echo "Post Processing $PROCESSING"
if [ "x$PETSC_DIR" != "x" ]; then if [ "x$PETSC_DIR" != "x" ]; then
echo -n "PETSc location " echo -n "PETSc location "
[ -d $PETSC_DIR ] && echo $PETSC_DIR || blink $PETSC_DIR [ -d $PETSC_DIR ] && echo $PETSC_DIR || blink $PETSC_DIR
@ -86,12 +83,8 @@ fi
export DAMASK_NUM_THREADS export DAMASK_NUM_THREADS
export PYTHONPATH=$DAMASK_ROOT/python:$PYTHONPATH export PYTHONPATH=$DAMASK_ROOT/python:$PYTHONPATH
for var in SOLVER PROCESSING BRANCH; do for var in SOLVER BRANCH; do
unset "${var}" unset "${var}"
done done
for var in DAMASK MSC; do unset "ENV_ROOT"
unset "${var}_ROOT" unset "DAMASK_ROOT"
done
for var in ABAQUS MARC; do
unset "${var}_VERSION"
done

View File

@ -2,11 +2,6 @@
SCRIPTLOCATION="$( cd "$( dirname "$0" )" && pwd )" SCRIPTLOCATION="$( cd "$( dirname "$0" )" && pwd )"
DAMASK_ROOT=$SCRIPTLOCATION/../../ DAMASK_ROOT=$SCRIPTLOCATION/../../
# defining set() allows to source the same file for tcsh and bash, with and without space around =
set() {
export $1$2$3
}
source $DAMASK_ROOT/CONFIG
if [ "x$MSC_ROOT" != "x" ]; then if [ "x$MSC_ROOT" != "x" ]; then
DEFAULT_DIR=$MSC_ROOT DEFAULT_DIR=$MSC_ROOT
@ -15,7 +10,7 @@ if [ "x$MARC_VERSION" != "x" ]; then
DEFAULT_VERSION=$MARC_VERSION DEFAULT_VERSION=$MARC_VERSION
fi fi
if [ "x$DAMASK_BIN" != "x" ]; then if [ "x$DAMASK_BIN" != "x" ]; then
BIN_DIR=$DAMASK_BIN BIN_DIR=$DAMASK_ROOT/bin
fi fi
while [ ! -d "$SCRIPTLOCATION/$VERSION" ] || [ -z "$VERSION" ] while [ ! -d "$SCRIPTLOCATION/$VERSION" ] || [ -z "$VERSION" ]

View File

@ -1,3 +1,2 @@
include damask/README
include damask/VERSION include damask/VERSION
include damask/LICENSE include damask/LICENSE

View File

@ -1,14 +0,0 @@
Copyright 2011-19 Max-Planck-Institut für Eisenforschung GmbH
DAMASK is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

1
python/damask/LICENSE Symbolic link
View File

@ -0,0 +1 @@
../../LICENSE

View File

@ -1,13 +0,0 @@
DAMASK - The Düsseldorf Advanced Material Simulation Kit
Visit damask.mpie.de for installation and usage instructions
CONTACT INFORMATION
Max-Planck-Institut für Eisenforschung GmbH
Max-Planck-Str. 1
40237 Düsseldorf
Germany
Email: DAMASK@mpie.de
https://damask.mpie.de
https://magit1.mpie.de

View File

@ -1 +0,0 @@
0.9.0

1
python/damask/VERSION Symbolic link
View File

@ -0,0 +1 @@
../../VERSION

View File

@ -1,5 +1,4 @@
import os import os
import re
class Environment(): class Environment():
__slots__ = [ \ __slots__ = [ \
@ -18,12 +17,9 @@ class Environment():
return os.path.normpath(os.path.join(os.path.realpath(__file__),'../../../')) return os.path.normpath(os.path.join(os.path.realpath(__file__),'../../../'))
def get_options(self): def get_options(self):
with open(self.relPath(self.rootDir()+'/CONFIG')) as configFile: for item in ['DAMASK_NUM_THREADS',
for line in configFile: 'MSC_ROOT',
line = line.strip() 'MARC_VERSION',
line = line[4:] if line.startswith('set ') else line # remove "set" (tcsh) when setting variables 'ABAQUS_VERSION',
if line and not line.startswith('#'): ]:
items = re.split(r'\s*=\s*',line) self.options[item] = os.environ[item] if item in os.environ else None
if len(items) == 2:
self.options[items[0].upper()] = \
re.sub(r'\${?DAMASK_ROOT}?',self.rootDir(),os.path.expandvars(items[1])) # expand all shell variables and DAMASK_ROOT

View File

@ -7,7 +7,7 @@ import damask
class Abaqus(Solver): class Abaqus(Solver):
"""Wrapper to run DAMASK with Abaqus.""" """Wrapper to run DAMASK with Abaqus."""
def __init__(self,version=int(damask.Environment().options['ABAQUS_VERSION'])): def __init__(self,version=None):
""" """
Create a Abaqus solver object. Create a Abaqus solver object.
@ -18,11 +18,17 @@ class Abaqus(Solver):
""" """
self.solver = 'Abaqus' self.solver = 'Abaqus'
try:
self.version = int(version) self.version = int(version)
except TypeError:
try:
self.version = int(damask.Environment().options['ABAQUS_VERSION'])
except TypeError:
self.version = -1
def return_run_command(self,model): def return_run_command(self,model):
try: try:
cmd = 'abq'+self.version cmd = 'abq{}'.format(self.version)
subprocess.check_output([cmd,'information=release']) subprocess.check_output([cmd,'information=release'])
except OSError: # link to abqXXX not existing except OSError: # link to abqXXX not existing
cmd = 'abaqus' cmd = 'abaqus'

View File

@ -1,6 +1,7 @@
import os import os
import subprocess import subprocess
import shlex import shlex
import string
from .solver import Solver from .solver import Solver
import damask import damask
@ -19,7 +20,13 @@ class Marc(Solver):
""" """
self.solver = 'Marc' self.solver = 'Marc'
self.version = damask.Environment().options['MARC_VERSION'] try:
self.version = int(version)
except TypeError:
try:
self.version = int(damask.Environment().options['MARC_VERSION'])
except TypeError:
self.version = -1
#-------------------------- #--------------------------
@ -75,7 +82,6 @@ class Marc(Solver):
#-------------------------- #--------------------------
def exit_number_from_outFile(self,outFile=None): def exit_number_from_outFile(self,outFile=None):
import string
exitnumber = -1 exitnumber = -1
with open(outFile,'r') as fid_out: with open(outFile,'r') as fid_out:
for line in fid_out: for line in fid_out:

View File

@ -1,12 +0,0 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $DIR
VERSION=$(head -n1 damask/VERSION)
read -p "updated version [${VERSION}]: " UP
echo ${UP:-$VERSION} > damask/VERSION
rm -rf dist/
python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*

View File

@ -3,7 +3,7 @@ import os
import re import re
with open(os.path.join(os.path.dirname(__file__),'damask/VERSION')) as f: with open(os.path.join(os.path.dirname(__file__),'damask/VERSION')) as f:
version = re.sub(r'^v','',f.readline().strip()) version = re.sub(r'(-([^-]*)).*$',r'.\2',re.sub(r'^v(\d+\.\d+(\.\d+)?)',r'\1',f.readline().strip()))
setuptools.setup( setuptools.setup(
name="damask", name="damask",