From 166df2ba8d96a0705459bd96bbda157341b4d862 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 4 Apr 2014 00:41:43 +0200 Subject: [PATCH] Auto-update README.rst --- scripts/.gitignore | 2 + scripts/create_rst_templates.sh | 13 ---- scripts/update_README.py | 124 ++++++++++++++++++++++++++++++++ setup_environment.sh | 8 ++- src/AOs/README.rst | 17 ++--- src/ASSUMPTIONS.rst | 0 src/Bitmask/README.rst | 19 ++--- src/Electrons/README.rst | 17 +++-- src/Ezfio_files/README.rst | 13 ---- src/MOs/README.rst | 18 +++-- src/Makefile.common | 111 ++++++++++++++++++++++------ src/Nuclei/README.rst | 16 ++--- src/Output/README.rst | 17 ++--- src/README.rst | 15 ++++ src/Utils/README.rst | 5 ++ 15 files changed, 287 insertions(+), 108 deletions(-) create mode 100644 scripts/.gitignore create mode 100755 scripts/update_README.py create mode 100644 src/ASSUMPTIONS.rst diff --git a/scripts/.gitignore b/scripts/.gitignore new file mode 100644 index 00000000..52e4e611 --- /dev/null +++ b/scripts/.gitignore @@ -0,0 +1,2 @@ +*.pyc +*.pyo diff --git a/scripts/create_rst_templates.sh b/scripts/create_rst_templates.sh index 842bb507..d78f49f3 100755 --- a/scripts/create_rst_templates.sh +++ b/scripts/create_rst_templates.sh @@ -43,19 +43,6 @@ $UNDERLINE $MODULE Module $UNDERLINE - - -Assumptions ------------ - -.. include:: ./ASSUMPTIONS.rst - - -Needed Modules --------------- - -.. include:: ./NEEDED_MODULES - EOF fi diff --git a/scripts/update_README.py b/scripts/update_README.py new file mode 100755 index 00000000..cb4f65aa --- /dev/null +++ b/scripts/update_README.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python + +"""Updates the README.rst file as the include directive is disabled on GitHub.""" +__date__ = "Thu Apr 3 23:06:18 CEST 2014" +__author__ = "Anthony Scemama " + + +README="README.rst" +Assum_key="Assumptions\n===========\n" +Needed_key="Needed Modules\n==============\n" +Sentinel="@@$%&@@" + + +def fetch_splitted_data(): + """Read the README.rst file and split it in 3 strings: + * The description + * The assumptions + * The needed modules + The result is given as a list of strings + """ + + file = open(README,'r') + data = file.read() + file.close() + + # Place sentinels + data = data.replace(Assum_key,Sentinel+Assum_key) + data = data.replace(Needed_key,Sentinel+Needed_key) + + # Now Split data using the sentinels + result = data.split(Sentinel) + + return result + + +def update_assumptions(data): + """Read the ASSUMPTIONS.rst file, and replace the data with it.""" + + try: + file = open('ASSUMPTIONS.rst','r') + except IOError: + file = open('ASSUMPTIONS.rst','w') + assumptions = "" + else: + assumptions = file.read() + file.close() + + header = """ +.. Do not edit this section. It was auto-generated from the +.. ASSUMPTIONS.rst file. + +""" + if assumptions.strip() != "": + assumptions = Assum_key + header + assumptions + '\n\n' + + has_assumptions = False + for i in range(len(data)): + if data[i].startswith(Assum_key): + has_assumptions = True + data[i] = assumptions + + if not has_assumptions: + data.insert(1,assumptions) + + return data + + +def update_needed(data): + """Read the NEEDED_MODULES file, and replace the data with it.""" + + file = open('NEEDED_MODULES','r') + modules = file.read() + file.close() + + header = """ +.. Do not edit this section. It was auto-generated from the +.. NEEDED_MODULES file. + +""" + if modules.strip() != "": + modules = "\n".join(map(lambda x: '* %s'%(x), modules.split())) + modules = Needed_key + header + modules + '\n\n' + + has_modules = False + for i in range(len(data)): + if data[i].startswith(Needed_key): + has_modules = True + data[i] = modules + + if not has_modules: + data.append(modules) + + return data + +import subprocess + +def git_add(): + """Executes: + git add README.rst + if git is present on the machine.""" + command = "git add "+README + + try: + subprocess.call(command.split()) + except OSError: + pass + + +def main(): + data = fetch_splitted_data() + data = update_assumptions(data) + data = update_needed(data) + output = ''.join(data) + + file = open(README,'w') + file.write(output) + file.close() + + git_add() + + +if __name__ == '__main__': + main() + diff --git a/setup_environment.sh b/setup_environment.sh index f6a77f66..cf05d133 100755 --- a/setup_environment.sh +++ b/setup_environment.sh @@ -9,11 +9,13 @@ then make irpf90 IRPF90=${QPACKAGE_ROOT}/irpf90/bin/irpf90 fi -make EZFIO cat << EOF > quantum_package.rc export IRPF90=${IRPF90} export QPACKAGE_ROOT=${QPACKAGE_ROOT} -export PATH+=:${QPACKAGE_ROOT}/scripts -export PATH+=:${QPACKAGE_ROOT}/bin +export PATH+=:\${QPACKAGE_ROOT}/scripts +export PATH+=:\${QPACKAGE_ROOT}/bin EOF + +source quantum_package.rc +make EZFIO diff --git a/src/AOs/README.rst b/src/AOs/README.rst index c65bab01..06be30d7 100644 --- a/src/AOs/README.rst +++ b/src/AOs/README.rst @@ -2,16 +2,13 @@ AOs Module ========== - - -Assumptions ------------ - -.. include:: ./ASSUMPTIONS.rst - - Needed Modules --------------- +============== -.. include:: ./NEEDED_MODULES +.. Do not edit this section. It was auto-generated from the +.. NEEDED_MODULES file. + +* Ezfio_files +* Nuclei +* Utils diff --git a/src/ASSUMPTIONS.rst b/src/ASSUMPTIONS.rst new file mode 100644 index 00000000..e69de29b diff --git a/src/Bitmask/README.rst b/src/Bitmask/README.rst index 92fa5c4f..a382d542 100644 --- a/src/Bitmask/README.rst +++ b/src/Bitmask/README.rst @@ -3,15 +3,16 @@ Bitmask Module ============== - -Assumptions ------------ - -.. include:: ./ASSUMPTIONS.rst - - Needed Modules --------------- +============== -.. include:: ./NEEDED_MODULES +.. Do not edit this section. It was auto-generated from the +.. NEEDED_MODULES file. + +* AOs +* Electrons +* Ezfio_files +* MOs +* Nuclei +* Utils diff --git a/src/Electrons/README.rst b/src/Electrons/README.rst index 56ca7988..509e5874 100644 --- a/src/Electrons/README.rst +++ b/src/Electrons/README.rst @@ -7,13 +7,22 @@ are provided by this module. Assumptions ------------ +=========== -.. include:: ./ASSUMPTIONS.rst +.. Do not edit this section. It was auto-generated from the +.. ASSUMPTIONS.rst file. + +* ``elec_num`` >= 0 +* ``elec_alpha_num`` >= 0 +* ``elec_beta_num`` >= 0 +* ``elec_alpha_num`` >= ``elec_beta_num`` Needed Modules --------------- +============== -.. include:: ./NEEDED_MODULES +.. Do not edit this section. It was auto-generated from the +.. NEEDED_MODULES file. + +* Ezfio_files diff --git a/src/Ezfio_files/README.rst b/src/Ezfio_files/README.rst index c88ee24a..fa289b43 100644 --- a/src/Ezfio_files/README.rst +++ b/src/Ezfio_files/README.rst @@ -2,16 +2,3 @@ Ezfio_files Module ================== - - -Assumptions ------------ - -.. include:: ./ASSUMPTIONS.rst - - -Needed Modules --------------- - -.. include:: ./NEEDED_MODULES - diff --git a/src/MOs/README.rst b/src/MOs/README.rst index e33810f6..ce89fced 100644 --- a/src/MOs/README.rst +++ b/src/MOs/README.rst @@ -2,16 +2,14 @@ MOs Module ========== - - -Assumptions ------------ - -.. include:: ./ASSUMPTIONS.rst - - Needed Modules --------------- +============== -.. include:: ./NEEDED_MODULES +.. Do not edit this section. It was auto-generated from the +.. NEEDED_MODULES file. + +* AOs +* Ezfio_files +* Nuclei +* Utils diff --git a/src/Makefile.common b/src/Makefile.common index 00177fb9..ba7cb7cc 100644 --- a/src/Makefile.common +++ b/src/Makefile.common @@ -1,45 +1,108 @@ -include $(QPACKAGE_ROOT)/src/Makefile.config +# Check if QPACKAGE_ROOT is defined + ifndef QPACKAGE_ROOT -$(error QPACKAGE_ROOT undefined. Run the setup_environment.sh script) +$(info -------------------- Error --------------------) +$(info QPACKAGE_ROOT undefined. Run the setup_environment.sh script) +$(info -----------------------------------------------) +$(error ) endif -NEEDED_MODULES=$(shell cat NEEDED_MODULES) -include Makefile.depend - -NEEDED_MODULES_OK=$(shell X=`$(QPACKAGE_ROOT)/scripts/check_dependencies.sh $(NEEDED_MODULES)` && echo OK || echo $$X) -ifneq ($(NEEDED_MODULES_OK),OK) - $(info ---------------------) - $(info Your NEEDED_MODULES file is inconsistent. It should be:) - $(info $(NEEDED_MODULES_OK)) - $(info ---------------------) - $(error ) -endif - -IRP_VERSION_OK=$(shell $(IRPF90) -v | python -c "import sys ; print float(sys.stdin.readline().rsplit('.',1)[0]) >= 1.3") -ifeq ($(IRP_VERSION_OK),False) -$(error 'IRPF90 version >= 1.3 is required') -endif - -README_RST_OK=$(shell ls README.rst || echo Failed) -ASSUMPTIONS_RST_OK=$(shell ls ASSUMPTIONS.rst || echo Failed) +# Check if the user's config exists MAKEFILE_OK=$(shell ls $(QPACKAGE_ROOT)/src/Makefile.config 2> /dev/null && echo True || echo False) ifeq ($(MAKEFILE_OK),False) -$(error 'Makefile.config is not present. Please modify Makefile.config.example to create Makefile.config') +$(info -------------------- Error --------------------) +$(info Makefile.config is not present.) +$(info You can create Makefile.config) +$(info by modifying Makefile.config.example) +$(info -----------------------------------------------) +$(error ) endif +# Include the user's config + +include $(QPACKAGE_ROOT)/src/Makefile.config + + +# Check the version of IRPF90 + +IRP_VERSION_OK=$(shell $(IRPF90) -v | python -c "import sys ; print float(sys.stdin.readline().rsplit('.',1)[0]) >= 1.3") +ifeq ($(IRP_VERSION_OK),False) +$(info -------------------- Error --------------------) +$(info IRPF90 version >= 1.3 is required) +$(info -----------------------------------------------) +$(error ) +endif + + +# Check if the NEEDED_MODULES file is consistent + +NEEDED_MODULES_OK=$(shell X=`$(QPACKAGE_ROOT)/scripts/check_dependencies.sh $(NEEDED_MODULES)` && echo OK || echo $$X) +ifneq ($(NEEDED_MODULES_OK),OK) +$(info -------------------- Error --------------------) +$(info Your NEEDED_MODULES file is inconsistent. It should be) +$(info $(NEEDED_MODULES_OK)) +$(info -----------------------------------------------) +$(error ) +endif + + +# Create the NEEDED_MODULES variable, needed for IRPF90 + +NEEDED_MODULES=$(shell cat NEEDED_MODULES) + + +# Check and update dependencies + +include Makefile.depend + + +# Check if README.rst exists + +README_RST_OK=$(shell ls README.rst 2>/dev/null || echo False) +ifeq ($(README_RST_OK), False) +$(shell $(QPACKAGE_ROOT)/scripts/create_rst_templates.sh) +$(info -------------------- Error --------------------) +$(info README.rst was not present, so I created a) +$(info default one for you.) +$(info You should document it before you compile, as) +$(info well as the ASSUMPTIONS.rst file.) +$(info -----------------------------------------------) +$(error ) +endif + + +# Check if ASSUMPTIONS.rst exists + +ASSUMPTIONS_RST_OK=$(shell ls ASSUMPTIONS.rst || echo False) +ifeq ($(ASSUMPTIONS_RST_OK), False) +$(info -------------------- Error --------------------) +$(info This is a Bug. At that point, the ASSUMPTIONS.rst) +$(info file should exist.) +$(info -----------------------------------------------) +endif + + +# Update the README.rst file for GitHub, and git add it + +$(shell update_README.py) + + +# Define the Makefile common variables and rules + EZFIO_DIR=$(QPACKAGE_ROOT)/EZFIO EZFIO=$(EZFIO_DIR)/lib/libezfio_irp.a +INCLUDE_DIRS=$(NEEDED_MODULES) include $(EZFIO): $(wildcard $(QPACKAGE_ROOT)/src/*.ezfio_config) $(wildcard $(QPACKAGE_ROOT)/src/*/*.ezfio_config) @echo Building EZFIO library @cp $(wildcard $(QPACKAGE_ROOT)/src/*.ezfio_config) $(wildcard $(QPACKAGE_ROOT)/src/*/*.ezfio_config) $(EZFIO_DIR)/config @cd $(EZFIO_DIR) ; export FC="$(FC)" ; export FCFLAGS="$(FCFLAGS)" ; export IRPF90="$(IRPF90)" ; $(MAKE) ; $(MAKE) Python -INCLUDE_DIRS=$(NEEDED_MODULES) include +# Create symbolic links of other modules ifneq ($(PWD),$(QPACKAGE_ROOT)/src) $(shell $(QPACKAGE_ROOT)/scripts/prepare_module.sh $(INCLUDE_DIRS)) @@ -60,5 +123,7 @@ Makefile.depend: Makefile include irpf90.make +# Dummy rule to enable to force recompilation + FORCE: diff --git a/src/Nuclei/README.rst b/src/Nuclei/README.rst index 7753e6ac..5e6c66de 100644 --- a/src/Nuclei/README.rst +++ b/src/Nuclei/README.rst @@ -2,16 +2,12 @@ Nuclei Module ============= - - -Assumptions ------------ - -.. include:: ./ASSUMPTIONS.rst - - Needed Modules --------------- +============== -.. include:: ./NEEDED_MODULES +.. Do not edit this section. It was auto-generated from the +.. NEEDED_MODULES file. + +* Ezfio_files +* Utils diff --git a/src/Output/README.rst b/src/Output/README.rst index c246a4c6..736449bf 100644 --- a/src/Output/README.rst +++ b/src/Output/README.rst @@ -2,16 +2,7 @@ Output Module ============= - - -Assumptions ------------ - -.. include:: ./ASSUMPTIONS.rst - - -Needed Modules --------------- - -.. include:: ./NEEDED_MODULES - + + + + diff --git a/src/README.rst b/src/README.rst index 680f4235..a6d93fe1 100644 --- a/src/README.rst +++ b/src/README.rst @@ -103,3 +103,18 @@ should be always checked. For example, when creating a directory the existence of the directory has to be checked. +Needed Modules +============== + +.. Do not edit this section. It was auto-generated from the +.. NEEDED_MODULES file. + +* AOs +* Bitmask +* Electrons +* Ezfio_files +* MOs +* Nuclei +* Output +* Utils + diff --git a/src/Utils/README.rst b/src/Utils/README.rst index 71e39fda..825a6599 100644 --- a/src/Utils/README.rst +++ b/src/Utils/README.rst @@ -15,3 +15,8 @@ Needed Modules .. include:: ./NEEDED_MODULES + + + + +