diff --git a/.gitignore b/.gitignore index 05ec978..e02fe6f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __pycache__ *.so *.bak package/ +src/msspec/results.txt diff --git a/CI/CI.bash b/CI/CI.bash index 67aea44..c32f68c 100644 --- a/CI/CI.bash +++ b/CI/CI.bash @@ -51,52 +51,26 @@ activate_msspec_python3_virtualenv() { } -make_pymsspec_package() { - echo "Running setuptools for pymsspec, please wait... " - VERSION=$(get_package_version) - DEST=${TOPLEVEL}/install_resources/packages/${VERSION} - mkdir -p $DEST - cd ${TOPLEVEL}/src/python/pymsspec && python setup.py sdist 2>&1 > /dev/null - cp ${TOPLEVEL}/src/python/pymsspec/dist/pymsspec-${VERSION}.tar.gz ${DEST}/ - rm -rf ${TOPLEVEL}/src/python/pymsspec/{*.egg-info,dist} -} - - make_pybinding() { echo "Creating Python library for Fortran code, please wait... " - activate_msspec_python3_virtualenv - cd ${TOPLEVEL}/src/ && make pybinding + activate_msspec_python3_virtualenv "$1" + cd ${TOPLEVEL}/src/ + make pybinding || exit 1 } make_selfex() { echo "Creating the self-extractible setup program... " - VERSION=$(get_package_version) - DEST=${TOPLEVEL}/install_resources/packages/${VERSION} - LICENSE="${TOPLEVEL}/src/CI/license.txt" - REQUIREMENTS="${TOPLEVEL}/src/CI/requirements" - SETUPFILE="MsSpec-${VERSION}.setup" - MAKESELF=${TOPLEVEL}/src/CI/makeself/makeself.sh - #pip freeze > "${REQUIREMENTS}" - mkdir -p $DEST - cp "${TOPLEVEL}/src/CI/install.sh" "${DEST}" - chmod u+x "${DEST}/install.sh" - cp "${TOPLEVEL}/src/CI/uninstall.sh" "${DEST}" - cp "${TOPLEVEL}/src/CI/msspec" "${DEST}" - cp "${TOPLEVEL}/src/CI/requirements" "${DEST}" - cp "${TOPLEVEL}/src/CI/distro-requirements" "${DEST}" - get_makeself - cd "${DEST}/../" && ${MAKESELF} --license ${LICENSE} --quiet ${VERSION} ${SETUPFILE} "MsSpec - pymsspec" ./install.sh - rm -rf ${SETUPFILE}.bak - rm -rf "${DEST}" - #rm -rf "${REQUIREMENTS}" + cd ${TOPLEVEL} + make selfex || exit 1 + mv pymsspec-${VERSION}.setup package/ } make_pdf() { DEST=${TOPLEVEL}/package mkdir -p ${DEST} # first activate the virtual environment - activate_msspec_python3_virtualenv + activate_msspec_python3_virtualenv "$1" # then build the documentation. cd "${TOPLEVEL}/doc" make --no-print-directory latexpdf || exit 1 @@ -107,9 +81,9 @@ make_pdf() { } make_html () { - make_pdf + make_pdf "$1" # first activate the virtual environment - activate_msspec_python3_virtualenv + activate_msspec_python3_virtualenv "$1" # then build the documentation. cd "${TOPLEVEL}/doc" make --no-print-directory html || exit 1 @@ -117,33 +91,23 @@ make_html () { make_tests() { echo "generate results for unit tests..." - activate_msspec_python3_virtualenv - python -c "from msspec.tests import create_tests_results; create_tests_results()" + activate_msspec_python3_virtualenv "$1" + make_pybinding + python -c "from msspec.tests import create_tests_results; create_tests_results()" || exit 1 } create_package() { - VENV_PATH="$1" - source "$VENV_PATH/bin/activate" - - #update_version - #make_tests - #make_pdf - #make_pymsspec_package - #make_msspecgui_package - #make_fortran_package - #make_selfex - #cleanup - - deactivate + echo "Creating the package..." + #make_tests "$1" + make_selfex "$1" + cleanup } cleanup() { echo "cleaning up..." # remove results.txt file - python -c "from msspec.tests import delete_results_file; delete_results_file()" - VERSION=$(get_package_version) - rm -f ${TOPLEVEL}/guide/MsSpec-${VERSION}.pdf + rm -rf ${TOPLEVEL}/src/msspec/results.txt } show_help () { @@ -158,13 +122,15 @@ show_help () { if [ "$sourced" == 0 ]; then - while getopts "hi:dt" option; do + while getopts "hi:d:t:p:" option; do case $option in i) setup_virtualenv "$OPTARG" ;; - d) make_html + d) make_html "$OPTARG" ;; - t) make_tests + t) make_tests "$OPTARG" + ;; + p) create_package "$OPTARG" ;; h) show_help ;; diff --git a/Jenkinsfile b/Jenkinsfile index 11b7f99..3d3f0fa 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,7 +4,38 @@ pipeline { stage('Initial setup...') { steps { echo 'Create or update the virtual Python environment' + sh '/bin/bash ./CI/CI.bash -i ci_venv' } } + + stage('Testing the package...') { + steps { + sh '/bin/bash ./CI/CI.bash -t ci_venv' + } + } + stage('Creatin a setup file and test installation...') { + steps { + sh '/bin/bash ./CI/CI.bash -p ci_venv' + sh '/bin/bash ./package/MsSpec*.setup --accept -- -p ./ci_venv -y' + } + } + stage('Building HTML documentation...') { + steps { + sh '/bin/bash ./CI/CI.bash -d ci_venv' + } + } + stage('Syncing website...') { + steps { + echo 'Updating the website files' + } + } + stage('Cleaning up...') { + steps { + echo 'Cleaning artifacts...' + sh 'rm -rf ./package' + sh 'cd ./doc && make clean' + } + } + } } diff --git a/Makefile b/Makefile index b5a30b0..5d76615 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,16 @@ MAKESELF:=makeself -LICENSE:=$(shell cat ./license.txt) +#LICENSE:=$(cat ./license.txt) #VERSION:=$(shell cd src && python -c "import msspec; print(msspec.__version__)") VERSION:=$(shell git describe|sed 's/-\([[:digit:]]\+\)-.*/\.post\1/') -SETUPFILE:=pymsspec-$(VERSION).setup +SETUPFILE:=MsSpec-$(VERSION).setup -.PHONY: clean purge version +.PHONY: clean purge version selfex clean: @echo "Cleaning all..." - @find ./src -type f -name '*.pyc' -exec rm {} + - @find ./src -type d -name '__pycache__' -exec rm -r {} + + @find ./src -type f -name '*.pyc' -exec rm -f {} + + @find ./src -type d -name '__pycache__' -exec rm -rf {} + +$(MAKE) -C src/ clean +$(MAKE) -C doc/ clean @@ -23,27 +23,27 @@ purge: clean @rm -rf *.setup +$(MAKE) -C src/ purge -selfex: purge +selfex: @echo "Creating the self-extractible setup program... " # update the version @cp ./src/msspec/version.py ./src/msspec/version.py.bak @echo "__version__ = \"$(VERSION)\"" > ./src/msspec/version.py # create the *.lsm file - @echo "Begin4" > pymsspec.lsm - @echo "Title: Python MsSpec" >> pymsspec.lsm - @echo "Version: $(VERSION)" >> pymsspec.lsm - @echo "Entered-date: `date +%Y-%m-%d`" >> pymsspec.lsm - @echo "Description: A multiple scattering package for spectroscopies using electrons to probe materials" >> pymsspec.lsm - @echo "Keywords: " >> pymsspec.lsm - @echo "Author: sylvain.tricot@univ-rennes1.fr (Sylvain Tricot), didier.sebilleau@univ-rennes1.fr (Didier Sébilleau)" >> pymsspec.lsm - @echo "Maintained-by: sylvain.tricot@univ-rennes1.fr (Sylvain Tricot)" >> pymsspec.lsm - @echo "Primary-site: https://msspec.cnrs.fr" >> pymsspec.lsm - @echo "Alternate-site:" >> pymsspec.lsm - @echo "Original-site:" >> pymsspec.lsm - @echo "Platforms:" >> pymsspec.lsm - @echo "Copying-policy: Gnu Library General Public License (GLPL) 2.0" >> pymsspec.lsm - @echo "End" >> pymsspec.lsm - $(MAKESELF) --license ./license.txt --lsm ./pymsspec.lsm ./src $(SETUPFILE) "Python MsSpec" ./install.sh + @echo "Begin4" > msspec.lsm + @echo "Title: Python MsSpec" >> msspec.lsm + @echo "Version: $(VERSION)" >> msspec.lsm + @echo "Entered-date: `date +%Y-%m-%d`" >> msspec.lsm + @echo "Description: A multiple scattering package for spectroscopies using electrons to probe materials" >> msspec.lsm + @echo "Keywords: " >> msspec.lsm + @echo "Author: sylvain.tricot@univ-rennes1.fr (Sylvain Tricot), didier.sebilleau@univ-rennes1.fr (Didier Sébilleau)" >> msspec.lsm + @echo "Maintained-by: sylvain.tricot@univ-rennes1.fr (Sylvain Tricot)" >> msspec.lsm + @echo "Primary-site: https://msspec.cnrs.fr" >> msspec.lsm + @echo "Alternate-site:" >> msspec.lsm + @echo "Original-site:" >> msspec.lsm + @echo "Platforms:" >> msspec.lsm + @echo "Copying-policy: Gnu Library General Public License (GLPL) 2.0" >> msspec.lsm + @echo "End" >> msspec.lsm + $(MAKESELF) --license "./license.txt" --lsm ./msspec.lsm ./src $(SETUPFILE) "Python MsSpec" ./install.sh @mv ./src/msspec/version.py.bak ./src/msspec/version.py - @rm ./pymsspec.lsm + @rm ./msspec.lsm diff --git a/src/MANIFEST.in b/src/MANIFEST.in index e63bcb2..7d868e4 100644 --- a/src/MANIFEST.in +++ b/src/MANIFEST.in @@ -1,2 +1,3 @@ include msspec/spec/*.so include msspec/phagen/*.so +include msspec/results.txt diff --git a/src/install.sh b/src/install.sh index 715958d..169f653 100755 --- a/src/install.sh +++ b/src/install.sh @@ -1,17 +1,16 @@ #!/bin/bash # vim: set ts=4 sw=4 sts noet mouse=a fdm=indent: -SCRIPT_NAME=$(basename "$0") -PYTHON=python3 -VERSION=$(cat ./msspec/version.py|cut -d\" -f2) DEFAULT_DEST="${HOME}/.local/share" DEFAULT_BIN="${HOME}/.local/bin" BYPASS="n" DEBUG="n" -TIMEOUT=0 + +SCRIPT_NAME=$(basename "$0") +PYTHON=python3 +VERSION=$(cat ./msspec/version.py|cut -d\" -f2) +TIMEOUT=5 DEST_ALREADY_EXISTS="n" - - ECHO="/bin/echo -e" DATE=$(date +%Y%m%d_%H%M%S) LOGFILE="${HOME}/msspec_install_${DATE}.log" @@ -29,7 +28,6 @@ init_install () { get_os if [ "$BYPASS" = "n" ]; then - ${ECHO} "Thanks for choosing MsSpec" ${ECHO} "" ${ECHO} "This program will install the MsSpec distribution on your computer" ${ECHO} -n "Press C^c to cancel now... " @@ -73,6 +71,9 @@ error_exit () { printf "\n" tail -v -n 10 "${LOGFILE}" + # uninstall if needed + pip uninstall -y msspec + # if the DEST_FOLDER existed before, do NOT delete it if [ x"$DEST_ALREADY_EXISTS" = "xn" ]; then rm -rf ${DEST_FOLDER} 2>/dev/null @@ -238,21 +239,66 @@ show_help () { echo " -d Debug mode." echo " -h Show this message." exit 0 -} +} + + +check_dependencies () { + # we need make + log_message "Checking if make is installed..." + command -V make || return 1 + log_message "Ok\n" + + # we need gfortran + gcc_ver_min=7 + log_message "Checking if gfortran >= $gcc_ver_min is installed..." + command -V gfortran || return 1 + gcc_ver=$(gcc -dumpversion) + echo "You have gfortran version $gcc_ver installed" + test $gcc_ver -ge $gcc_ver_min || return 1 + log_message "Ok\n" + + # we need libcairo and dev files + log_message "Checking if libcairo is installed..." + pkg-config --exists cairo || return 1 + log_message "Ok\n" + + # we need Python 3 + py_ver_major_min=3 + py_ver_minor_min=0 + log_message "Checking if Python >= ${py_ver_major_min}.${py_ver_minor_min}..." + message="You need Python version ${py_ver_major_min}.${py_ver_minor_min}" + python --version|cut -d" " -f2 || return 1 + py_ver=$(python --version | cut -d" " -f2) + echo "You have Python version $py_ver installed" + py_ver_major=$(echo $py_ver|cut -d. -f1) + py_ver_minor=$(echo $py_ver|cut -d. -f2) + test $py_ver_major -ge $py_ver_major_min || return 1 + test $py_ver_minor -ge $py_ver_minor_min || return 1 + log_message "Ok\n" + + # we need virtualenv + log_message "Checking if virtualenv is installed..." + command -V virtualenv || return 1 + log_message "Ok\n" + +} local_install () { # Initialize the install process init_install + # check dependencies + wrap "check_dependencies" "Checking dependencies" + # ask for a place to put the binary - read_folder "Please, type in the folder where to place the binary" "${DEFAULT_BIN}" - BIN_FOLDER=${FOLDER} - create_folder "${BIN_FOLDER}" || error_exit - export BIN_FOLDER + #read_folder "Please, type in the folder where to place the binary" "${DEFAULT_BIN}" + #BIN_FOLDER=${FOLDER} + #create_folder "${BIN_FOLDER}" || error_exit + #export BIN_FOLDER # If in a virtualenv, ask if we should install inside if [ x"$VIRTUAL_ENV" != x ]; then - read_yes_no "You are running a Python virtual environment.\ Do you wish to install msspec inside ?" "y" + read_yes_no "You are running a Python virtual environment. Do you wish to install msspec inside ?" "y" case ${ANSWER} in y) # get the python version of this venv... v=$(python -V 2>&1 | cut -d" " -f2 | cut -d. -f1) @@ -318,6 +364,14 @@ local_install () { ## move the uninstal script #wrap "cp ./uninstall.sh ${DEST}" "Moving the uninstall script" # + # Run unit tests ? + read_yes_no "Do you wish to run unit tests (${LOGFILE})" "y" + if [ x"${ANSWER}" = "xy" ]; then + wrap "python -c \"from msspec.tests import run_tests; run_tests()\"" \ + "Runing test suite" + fi + + # installation was a succes so ask if we keep the log file read_yes_no "Do you wish to keep the log file (${LOGFILE})" "n" if [ x"${ANSWER}" = "xn" ]; then diff --git a/src/msspec/spec/fortran/main.f b/src/msspec/spec/fortran/main.f index 9925513..4bdf296 100644 --- a/src/msspec/spec/fortran/main.f +++ b/src/msspec/spec/fortran/main.f @@ -16,6 +16,5 @@ CF2PY INTEGER, INTENT(IN,COPY) :: N_TILT_M_, N_ORD_M_, NPATH_M_, NGR_M_ & N_TILT_M_, N_ORD_M_, NPATH_M_, NGR_M_) CALL DO_MAIN() - PRINT *, "BEFORE END IN SPEC" END SUBROUTINE RUN diff --git a/src/msspec/tests.py b/src/msspec/tests.py index 1d3da78..49826e0 100644 --- a/src/msspec/tests.py +++ b/src/msspec/tests.py @@ -121,7 +121,8 @@ def run_tests(): suite.addTest(PEDCopperTestCase('test_theta_scan')) runner = unittest.TextTestRunner(verbosity=2) rc = runner.run(suite) - exit(rc) + #print("rc = ", rc) + exit(not(rc.wasSuccessful())) def create_tests_results(): with open(RESULTS_FILENAME, 'w') as fd: