From 50219b9f45489bfead8eecba39ceab6d2ae619b0 Mon Sep 17 00:00:00 2001 From: Sylvain Tricot Date: Mon, 30 Nov 2020 16:39:29 +0100 Subject: [PATCH] Work on topmost Makefile (unittests and install targets) Just began to rewrite the topmost Makefile which will provide targets for: * runing the tests * creating the Python venv * building and installing the code * building the manual and the website Makefiles in subfolder were also upgraded to fix some issues in target filenames. --- Makefile | 84 ++++++--------------------- src/Makefile | 2 +- src/msspec/spec/fortran/Makefile | 2 +- src/msspec/spec/fortran/comp_curve.mk | 2 +- src/msspec/spec/fortran/eig_mi.mk | 2 +- src/options.mk | 36 ++++++++---- src/pip.freeze | 2 +- 7 files changed, 48 insertions(+), 82 deletions(-) diff --git a/Makefile b/Makefile index fdfc501..8f9a539 100644 --- a/Makefile +++ b/Makefile @@ -1,78 +1,28 @@ -MAKESELF:=makeself -VERSION:=$(shell git describe|sed 's/-\([[:digit:]]\+\)-.*/\.post\1/') -SETUPFILE:=MsSpec-$(VERSION).setup +include src/options.mk +PYTHON = python -VERBOSE:=0 -ifeq ($(VERBOSE),0) - SUPPRESS_OUPUT:=1>/dev/null 2>/dev/null - MAKEFLAGS += --no-print-directory -else - SUPPRESS_OUPUT:= +# Checking Python version +PYTHON_EXE := $(shell command -v $(PYTHON) 2> /dev/null) + +ifndef PYTHON_EXE + $(error Unable to find the $(PYTHON) executable!) +endif + +PYTHON_VERSION_MAJOR := $(shell $(PYTHON_EXE) --version 2>&1 | cut -d" " -f2 | cut -d. -f1) +PYTHON_VERSION_MINOR := $(shell $(PYTHON_EXE) --version 2>&1 | cut -d" " -f2 | cut -d. -f2) + +ifneq ($(shell test $(PYTHON_VERSION_MAJOR) -ge 3 -a $(PYTHON_VERSION_MINOR) -ge 6; echo $$?),0) + $(error Python version >= 3.6 is needed!) endif -.PHONY: clean version selfex venv doc - - -selfex: results - @echo "Creating the self-extractible setup program... " -# copy the src folder and purge it - @cp -r src src_ - @+$(MAKE) -C ./src_ purge -# update the version - @echo "$(VERSION)" > ./src_/VERSION -# distribute the README.md file - @cp README.md ./src_/ -# create the package folder - @mkdir -p package -# create the *.lsm file - @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 -# create the self-extractible archive - @$(MAKESELF) --license "./license.txt" --lsm ./msspec.lsm ./src_ package/$(SETUPFILE) "Python MsSpec" ./install.sh $(SUPPRESS_OUPUT) -# remove *.lsm file and src_ - @rm ./msspec.lsm - @rm -rf ./src_ - - -version: - @python ./CI/update_version.py - - -clean: - @echo "Cleaning all..." - @find ./src -type f -name '*.pyc' -exec rm -f {} + - @find ./src -type d -name '__pycache__' -exec rm -rf {} + - @rm -rf src/dist - @rm -rf src/*.egg* - @+$(MAKE) -C src/ clean $(SUPPRESS_OUPUT) - @+$(MAKE) -C doc/ clean $(SUPPRESS_OUPUT) - @rm -rf package - -purge: clean - @echo "Removing also shared objects..." - @find ./src -type f -name '*.so' -exec rm -f {} + - -results: - @+$(MAKE) -C src results +.PHONY: venv doc venv: - @virtualenv --python=python3 --system-site-packages ci_venv $(SUPPRESS_OUPUT) - @. "./ci_venv/bin/activate" && pip install --upgrade pip && pip install --upgrade -r requirements.txt $(SUPPRESS_OUPUT) + virtualenv --python=python$(PYTHON_VERSION_MAJOR).$(PYTHON_VERSION_MINOR) --system-site-packages --prompt="(msspec-$(VERSION)) " venv + . ./venv/bin/activate && pip install --upgrade pip && pip install -r src/pip.freeze doc: @echo "Building pdf and html documentation..." diff --git a/src/Makefile b/src/Makefile index 598e623..66b7610 100644 --- a/src/Makefile +++ b/src/Makefile @@ -20,7 +20,7 @@ tests: pybinding @echo "Runing unittests" @python -m msspec.tests 1>/dev/null -clean: +clean:: @echo "Cleaning all..." @find ./ -type f -name '*.pyc' -exec rm -f {} + @find ./ -type d -name '__pycache__' -exec rm -rf {} + diff --git a/src/msspec/spec/fortran/Makefile b/src/msspec/spec/fortran/Makefile index f7def44..ad5e58f 100644 --- a/src/msspec/spec/fortran/Makefile +++ b/src/msspec/spec/fortran/Makefile @@ -17,7 +17,7 @@ eig_pw: comp_curve: @+$(MAKE) -f comp_curve.mk all -clean: +clean:: @+$(MAKE) -f phd_se_noso_nosp_nosym.mk $@ @+$(MAKE) -f phd_mi_noso_nosp_nosym.mk $@ @+$(MAKE) -f eig_mi.mk $@ diff --git a/src/msspec/spec/fortran/comp_curve.mk b/src/msspec/spec/fortran/comp_curve.mk index 616e9ba..35ec9ff 100644 --- a/src/msspec/spec/fortran/comp_curve.mk +++ b/src/msspec/spec/fortran/comp_curve.mk @@ -1,5 +1,5 @@ SRCS = treatment/comp_curves.f MAIN_F = treatment/main.f -SO = comp_curves.so +SO = _comp_curves.so include ../../../options.mk diff --git a/src/msspec/spec/fortran/eig_mi.mk b/src/msspec/spec/fortran/eig_mi.mk index c9be31d..5f0a797 100644 --- a/src/msspec/spec/fortran/eig_mi.mk +++ b/src/msspec/spec/fortran/eig_mi.mk @@ -7,6 +7,6 @@ eig_mi_src := $(wildcard eig/mi/*.f) SRCS = $(memalloc_src) $(cluster_gen_src) $(common_sub_src) $(renormalization_src) $(eig_mi_src) MAIN_F = eig/mi/main.f -SO = _eig_pw.so +SO = _eig_mi.so include ../../../options.mk diff --git a/src/options.mk b/src/options.mk index d3e7187..cf38c15 100644 --- a/src/options.mk +++ b/src/options.mk @@ -35,7 +35,8 @@ F2PYFLAGS_DBG = --debug-capi --debug # /!\ DO NOT EDIT BELOW THAT LINE (unlesss you know what you're doing...) # # CORE CONFIGURATION # ################################################################################ -VERSION:=$(shell python -c "import msspec; print(msspec.__version__)") +#VERSION:=$(shell python -c "import msspec; print(msspec.__version__)") +VERSION:=$(shell git describe|sed 's/-\([[:digit:]]\+\)-.*/\.post\1/') ifeq ($(VERBOSE),0) OUPUT_REDIRECTION := 1>/dev/null 2>/dev/null @@ -64,12 +65,13 @@ FFLAGS = $($(PREFIX)_FFLAGS$(SUFFIX)) OBJS = $(addprefix $(BUILDDIR)/, $(patsubst %.f,%.o, $(filter-out $(MAIN_F), $(SRCS)))) -.PHONY: clean obj all compilation_info +.PHONY: clean obj all info -compilation_info: - @echo "Compiler used: $(FC)" - @echo "fortran flags: $(FFLAGS)" - @echo "f2py flags: $(FFLAGS)" +info: + @echo "Compilation information for msspec $(VERSION)" + @echo "FC : $(FC)" + @echo "FFLAGS:" + @for flag in $(FFLAGS); do echo "\t$$flag"; done all: $(SO) @@ -78,10 +80,24 @@ all: $(SO) obj: $(OBJS) -clean: - @echo "Cleaning..." - rm -rf $(BUILDDIR) - rm -rf $(SO) +clean:: + @for objfile in $(OBJS); do \ + if test -f $$objfile; then \ + echo "Removing $$objfile..."; \ + rm $$objfile; \ + fi;\ + done + @if test -d $(abspath $(BUILDDIR)); then \ + if test `find $(abspath $(BUILDDIR)) -type f|wc -l` -eq 0; then \ + echo "Removing empty folder $(abspath $(BUILDDIR))..."; \ + rm -r $(abspath $(BUILDDIR)); \ + fi; \ + fi + @if test x$(SO) != x; then \ + if test -f $(SO); then \ + echo "Removing $(SO)..."; rm $(SO); \ + fi; \ + fi $(BUILDDIR)/%.o: %.f diff --git a/src/pip.freeze b/src/pip.freeze index 26b724c..49e5fc2 100644 --- a/src/pip.freeze +++ b/src/pip.freeze @@ -54,4 +54,4 @@ traitlets==4.3.3 urllib3==1.25.8 wcwidth==0.1.9 wheel==0.34.2 -wxPython@https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04/wxPython-4.0.7.post2-cp36-cp36m-linux_x86_64.whl +#wxPython@https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04/wxPython-4.0.7.post2-cp36-cp36m-linux_x86_64.whl