mirror of
https://github.com/LCPQ/quantum_package
synced 2025-01-03 10:05:57 +01:00
commit
31e7f20e85
@ -10,9 +10,8 @@ before_script:
|
||||
- sudo apt-get install graphviz
|
||||
|
||||
script:
|
||||
- ./setup_environment.py
|
||||
- ./configure.py --production ./config/gfortran.cfg
|
||||
- source ./quantum_package.rc
|
||||
- qp_create_ninja.py --production ./config/gfortran.cfg
|
||||
- ninja
|
||||
- cd ocaml ; make ; cd -
|
||||
- cd testing_no_regression ; ./unit_test.py
|
||||
|
@ -12,7 +12,8 @@ The script to create the dependency file (aka `build.ninja`) is
|
||||
* If you only want the binaries (for production workflow) use the flag
|
||||
`--production` in when calling this script. It's quicker
|
||||
* Else if you are a developer and you want to be able to compile specific
|
||||
modules use: `--development`
|
||||
modules use: `--development`. It will create for you the `build.ninja` in each
|
||||
module
|
||||
|
||||
## Compilation Flags
|
||||
|
||||
@ -23,12 +24,7 @@ used. You can edit these files to modify the compiling options.
|
||||
|
||||
## Example to create the Ninja file
|
||||
|
||||
`qp_create_ninja.py --production $QP_ROOT/config/ifort.cfg`
|
||||
|
||||
# WARNING
|
||||
|
||||
For now you need to execute this command if you add a `irp.f` or `EZFIO.cfg`
|
||||
file or modify the `NEED_CHILDREN_MODULE`!
|
||||
`qp_create_ninja.py create --production $QP_ROOT/config/ifort.cfg`
|
||||
|
||||
## Compiling
|
||||
|
||||
@ -37,5 +33,6 @@ elsewhere). The compilation will take approximately 3 min.
|
||||
|
||||
If you have set the `--developement` flag in a specific module you can go in
|
||||
the corresponding module directory and run `ninja` to build only this module.
|
||||
You can type `ninja all` in a module for compiling all the submodule
|
||||
|
||||
Finally, go in `$QP_ROOT/ocaml` and type `make`
|
||||
|
477
configure.py
Executable file
477
configure.py
Executable file
@ -0,0 +1,477 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""configure
|
||||
|
||||
Usage: configure <config_file> (--production | --development)
|
||||
|
||||
Options:
|
||||
config_file A config file will all the information for the compilation
|
||||
(Fortran Compiler, FLag, ...)
|
||||
--production You cannot compile only one module with this flag.
|
||||
but the compilation will be lighting fast
|
||||
--development It will create a build.ninja for each directory
|
||||
who containt a binary, than you can compile then
|
||||
individualy if you want
|
||||
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
|
||||
from os.path import join
|
||||
|
||||
if not any(i in ["--production", "--development"] for i in sys.argv):
|
||||
print __doc__
|
||||
sys.exit()
|
||||
if len(sys.argv) != 3:
|
||||
print __doc__
|
||||
sys.exit()
|
||||
|
||||
# __ _
|
||||
# /__ | _ |_ _. | o ._ _|_ _
|
||||
# \_| |_ (_) |_) (_| | | | | | (_)
|
||||
#
|
||||
|
||||
QP_ROOT = os.getcwd()
|
||||
QP_ROOT_BIN = join(QP_ROOT, "bin")
|
||||
QP_ROOT_INSTALL = join(QP_ROOT, "install")
|
||||
|
||||
d_dependency = {
|
||||
"ocaml": ["m4", "curl", "zlib", "patch", "gcc"],
|
||||
"m4": ["make"],
|
||||
"curl": ["make"],
|
||||
"zlib": ["gcc", "make"],
|
||||
"patch": ["make"],
|
||||
"ezfio": ["irpf90"],
|
||||
"irpf90": ["python"],
|
||||
"docopt": ["python"],
|
||||
"resultsFile": ["python"],
|
||||
"emsl": ["python"],
|
||||
"gcc": [],
|
||||
"python": [],
|
||||
"ninja": ["gcc", "python"],
|
||||
"make": []
|
||||
}
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
Info = namedtuple("Info", ["url", "description", "default_path"])
|
||||
|
||||
path_github = {"head": "http://github.com/", "tail": "archive/master.tar.gz"}
|
||||
|
||||
ocaml = Info(
|
||||
url='http://raw.github.com/ocaml/opam/master/shell/opam_installer.sh',
|
||||
description=' ocaml (it will take some time roughly 20min)',
|
||||
default_path=join(QP_ROOT_BIN, "opam"))
|
||||
|
||||
m4 = Info(
|
||||
url="http://ftp.gnu.org/gnu/m4/m4-latest.tar.gz",
|
||||
description=" m4",
|
||||
default_path=join(QP_ROOT_BIN, "m4"))
|
||||
|
||||
curl = Info(
|
||||
url="http://qmcchem.ups-tlse.fr/files/scemama/curl-7.30.0.ermine.tar.bz2",
|
||||
description=" curl",
|
||||
default_path=join(QP_ROOT_BIN, "curl"))
|
||||
|
||||
zlib = Info(
|
||||
url='http://zlib.net/zlib-1.2.8.tar.gz',
|
||||
description=' zlib',
|
||||
default_path=join(QP_ROOT_INSTALL, "zlib"))
|
||||
|
||||
path = Info(
|
||||
url='ftp://ftp.gnu.org/gnu/patch/patch-2.7.5.tar.gz',
|
||||
description=' path',
|
||||
default_path=join(QP_ROOT, "lib", "libz.a"))
|
||||
|
||||
irpf90 = Info(
|
||||
url='{head}/LCPQ/irpf90/{tail}'.format(**path_github),
|
||||
description=' irpf90',
|
||||
default_path=join(QP_ROOT_BIN, "irpf90"))
|
||||
|
||||
docopt = Info(
|
||||
url='{head}/docopt/docopt/{tail}'.format(**path_github),
|
||||
description=' docop',
|
||||
default_path=join(QP_ROOT_INSTALL, "docopt"))
|
||||
|
||||
resultsFile = Info(
|
||||
url='{head}/LCPQ/resultsFile/{tail}'.format(**path_github),
|
||||
description=' resultsFile',
|
||||
default_path=join(QP_ROOT_INSTALL, "resultsFile"))
|
||||
|
||||
ninja = Info(
|
||||
url='{head}/martine/ninja/{tail}'.format(**path_github),
|
||||
description=' nina',
|
||||
default_path=join(QP_ROOT_BIN, "ninja"))
|
||||
|
||||
emsl = Info(
|
||||
url='{head}/LCPQ/EMSL_Basis_Set_Exchange_Local/{tail}'.format(**
|
||||
path_github),
|
||||
description=' emsl',
|
||||
default_path=join(QP_ROOT_INSTALL, "emsl"))
|
||||
|
||||
ezfio = Info(
|
||||
url='{head}/LCPQ/EZFIO/{tail}'.format(**path_github),
|
||||
description=' EZFIO',
|
||||
default_path=join(QP_ROOT_INSTALL, "EZFIO"))
|
||||
|
||||
d_info = dict()
|
||||
|
||||
for m in ["ocaml", "m4", "curl", "zlib", "path", "irpf90", "docopt",
|
||||
"resultsFile", "ninja", "emsl", "ezfio"]:
|
||||
exec ("d_info['{0}']={0}".format(m))
|
||||
|
||||
|
||||
def find_path(bin_, l_installed):
|
||||
"""Use the global variable
|
||||
* l_installed
|
||||
* d_info
|
||||
"""
|
||||
|
||||
try:
|
||||
locate = l_installed[bin_]
|
||||
except KeyError:
|
||||
locate = d_info[bin_].default_path
|
||||
return locate
|
||||
|
||||
|
||||
# _
|
||||
# |_ ._ _ _|_ o _ ._
|
||||
# | |_| | | (_ |_ | (_) | |
|
||||
#
|
||||
def check_output(*popenargs, **kwargs):
|
||||
"""Run command with arguments and return its output as a byte string.
|
||||
|
||||
Backported from Python 2.7 as it's implemented as pure python on stdlib.
|
||||
|
||||
>>> check_output(['/usr/bin/python', '--version'])
|
||||
Python 2.6.2
|
||||
"""
|
||||
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
|
||||
output, unused_err = process.communicate()
|
||||
retcode = process.poll()
|
||||
if retcode:
|
||||
cmd = kwargs.get("args")
|
||||
if cmd is None:
|
||||
cmd = popenargs[0]
|
||||
error = subprocess.CalledProcessError(retcode, cmd)
|
||||
error.output = output
|
||||
raise error
|
||||
return output
|
||||
|
||||
|
||||
def checking(d_dependency):
|
||||
"""
|
||||
For each key in d_dependency check if it
|
||||
it avalabie or not
|
||||
"""
|
||||
|
||||
def check_python():
|
||||
req_version = (2, 6)
|
||||
cur_version = sys.version_info
|
||||
|
||||
# Check python
|
||||
if cur_version >= req_version:
|
||||
return 1
|
||||
else:
|
||||
print "To old version (need >2.5). Abort"
|
||||
sys.exit(1)
|
||||
|
||||
def check_availabiliy(binary):
|
||||
"""
|
||||
If avalabie return the path who can can't find the
|
||||
binary else return 0
|
||||
"""
|
||||
|
||||
if binary == "python":
|
||||
check_python()
|
||||
|
||||
try:
|
||||
return check_output(["which", binary])
|
||||
except subprocess.CalledProcessError:
|
||||
default_path = d_info[binary].default_path
|
||||
if os.path.exists(default_path):
|
||||
return default_path
|
||||
else:
|
||||
return 0
|
||||
|
||||
def get_list_descendant(d_dependency, l_installed, l_needed):
|
||||
"""
|
||||
Descendant – a node reachable by repeated proceeding from parent to child.
|
||||
"""
|
||||
d_need_genealogy = dict()
|
||||
|
||||
for need in l_needed:
|
||||
d_need_genealogy[need] = None
|
||||
for childen in d_dependency[need]:
|
||||
if childen not in l_installed:
|
||||
d_need_genealogy[childen] = None
|
||||
return d_need_genealogy.keys()
|
||||
|
||||
return d_need_genealogy.keys()
|
||||
print """
|
||||
_
|
||||
|_) _ o _
|
||||
| \ (/_ \/ | (/_ \/\/
|
||||
|
||||
"""
|
||||
|
||||
print "Checking what you need to install and what is it avalaible"
|
||||
print ""
|
||||
l_installed = dict()
|
||||
l_needed = []
|
||||
|
||||
# Check all the other
|
||||
length = max(map(len, d_dependency))
|
||||
|
||||
for i in d_dependency.keys():
|
||||
print "Checking {0:>{1}}...".format(i, length),
|
||||
|
||||
r = check_availabiliy(i)
|
||||
if r:
|
||||
print "[ OK ] ( {0} )".format(r.strip())
|
||||
l_installed[i] = r.strip()
|
||||
else:
|
||||
print "[ FAIL ]"
|
||||
l_needed.append(i)
|
||||
print ""
|
||||
|
||||
# Expend the need_stuff for all the genealogy
|
||||
l_install_descendant = get_list_descendant(d_dependency, l_installed,
|
||||
l_needed)
|
||||
|
||||
return l_installed, l_install_descendant
|
||||
|
||||
|
||||
def installation(l_install_descendant):
|
||||
"""
|
||||
Installing all the list
|
||||
0 install ninja
|
||||
1 create ninja
|
||||
2 run ninja
|
||||
"""
|
||||
|
||||
def create_rule_ninja():
|
||||
|
||||
l_rules = [
|
||||
"rule download", " command = wget ${url} -O ${out} -o /dev/null",
|
||||
" description = Downloading ${descr}", ""
|
||||
]
|
||||
|
||||
l_rules += [
|
||||
"rule install",
|
||||
" command = ./scripts/install_${target}.sh > _build/${target}.log 2>&1",
|
||||
" description = Installing ${descr}", ""
|
||||
]
|
||||
|
||||
l_rules += [
|
||||
"rule install_verbose",
|
||||
" command = ./scripts/install_${target}.sh | tee _build/${target}.log 2>&1",
|
||||
" description = Installing ${descr}", " pool = console", ""
|
||||
]
|
||||
|
||||
return l_rules
|
||||
|
||||
def splitext(path):
|
||||
for ext in ['.tar.gz', '.tar.bz2']:
|
||||
if path.endswith(ext):
|
||||
return path[:-len(ext)], path[-len(ext):]
|
||||
return os.path.splitext(path)
|
||||
|
||||
print """
|
||||
___
|
||||
| ._ _ _|_ _. | | _. _|_ o _ ._
|
||||
_|_ | | _> |_ (_| | | (_| |_ | (_) | |
|
||||
|
||||
"""
|
||||
|
||||
d_print = {
|
||||
"install_ninja": "Install ninja...",
|
||||
"build": "Creating build.ninja...",
|
||||
"install": "Installing the dependancy through ninja..."
|
||||
}
|
||||
|
||||
length = max(map(len, d_print.values()))
|
||||
|
||||
def str_info(key):
|
||||
return "{0:<{1}}".format(d_print[key], length)
|
||||
|
||||
if "ninja" in l_install_descendant:
|
||||
|
||||
print str_info("install_ninja"),
|
||||
|
||||
url = d_info["ninja"].url
|
||||
extension = splitext(url)[1]
|
||||
path_archive = "Downloads/{0}{1}".format("ninja", extension)
|
||||
|
||||
l_cmd = ["cd install &&",
|
||||
"wget {0} -O {1} -o /dev/null &&".format(url, path_archive),
|
||||
"./scripts/install_ninja.sh 2> /dev/null &&", "cd -"]
|
||||
|
||||
try:
|
||||
check_output(" ".join(l_cmd), shell=True)
|
||||
except:
|
||||
raise
|
||||
else:
|
||||
print "[ OK ]"
|
||||
|
||||
l_install_descendant.remove("ninja")
|
||||
|
||||
print str_info("build"),
|
||||
l_string = create_rule_ninja()
|
||||
|
||||
l_build = []
|
||||
|
||||
for need in l_install_descendant:
|
||||
|
||||
url = d_info[need].url
|
||||
extension = splitext(url)[1]
|
||||
|
||||
archive_path = "Downloads/{0}{1}".format(need, extension)
|
||||
|
||||
descr = d_info[need].description
|
||||
default_path = d_info[need].default_path
|
||||
|
||||
# Build to dowload
|
||||
l_build += ["build {0}: download".format(archive_path),
|
||||
" url = {0}".format(url), " descr = {0}".format(descr),
|
||||
""]
|
||||
|
||||
# Build to install
|
||||
l_dependancy = [d_info[i].default_path for i in d_dependency[need]
|
||||
if i in l_install_descendant]
|
||||
str_dependancy = " ".join(l_dependancy)
|
||||
|
||||
rule = "install" if need != "ocaml" else "install_verbose"
|
||||
|
||||
l_build += ["build {0}: {1} {2} {3}".format(default_path, rule,
|
||||
archive_path,
|
||||
str_dependancy),
|
||||
" target = {0}".format(need),
|
||||
" descr = {0}".format(descr), ""]
|
||||
|
||||
l_string += l_build
|
||||
|
||||
path = join(QP_ROOT_INSTALL, "build.ninja")
|
||||
with open(path, "w+") as f:
|
||||
f.write("\n".join(l_string))
|
||||
|
||||
print " [ OK ] ({0})".format(path)
|
||||
|
||||
print str_info("install"),
|
||||
print " [ Running ]"
|
||||
try:
|
||||
path_ninja = find_path("ninja", l_installed)
|
||||
subprocess.check_call("cd install ;{0}".format(path_ninja), shell=True)
|
||||
except:
|
||||
raise
|
||||
else:
|
||||
print r"""
|
||||
_________
|
||||
< Success >
|
||||
---------
|
||||
\ ^__^
|
||||
\ (oo)\_______
|
||||
(__)\ )\/\
|
||||
||----w |
|
||||
|| ||
|
||||
"""
|
||||
|
||||
|
||||
def create_ninja_and_rc(l_installed):
|
||||
print """
|
||||
_
|
||||
|_ o ._ _. | o _ _
|
||||
| | | | (_| | | /_ (/_
|
||||
|
||||
"""
|
||||
|
||||
d_print = {
|
||||
"qp_root": "Creating quantum_package.rc...",
|
||||
"build": "Creating build.ninja..."
|
||||
}
|
||||
|
||||
length = max(map(len, d_print.values()))
|
||||
|
||||
def str_info(key):
|
||||
return "{0:<{1}}".format(d_print[key], length)
|
||||
|
||||
print str_info("qp_root"),
|
||||
python_path = [join(QP_ROOT, "scripts"), join(QP_ROOT, "install")]
|
||||
|
||||
l_python = [join(QP_ROOT, "scripts")]
|
||||
for dir_ in python_path:
|
||||
for folder in os.listdir(dir_):
|
||||
path = join(dir_, folder)
|
||||
if os.path.isdir(path):
|
||||
l_python.append(path)
|
||||
|
||||
l_rc = [
|
||||
'export QP_ROOT={0}'.format(QP_ROOT),
|
||||
'export QP_EZFIO={0}'.format(find_path('ezfio', l_installed)),
|
||||
'export IRPF90={0}'.format(find_path("irpf90", l_installed)),
|
||||
'export NINJA={0}'.format(find_path("ninja", l_installed)),
|
||||
'export QP_PYTHON={0}'.format(":".join(l_python)), "",
|
||||
'export PYTHONPATH="${PYTHONPATH}":"${QP_PYTHON}"',
|
||||
'export PATH="${PATH}":"${QP_PYTHON}":"${QP_ROOT}"/bin:"${QP_ROOT}"/ocaml',
|
||||
'export LD_LIBRARY_PATH="${QP_ROOT}"/lib:"${LD_LIBRARY_PATH}"',
|
||||
'export LIBRARY_PATH="${QP_ROOT}"/lib:"${LIBRARY_PATH}"', ""
|
||||
'source ${HOME}/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true',
|
||||
""
|
||||
]
|
||||
|
||||
path = join(QP_ROOT, "quantum_package.rc")
|
||||
with open(path, "w+") as f:
|
||||
f.write("\n".join(l_rc))
|
||||
|
||||
print "[ OK ] ({0})".format(path)
|
||||
|
||||
print str_info("build"),
|
||||
|
||||
command = ['bash', '-c', 'source {0} && env'.format(path)]
|
||||
|
||||
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
|
||||
|
||||
for line in proc.stdout:
|
||||
(key, _, value) = line.partition("=")
|
||||
os.environ[key] = value.strip()
|
||||
|
||||
qp_create_ninja = os.path.join(QP_ROOT, "scripts", "compilation",
|
||||
"qp_create_ninja.py")
|
||||
|
||||
l = [qp_create_ninja, "create"] + sys.argv[1:]
|
||||
try:
|
||||
subprocess.check_call(" ".join(l), shell=True)
|
||||
except:
|
||||
raise
|
||||
else:
|
||||
print "[ OK ]"
|
||||
|
||||
|
||||
def recommendation():
|
||||
print "Last Step:"
|
||||
path = join(QP_ROOT, "quantum_package.rc")
|
||||
print "Now :"
|
||||
print " source {0}".format(path)
|
||||
print " ninja"
|
||||
print " cd ocaml; make "
|
||||
print ""
|
||||
print "PS : For more info on compiling the code, read the COMPILE_RUN.md file."
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
l_installed, l_install_descendant = checking(d_dependency)
|
||||
|
||||
if l_install_descendant:
|
||||
print "You will need to install:"
|
||||
for i in l_install_descendant:
|
||||
print "* {0}".format(i)
|
||||
|
||||
installation(l_install_descendant)
|
||||
else:
|
||||
print "Perfect, nothing to install"
|
||||
create_ninja_and_rc(l_installed)
|
||||
|
||||
recommendation()
|
@ -1,7 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Usage: qp_create_ninja.py (--development | --production) CONFIG_FILE
|
||||
Usage: qp_create_ninja.py create <config_file> (--development | --production)
|
||||
qp_create_ninja.py update
|
||||
|
||||
"""
|
||||
|
||||
import os
|
||||
@ -10,6 +12,7 @@ import glob
|
||||
from os.path import join
|
||||
from collections import namedtuple
|
||||
from collections import defaultdict
|
||||
import pickle
|
||||
|
||||
try:
|
||||
from module_handler import ModuleHandler
|
||||
@ -19,6 +22,27 @@ except ImportError:
|
||||
print "source .quantum_package.rc"
|
||||
sys.exit(1)
|
||||
|
||||
header = r"""#
|
||||
# _______ _____
|
||||
# __ __ \___ _______ _________ /____ ________ ___
|
||||
# _ / / / / / / __ `/_ __ \ __/ / / /_ __ `__ \
|
||||
# / /_/ // /_/ // /_/ /_ / / / /_ / /_/ /_ / / / / /
|
||||
# \___\_\\__,_/ \__,_/ /_/ /_/\__/ \__,_/ /_/ /_/ /_/
|
||||
#
|
||||
# ________ ______
|
||||
# ___ __ \_____ _________ /_______ _______ _____
|
||||
# __ /_/ / __ `/ ___/_ //_/ __ `/_ __ `/ _ \
|
||||
# _ ____// /_/ // /__ _ ,< / /_/ /_ /_/ // __/
|
||||
# /_/ \__,_/ \___/ /_/|_| \__,_/ _\__, / \___/
|
||||
# /____/
|
||||
#
|
||||
# https://github.com/LCPQ/quantum_package,
|
||||
#
|
||||
# Generated automatically by {0}.".format(__file__)
|
||||
#
|
||||
#
|
||||
"""
|
||||
|
||||
# __
|
||||
# /__ | _ |_ _. | _. ._ o _. |_ | _ _
|
||||
# \_| | (_) |_) (_| | \/ (_| | | (_| |_) | (/_ _>
|
||||
@ -29,6 +53,7 @@ QP_ROOT_SRC = join(QP_ROOT, 'src')
|
||||
QP_ROOT_EZFIO = join(QP_ROOT, 'install', 'EZFIO')
|
||||
|
||||
EZFIO_LIB = join(QP_ROOT, "lib", "libezfio.a")
|
||||
ROOT_BUILD_NINJA = join(QP_ROOT, "config", "build.ninja")
|
||||
|
||||
#
|
||||
# |\ | _. ._ _ _ _| _|_ ._ | _
|
||||
@ -39,6 +64,7 @@ EZ_config_path = namedtuple('EZ_config', ['path_in_module', 'path_in_ezfio'])
|
||||
EZ_handler = namedtuple('EZ_handler', ['ez_module', 'ez_cfg', 'ez_interface',
|
||||
'ez_config'])
|
||||
Sym_link = namedtuple('Sym_link', ['source', 'destination'])
|
||||
module_instance = ModuleHandler()
|
||||
|
||||
|
||||
# _
|
||||
@ -79,8 +105,7 @@ def dict_module_genelogy_path(d_module_genelogy):
|
||||
|
||||
p = Path(module_abs, module_rel)
|
||||
try:
|
||||
d[p] = Path(join(QP_ROOT_SRC, l_children_rel),
|
||||
l_children_rel)
|
||||
d[p] = Path(join(QP_ROOT_SRC, l_children_rel), l_children_rel)
|
||||
except:
|
||||
d[p] = [Path(join(QP_ROOT_SRC, children), children)
|
||||
for children in l_children_rel]
|
||||
@ -222,14 +247,13 @@ def ninja_ezfio_rule():
|
||||
l_flag = ["export {0}='${0}'".format(flag)
|
||||
for flag in ["FC", "FCFLAGS", "IRPF90"]]
|
||||
|
||||
l_cmd = ["cd {0}".format(QP_ROOT_EZFIO)
|
||||
] + l_flag + ["ninja && ln -f {0} {1}".format(join(QP_ROOT, 'install', 'EZFIO',"lib","libezfio.a"),
|
||||
EZFIO_LIB)]
|
||||
install_lib_ezfio = join(QP_ROOT, 'install', 'EZFIO', "lib", "libezfio.a")
|
||||
l_cmd = ["cd {0}".format(QP_ROOT_EZFIO)] + l_flag
|
||||
l_cmd += ["ninja && ln -f {0} {1}".format(install_lib_ezfio, EZFIO_LIB)]
|
||||
|
||||
l_string = ["rule build_ezfio",
|
||||
" command = {0}".format(" ; ".join(l_cmd)),
|
||||
" description = Create $out"
|
||||
""]
|
||||
" pool = console", " description = Create $out", ""]
|
||||
|
||||
return l_string
|
||||
|
||||
@ -244,11 +268,7 @@ def ninja_ezfio_build(l_ezfio_config, l_util):
|
||||
l_ezfio_from_cfg = [i.ez_config.abs for i in l_util.itervalues()]
|
||||
|
||||
str_ = " ".join(l_ezfio_config + l_ezfio_from_cfg)
|
||||
|
||||
ezfio_make_config = join(QP_ROOT_EZFIO, "make.config")
|
||||
l_string = ["build {0} {1}: build_ezfio {2}".format(EZFIO_LIB,
|
||||
ezfio_make_config,
|
||||
str_), ""]
|
||||
l_string = ["build {0}: build_ezfio {1}".format(EZFIO_LIB, str_), ""]
|
||||
|
||||
return l_string
|
||||
|
||||
@ -312,17 +332,19 @@ def get_l_file_for_module(path_module):
|
||||
elif f.endswith(".irp.f"):
|
||||
l_depend.append(join(path_module.abs, f))
|
||||
elif f.lower().endswith(tuple([".f", ".f90", ".c", ".cpp", ".cxx"])):
|
||||
l_depend.append(join(path_module.abs,f))
|
||||
l_depend.append(join(path_module.abs, f))
|
||||
l_src.append(f)
|
||||
obj = '{0}.o'.format(os.path.splitext(f)[0])
|
||||
l_obj.append(obj)
|
||||
elif f == "EZFIO.cfg":
|
||||
l_depend.append(join(path_module.abs, "ezfio_interface.irp.f"))
|
||||
|
||||
d = {"l_depend": l_depend,
|
||||
"l_src": l_src,
|
||||
"l_obj": l_obj,
|
||||
"l_template": l_template}
|
||||
d = {
|
||||
"l_depend": l_depend,
|
||||
"l_src": l_src,
|
||||
"l_obj": l_obj,
|
||||
"l_template": l_template
|
||||
}
|
||||
|
||||
return d
|
||||
|
||||
@ -337,18 +359,20 @@ def get_file_dependency(d_info_module):
|
||||
|
||||
for key, values in get_l_file_for_module(module).iteritems():
|
||||
if key in ["l_src"]:
|
||||
values = [join(module.abs,o) for o in values]
|
||||
values = [join(module.abs, o) for o in values]
|
||||
if key in ["l_obj"]:
|
||||
values = [join(module.abs,"IRPF90_temp",o) for o in values]
|
||||
values = [join(module.abs, "IRPF90_temp", o) for o in values]
|
||||
|
||||
d_irp[module][key] = values
|
||||
|
||||
for children in l_children:
|
||||
for key, values in get_l_file_for_module(children).iteritems():
|
||||
if key in ["l_src"]:
|
||||
values = [join(module.abs,children.rel,o) for o in values]
|
||||
values = [join(module.abs, children.rel, o)
|
||||
for o in values]
|
||||
if key in ["l_obj"]:
|
||||
values = [join(module.abs,"IRPF90_temp",children.rel,o) for o in values]
|
||||
values = [join(module.abs, "IRPF90_temp", children.rel, o)
|
||||
for o in values]
|
||||
|
||||
d_irp[module][key].extend(values)
|
||||
|
||||
@ -374,7 +398,7 @@ def ninja_irpf90_make_rule():
|
||||
# c m d #
|
||||
# ~#~#~ #
|
||||
|
||||
l_cmd = ["cd $module"] + l_flag + ["irpf90 $include_dir $IRPF90_FLAGS"]
|
||||
l_cmd = ["cd $module_abs"] + l_flag + ["irpf90 $include_dir $IRPF90_FLAGS"]
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# s t r i n g #
|
||||
@ -383,7 +407,7 @@ def ninja_irpf90_make_rule():
|
||||
l_string = ["pool irp_pool", " depth = 1", "", "rule build_irpf90.ninja",
|
||||
" command = {0}".format(" ; ".join(l_cmd)),
|
||||
" pool = irp_pool",
|
||||
" description = Create the IRP_Tree for $module", ""]
|
||||
" description = Running IRPF90 for $module_rel", ""]
|
||||
|
||||
return l_string
|
||||
|
||||
@ -426,7 +450,8 @@ def ninja_irpf90_make_build(path_module, l_needed_molule, d_irp):
|
||||
|
||||
l_string = [
|
||||
"build {0}: build_irpf90.ninja {1}".format(str_creation, str_depend),
|
||||
" module = {0}".format(path_module.abs),
|
||||
" module_abs = {0}".format(path_module.abs),
|
||||
" module_rel = {0}".format(path_module.rel),
|
||||
" SRC = {0}".format(" ".join(l_src)),
|
||||
" OBJ = {0}".format(" ".join(l_obj)),
|
||||
" include_dir = {0}".format(" ".join(l_include_dir)), ""
|
||||
@ -441,7 +466,7 @@ def ninja_readme_rule():
|
||||
For not dealted the readme when ninja -t clean and the generator option
|
||||
"""
|
||||
l_string = ["rule build_readme",
|
||||
" command = cd $module ; update_README.py",
|
||||
" command = cd $module_abs ; update_README.py",
|
||||
" generator = 1", ""]
|
||||
|
||||
return l_string
|
||||
@ -456,7 +481,8 @@ def ninja_readme_build(path_module):
|
||||
|
||||
l_string = ["build {0}: build_readme {1}".format(path_readme,
|
||||
path_irp_man),
|
||||
" module = {0}".format(path_module.abs), ""]
|
||||
" module_abs = {0}".format(path_module.abs),
|
||||
" module_rel = {0}".format(path_module.rel), ""]
|
||||
|
||||
return l_string
|
||||
|
||||
@ -498,6 +524,9 @@ def get_dict_binaries(l_module, mode="production"):
|
||||
|
||||
Example : The module Full_CI can produce the binary SCF
|
||||
so you dont need to compile at all the module Hartree-Fock
|
||||
|
||||
But you need to change the path acordingle
|
||||
Full_CI/Hartree-Fock/SCF
|
||||
"""
|
||||
d_binaries = defaultdict(list)
|
||||
|
||||
@ -511,12 +540,28 @@ def get_dict_binaries(l_module, mode="production"):
|
||||
|
||||
if mode == "production":
|
||||
|
||||
dict_root = ModuleHandler.dict_root
|
||||
dict_root_path = dict_module_genelogy_path(dict_root)
|
||||
dict_root = module_instance.dict_root
|
||||
dict_root_module_path = dict_module_genelogy_path(dict_root)
|
||||
|
||||
d_binaries_condensed = defaultdict(list)
|
||||
|
||||
for module in d_binaries:
|
||||
d_binaries_condensed[dict_root_path[module]] += d_binaries[module]
|
||||
|
||||
root_module = dict_root_module_path[module]
|
||||
|
||||
if module == root_module:
|
||||
d_binaries_condensed[root_module] += d_binaries[module]
|
||||
else:
|
||||
|
||||
l_binaries = []
|
||||
for binaries in d_binaries[module]:
|
||||
p_abs = join(QP_ROOT_SRC, root_module.rel, module.rel,
|
||||
binaries.rel)
|
||||
p_rel = binaries.rel
|
||||
p = Path(p_abs, p_rel)
|
||||
l_binaries.append(p)
|
||||
|
||||
d_binaries_condensed[root_module] += l_binaries
|
||||
|
||||
d_binaries = d_binaries_condensed
|
||||
|
||||
@ -532,7 +577,7 @@ def ninja_binaries_rule():
|
||||
# c m d #
|
||||
# ~#~#~ #
|
||||
|
||||
l_cmd = ["cd $module", "ninja -C IRPF90_temp"]
|
||||
l_cmd = ["cd $module_abs/IRPF90_temp", "ninja $out && touch $out"]
|
||||
|
||||
# ~#~#~#~#~#~ #
|
||||
# s t r i n g #
|
||||
@ -540,7 +585,9 @@ def ninja_binaries_rule():
|
||||
|
||||
l_string = ["rule build_binaries",
|
||||
" command = {0}".format(" ; ".join(l_cmd)),
|
||||
" description = Create all the binaries from $module", ""]
|
||||
" pool = console",
|
||||
" description = Create all the binaries from $module_rel",
|
||||
""]
|
||||
|
||||
return l_string
|
||||
|
||||
@ -564,8 +611,25 @@ def ninja_binaries_build(path_module, l_children, d_binaries):
|
||||
l_string = ["build {0}: build_binaries {1} {2}".format(" ".join(l_abs_bin),
|
||||
EZFIO_LIB,
|
||||
ninja_module_path),
|
||||
" module = {0}".format(path_module.abs), ""]
|
||||
" module_abs = {0}".format(path_module.abs),
|
||||
" module_rel = {0}".format(path_module.rel), ""]
|
||||
|
||||
l_string += ["build module_{0}: phony {1}".format(path_module.rel,
|
||||
" ".join(l_abs_bin)), ""]
|
||||
|
||||
return l_string
|
||||
|
||||
|
||||
#
|
||||
# |\/| _ _| | _
|
||||
# | | (_) (_| |_| | (/_
|
||||
#
|
||||
def create_module_ninja():
|
||||
"""
|
||||
In a module create a build.ninja
|
||||
"""
|
||||
|
||||
l_string = ["rule all:"]
|
||||
return l_string
|
||||
|
||||
|
||||
@ -581,13 +645,14 @@ def ninja_dot_tree_rule():
|
||||
# c m d #
|
||||
# ~#~#~ #
|
||||
|
||||
l_cmd = ["cd $module", "module_handler.py create_png"]
|
||||
l_cmd = ["cd $module_abs", "module_handler.py create_png"]
|
||||
|
||||
l_string = ["rule build_dot_tree",
|
||||
" command = {0}".format(" ; ".join(l_cmd)),
|
||||
" generator = 1",
|
||||
" description = Generate Png representtion of the Tree Dependancies of $module",
|
||||
""]
|
||||
l_string = [
|
||||
"rule build_dot_tree", " command = {0}".format(" ; ".join(l_cmd)),
|
||||
" generator = 1",
|
||||
" description = Generate Png representtion of the Tree Dependencies of $module_rel",
|
||||
""
|
||||
]
|
||||
|
||||
return l_string
|
||||
|
||||
@ -596,18 +661,100 @@ def ninja_dot_tree_build(path_module):
|
||||
|
||||
path_tree = join(path_module.abs, "tree_dependency.png")
|
||||
l_string = ["build {0}: build_dot_tree".format(path_tree),
|
||||
" module = {0}".format(path_module.abs), ""]
|
||||
" module_abs = {0}".format(path_module.abs),
|
||||
" module_rel = {0}".format(path_module.rel), ""]
|
||||
|
||||
return l_string
|
||||
|
||||
|
||||
#
|
||||
# |\/| _ _| | _
|
||||
# | | (_) (_| |_| | (/_
|
||||
#
|
||||
def create_build_ninja_module(path_module):
|
||||
|
||||
l_string = ["rule update_build_ninja_root",
|
||||
" command = qp_create_ninja.py update", ""]
|
||||
|
||||
l_string += ["rule make_local_binaries",
|
||||
" command = ninja -f {0} module_{1}".format(
|
||||
ROOT_BUILD_NINJA, path_module.rel), " pool = console",
|
||||
" description = Compile only {0}".format(path_module.rel),
|
||||
""]
|
||||
|
||||
l_string += ["rule make_all_binaries",
|
||||
" command = ninja -f {0}".format(ROOT_BUILD_NINJA),
|
||||
" pool = console", " description = Compile all the module",
|
||||
""]
|
||||
|
||||
l_string += ["rule make_clean", " command = clean_modules.sh",
|
||||
" description = Cleaning module {0}".format(path_module.rel),
|
||||
""]
|
||||
|
||||
l_string += ["build dummy_target: update_build_ninja_root", "",
|
||||
"build all: make_all_binaries dummy_target", "",
|
||||
"build local: make_local_binaries dummy_target",
|
||||
"default local", "", "build clean: make_clean dummy_target",
|
||||
""]
|
||||
|
||||
path_ninja_cur = join(path_module.abs, "build.ninja")
|
||||
with open(path_ninja_cur, "w") as f:
|
||||
f.write(header)
|
||||
f.write("\n".join(l_string))
|
||||
|
||||
|
||||
def create_build_ninja_global():
|
||||
|
||||
l_string = ["rule update_build_ninja_root",
|
||||
" command = qp_create_ninja.py update", ""]
|
||||
|
||||
l_string += ["rule make_all_binaries",
|
||||
" command = ninja -f {0}".format(ROOT_BUILD_NINJA),
|
||||
" pool = console", " description = Compile all the module",
|
||||
""]
|
||||
|
||||
l_string += ["rule make_clean",
|
||||
" command = cd {0} ; clean_modules.sh *".format(QP_ROOT_SRC),
|
||||
" description = Cleaning all modules", ""]
|
||||
|
||||
l_string += ["build dummy_target: update_build_ninja_root",
|
||||
"",
|
||||
"build all: make_all_binaries dummy_target",
|
||||
"default all",
|
||||
"",
|
||||
"build clean: make_clean",
|
||||
"", ]
|
||||
|
||||
path_ninja_cur = join(QP_ROOT, "build.ninja")
|
||||
with open(path_ninja_cur, "w") as f:
|
||||
f.write(header)
|
||||
f.write("\n".join(l_string))
|
||||
|
||||
#
|
||||
# |\/| _. o ._
|
||||
# | | (_| | | |
|
||||
#
|
||||
if __name__ == "__main__":
|
||||
|
||||
arguments = docopt(__doc__)
|
||||
pwd_config_file = arguments["CONFIG_FILE"]
|
||||
|
||||
pickle_path = os.path.join(QP_ROOT, "config", "qp_create_ninja.pickle")
|
||||
|
||||
if arguments["update"]:
|
||||
try:
|
||||
with open(pickle_path, 'rb') as handle:
|
||||
arguments = pickle.load(handle)
|
||||
except IOError:
|
||||
print "You need to create first my friend"
|
||||
sys.exit(1)
|
||||
|
||||
elif arguments["create"]:
|
||||
|
||||
arguments["<config_file>"] = os.path.realpath(arguments["<config_file>"])
|
||||
|
||||
with open(pickle_path, 'wb') as handle:
|
||||
pickle.dump(arguments, handle)
|
||||
|
||||
pwd_config_file = arguments["<config_file>"]
|
||||
|
||||
# _
|
||||
# |_ ._ _. ._ o _. |_ | _ _
|
||||
@ -656,26 +803,32 @@ if __name__ == "__main__":
|
||||
# G e n e a l o g y _ d i c t #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
d_genealogy = ModuleHandler.dict_descendant
|
||||
d_genealogy = module_instance.dict_descendant
|
||||
d_genealogy_path = dict_module_genelogy_path(d_genealogy)
|
||||
d_irp = get_file_dependency(d_genealogy_path)
|
||||
|
||||
l_module = d_genealogy_path.keys()
|
||||
|
||||
d_binaries_production = get_dict_binaries(l_module,
|
||||
mode="production")
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# M o d u l e _ t o _ i r p #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
if arguments["--production"]:
|
||||
l_module_to_irp = d_binaries_production.keys()
|
||||
|
||||
d_binaries = get_dict_binaries(l_module, mode="production")
|
||||
l_module = d_binaries.keys()
|
||||
|
||||
elif arguments["--development"]:
|
||||
l_module_to_irp = d_genealogy_path.keys()
|
||||
|
||||
for module_to_compile in l_module_to_irp:
|
||||
d_binaries = get_dict_binaries(l_module, mode="development")
|
||||
l_module = d_binaries.keys()
|
||||
|
||||
create_build_ninja_global()
|
||||
|
||||
for module_to_compile in l_module:
|
||||
|
||||
if arguments["--development"]:
|
||||
create_build_ninja_module(module_to_compile)
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# S y m l i n k #
|
||||
@ -697,13 +850,9 @@ if __name__ == "__main__":
|
||||
l_string += ninja_dot_tree_build(module_to_compile)
|
||||
l_string += ninja_readme_build(module_to_compile)
|
||||
|
||||
# ~#~#~#~#~#~#~ #
|
||||
# b i n a r y #
|
||||
# ~#~#~#~#~#~#~ #
|
||||
for module_to_compile in d_binaries_production.keys():
|
||||
|
||||
l_string += ninja_binaries_build(module_to_compile, l_children,
|
||||
d_binaries_production)
|
||||
d_binaries)
|
||||
|
||||
with open(join(QP_ROOT, "build.ninja"), "w+") as f:
|
||||
with open(join(QP_ROOT, "config", "build.ninja"), "w+") as f:
|
||||
f.write(header)
|
||||
f.write("\n".join(l_string))
|
||||
|
@ -13,11 +13,9 @@ source ${QP_ROOT}/scripts/qp_include.sh
|
||||
function do_clean()
|
||||
{
|
||||
rm -rf -- \
|
||||
IRPF90_temp IRPF90_man Makefile.depend \
|
||||
IRPF90_temp IRPF90_man \
|
||||
$(module_handler.py print_descendant) include \
|
||||
ezfio_interface.irp.f irpf90.make irpf90_entities tags $(ls_exe) *.mod
|
||||
|
||||
touch -c EZFIO.cfg *.ezfio_config
|
||||
}
|
||||
|
||||
if [[ -z $1 ]]
|
||||
|
@ -19,42 +19,51 @@ Options:
|
||||
import os
|
||||
import sys
|
||||
import os.path
|
||||
from collections import namedtuple
|
||||
|
||||
try:
|
||||
from docopt import docopt
|
||||
from decorator import classproperty
|
||||
except ImportError:
|
||||
print "source .quantum_package.rc"
|
||||
raise
|
||||
|
||||
|
||||
# Canot cache for namedtuple are not hashable
|
||||
def get_dict_child():
|
||||
def get_dict_child(l_root_abs=None):
|
||||
"""Loop over MODULE in QP_ROOT/src, open all the NEEDED_CHILDREN_MODULES
|
||||
and create a dict[MODULE] = [sub module needed, ...]
|
||||
"""
|
||||
d_ref = dict()
|
||||
|
||||
qp_root = os.environ['QP_ROOT']
|
||||
dir_ = os.path.join(qp_root, 'src')
|
||||
if not l_root_abs:
|
||||
qp_root = os.environ['QP_ROOT']
|
||||
l_root_abs = [os.path.join(qp_root, 'src')]
|
||||
|
||||
for o in os.listdir(dir_):
|
||||
for root_abs in l_root_abs:
|
||||
for module_rel in os.listdir(root_abs):
|
||||
|
||||
try:
|
||||
path_file = os.path.join(dir_, o, "NEEDED_CHILDREN_MODULES")
|
||||
with open(path_file, "r") as f:
|
||||
l_children = f.read().split()
|
||||
except IOError:
|
||||
pass
|
||||
else:
|
||||
d_ref[o] = l_children
|
||||
module_abs = os.path.join(root_abs, module_rel)
|
||||
try:
|
||||
path_file = os.path.join(module_abs, "NEEDED_CHILDREN_MODULES")
|
||||
|
||||
with open(path_file, "r") as f:
|
||||
l_children = f.read().split()
|
||||
except IOError:
|
||||
pass
|
||||
else:
|
||||
if module_rel not in d_ref:
|
||||
d_ref[module_rel] = l_children
|
||||
else:
|
||||
print "Module {0} alredy defined"
|
||||
print "Abort"
|
||||
sys.exit(1)
|
||||
|
||||
return d_ref
|
||||
|
||||
|
||||
def l_module_generalogy_rec(d_chidlren, l_module):
|
||||
def get_l_module_descendant(d_child, l_module):
|
||||
"""
|
||||
From a list of module return the module and all of the genealogy
|
||||
From a list of module return the module and descendant
|
||||
"""
|
||||
|
||||
l = []
|
||||
@ -62,7 +71,7 @@ def l_module_generalogy_rec(d_chidlren, l_module):
|
||||
if module not in l:
|
||||
l.append(module)
|
||||
try:
|
||||
l.extend(l_module_generalogy_rec(d_chidlren, d_chidlren[module]))
|
||||
l.extend(get_l_module_descendant(d_child, d_child[module]))
|
||||
except KeyError:
|
||||
print >> sys.stderr, "`{0}` not submodule".format(module)
|
||||
print >> sys.stderr, "Check the corresponding NEEDED_CHILDREN_MODULES"
|
||||
@ -71,15 +80,16 @@ def l_module_generalogy_rec(d_chidlren, l_module):
|
||||
return list(set(l))
|
||||
|
||||
|
||||
class ModuleHandler:
|
||||
class ModuleHandler():
|
||||
|
||||
dict_child = get_dict_child()
|
||||
def __init__(self, l_root_abs=None):
|
||||
self.dict_child = get_dict_child(l_root_abs)
|
||||
|
||||
@classproperty
|
||||
@property
|
||||
def l_module(self):
|
||||
return self.dict_child.keys()
|
||||
|
||||
@classproperty
|
||||
@property
|
||||
def dict_parent(self):
|
||||
"""
|
||||
Get a dic of the first parent
|
||||
@ -93,7 +103,7 @@ class ModuleHandler:
|
||||
|
||||
return d
|
||||
|
||||
@classproperty
|
||||
@property
|
||||
def dict_descendant(self):
|
||||
"""
|
||||
Get a dic of all the genealogy desc (children and all_children)
|
||||
@ -103,12 +113,12 @@ class ModuleHandler:
|
||||
d_child = self.dict_child
|
||||
|
||||
for module_name in d_child:
|
||||
d[module_name] = l_module_generalogy_rec(d_child,
|
||||
d[module_name] = get_l_module_descendant(d_child,
|
||||
d_child[module_name])
|
||||
|
||||
return d
|
||||
|
||||
@classproperty
|
||||
@property
|
||||
def dict_root(self):
|
||||
"""
|
||||
Return a dict(module_name) = module_boss
|
||||
@ -126,9 +136,8 @@ class ModuleHandler:
|
||||
|
||||
return dict_root
|
||||
|
||||
@classmethod
|
||||
def l_descendant_unique(cls, l_module):
|
||||
d_desc = cls.dict_descendant
|
||||
def l_descendant_unique(self, l_module):
|
||||
d_desc = self.dict_descendant
|
||||
|
||||
d = {}
|
||||
for module in l_module:
|
||||
@ -137,10 +146,9 @@ class ModuleHandler:
|
||||
|
||||
return d.keys()
|
||||
|
||||
@classmethod
|
||||
def l_reduce_tree(cls, l_module):
|
||||
def l_reduce_tree(self, l_module):
|
||||
"""For a list of module in input return only the root"""
|
||||
l_d_u = cls.l_descendant_unique(l_module)
|
||||
l_d_u = self.l_descendant_unique(l_module)
|
||||
l_module_reduce = []
|
||||
for module in l_module:
|
||||
if module not in l_d_u:
|
||||
@ -148,8 +156,7 @@ class ModuleHandler:
|
||||
|
||||
return l_module_reduce
|
||||
|
||||
@classmethod
|
||||
def create_png(cls, l_module):
|
||||
def create_png(self, l_module):
|
||||
"""Create the png of the dependency tree for a l_module"""
|
||||
|
||||
# Init
|
||||
@ -170,7 +177,7 @@ class ModuleHandler:
|
||||
|
||||
# Init
|
||||
graph = pydot.Dot(graph_type='digraph')
|
||||
d_ref = cls.dict_child
|
||||
d_ref = self.dict_child
|
||||
|
||||
# Create all the edge
|
||||
for module in l_module:
|
||||
@ -196,9 +203,10 @@ if __name__ == '__main__':
|
||||
dir_ = os.path.dirname(path_file)
|
||||
|
||||
path_file = os.path.basename(dir_)
|
||||
m = ModuleHandler()
|
||||
|
||||
if arguments['print_descendant']:
|
||||
print " ".join(sorted(ModuleHandler.l_module))
|
||||
print " ".join(sorted(m.l_module))
|
||||
|
||||
if arguments["create_png"]:
|
||||
ModuleHandler.create_png([path_file])
|
||||
m.create_png([path_file])
|
||||
|
@ -1,12 +1,15 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Usage: qp_install_module.py list
|
||||
Usage: qp_install_module.py list [--installed|--avalaible-local|--avalaible-remote]
|
||||
qp_install_module.py install -n <name>
|
||||
qp_install_module.py create -n <name> [<children_module>...]
|
||||
qp_install_module.py download -n <name> [<path_folder>...]
|
||||
|
||||
|
||||
Options:
|
||||
list: List all the module avalaible
|
||||
create: Create a new module
|
||||
create: Create a new module
|
||||
"""
|
||||
|
||||
import sys
|
||||
@ -14,7 +17,8 @@ import os
|
||||
|
||||
try:
|
||||
from docopt import docopt
|
||||
from module_handler import ModuleHandler
|
||||
from module_handler import ModuleHandler, get_dict_child
|
||||
from module_handler import get_l_module_descendant
|
||||
from update_README import Doc_key, Needed_key
|
||||
except ImportError:
|
||||
print "source .quantum_package.rc"
|
||||
@ -53,22 +57,32 @@ def save_new_module(path, l_child):
|
||||
|
||||
if __name__ == '__main__':
|
||||
arguments = docopt(__doc__)
|
||||
qp_root_src = os.path.join(os.environ['QP_ROOT'], "src")
|
||||
qp_root_plugin = os.path.join(os.environ['QP_ROOT'], "plugins")
|
||||
|
||||
if arguments["list"]:
|
||||
for module in ModuleHandler.l_module:
|
||||
|
||||
if arguments["--installed"]:
|
||||
l_repository = [qp_root_src]
|
||||
|
||||
m_instance = ModuleHandler(l_repository)
|
||||
|
||||
for module in m_instance.l_module:
|
||||
print module
|
||||
|
||||
elif arguments["create"]:
|
||||
m_instance = ModuleHandler(l_repository)
|
||||
|
||||
l_children = arguments["<children_module>"]
|
||||
|
||||
qpackage_root = os.environ['QP_ROOT']
|
||||
path = os.path.join(qpackage_root, "src", arguments["<name>"])
|
||||
qp_root = os.environ['QP_ROOT']
|
||||
path = os.path.join(qp_root_src, arguments["<name>"])
|
||||
|
||||
print "You will create the module:"
|
||||
print path
|
||||
|
||||
for children in l_children:
|
||||
if children not in ModuleHandler.dict_descendant:
|
||||
if children not in m_instance.dict_descendant:
|
||||
print "This module ({0}) is not a valide module.".format(children)
|
||||
print "Run `list` flag for the list of module avalaible"
|
||||
print "Aborting..."
|
||||
@ -78,9 +92,41 @@ if __name__ == '__main__':
|
||||
print l_children
|
||||
|
||||
print "You can use all the routine in this module"
|
||||
print l_children + ModuleHandler.l_descendant_unique(l_children)
|
||||
print l_children + m_instance.l_descendant_unique(l_children)
|
||||
|
||||
print "This can be reduce to:"
|
||||
l_child_reduce = ModuleHandler.l_reduce_tree(l_children)
|
||||
l_child_reduce = m_instance.l_reduce_tree(l_children)
|
||||
print l_child_reduce
|
||||
save_new_module(path, l_child_reduce)
|
||||
|
||||
elif arguments["download"]:
|
||||
|
||||
d_local = get_dict_child([qp_root_src])
|
||||
d_remote = get_dict_child(arguments["<path_folder>"])
|
||||
|
||||
d_child = d_local.copy()
|
||||
d_child.update(d_remote)
|
||||
|
||||
name = arguments["<name>"]
|
||||
l_module_descendant = get_l_module_descendant(d_child, [name])
|
||||
|
||||
for module in l_module_descendant:
|
||||
if module not in d_local:
|
||||
print "you need to install", module
|
||||
|
||||
elif arguments["install"]:
|
||||
|
||||
d_local = get_dict_child([qp_root_src])
|
||||
|
||||
d_plugin = get_dict_child([qp_root_plugin])
|
||||
|
||||
d_child = d_local.copy()
|
||||
d_child.update(d_plugin)
|
||||
|
||||
name = arguments["<name>"]
|
||||
l_module_descendant = get_l_module_descendant(d_child, [name])
|
||||
|
||||
module_to_cp = [module for module in l_module_descendant if module not in d_local]
|
||||
|
||||
print "For ln -s by hand the module"
|
||||
print module_to_cp
|
||||
|
@ -1,26 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Upgrades the EZFIO library from the web.
|
||||
# Tue Nov 4 00:53:13 CET 2014
|
||||
|
||||
if [[ -z ${QP_ROOT} ]]
|
||||
then
|
||||
print "The QP_ROOT environment variable is not set."
|
||||
print "Please reload the quantum_package.rc file."
|
||||
fi
|
||||
|
||||
cd -- ${QP_ROOT}
|
||||
mv -- ${QP_ROOT}/EZFIO ${QP_ROOT}/EZFIO.old
|
||||
|
||||
${QP_ROOT}/scripts/install/install_ezfio.sh
|
||||
|
||||
if [[ $? -eq 0 ]]
|
||||
then
|
||||
rm -rf -- ${QP_ROOT}/EZFIO.old
|
||||
echo "Successfully updated EZFIO"
|
||||
else
|
||||
rm -rf -- ${QP_ROOT}/EZFIO
|
||||
mv -- ${QP_ROOT}/EZFIO.old ${QP_ROOT}/EZFIO
|
||||
echo "Failed to update EZFIO"
|
||||
fi
|
||||
|
@ -1,25 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Upgrades IRPF90 from the web.
|
||||
# Wed Mar 25 11:41:04 CET 2015
|
||||
|
||||
if [[ -z ${QP_ROOT} ]]
|
||||
then
|
||||
print "The QP_ROOT environment variable is not set."
|
||||
print "Please reload the quantum_package.rc file."
|
||||
fi
|
||||
|
||||
cd -- ${QP_ROOT}
|
||||
mv -f -- ${QP_ROOT}/irpf90 ${QP_ROOT}/irpf90.old
|
||||
|
||||
${QP_ROOT}/scripts/install/install_irpf90.sh
|
||||
|
||||
if [[ $? -eq 0 ]]
|
||||
then
|
||||
rm -rf -- ${QP_ROOT}/irpf90.old
|
||||
echo "Successfully updated IRPF90"
|
||||
else
|
||||
rm -rf -- ${QP_ROOT}/irpf90
|
||||
mv -- ${QP_ROOT}/irpf90.old ${QP_ROOT}/irpf90
|
||||
echo "Failed to update IRPF90"
|
||||
fi
|
@ -15,12 +15,3 @@ def cache(func):
|
||||
saved[args] = result
|
||||
return result
|
||||
return newfunc
|
||||
|
||||
|
||||
class classproperty(object):
|
||||
|
||||
def __init__(self, fget):
|
||||
self.fget = fget
|
||||
|
||||
def __get__(self, owner_self, owner_cls):
|
||||
return self.fget(owner_cls)
|
||||
|
@ -1,400 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
import pprint
|
||||
|
||||
from os.path import join
|
||||
|
||||
def finalize():
|
||||
path = join(QP_ROOT, "quantum_package.rc")
|
||||
print "For more info on compiling the code, read the COMPILE_RUN.md file."
|
||||
print ""
|
||||
print "You can check {0} and run:".format(path)
|
||||
print ""
|
||||
print " source {0}".format(path)
|
||||
print " qp_create_ninja.py --production $QP_ROOT/config/ifort.cfg"
|
||||
print " ninja"
|
||||
print " make -C ocaml"
|
||||
print ""
|
||||
sys.exit()
|
||||
|
||||
|
||||
# __ _
|
||||
# /__ | _ |_ _. | o ._ _|_ _
|
||||
# \_| |_ (_) |_) (_| | | | | | (_)
|
||||
#
|
||||
|
||||
QP_ROOT = os.getcwd()
|
||||
QP_ROOT_BIN = join(QP_ROOT, "bin")
|
||||
QP_ROOT_INSTALL = join(QP_ROOT, "install")
|
||||
os.environ["PATH"] = ":".join( [QP_ROOT_BIN,os.environ["PATH"] ] )
|
||||
|
||||
|
||||
d_dependency = {
|
||||
"ocaml": ["m4", "curl", "zlib", "patch", "gcc"],
|
||||
"m4": ["make"],
|
||||
"curl": ["make"],
|
||||
"zlib": ["gcc", "make"],
|
||||
"patch": ["make"],
|
||||
"ezfio": ["irpf90"],
|
||||
"irpf90": ["python"],
|
||||
"docopt": ["python"],
|
||||
"resultsFile": ["python"],
|
||||
"emsl": ["python"],
|
||||
"gcc": [],
|
||||
"python": [],
|
||||
"ninja": ["gcc", "python"],
|
||||
"make": []
|
||||
}
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
Info = namedtuple("Info", ["url", "description", "default_path"])
|
||||
|
||||
path_github = {"head": "http://github.com/", "tail": "archive/master.tar.gz"}
|
||||
|
||||
ocaml = Info(
|
||||
url='http://raw.github.com/ocaml/opam/master/shell/opam_installer.sh',
|
||||
description=' ocaml (it will take some time roughly 20min)',
|
||||
default_path=join(QP_ROOT_BIN, "opam"))
|
||||
|
||||
m4 = Info(
|
||||
url="http://ftp.gnu.org/gnu/m4/m4-latest.tar.gz",
|
||||
description=" m4",
|
||||
default_path=join(QP_ROOT_BIN, "m4"))
|
||||
|
||||
curl = Info(
|
||||
url="http://qmcchem.ups-tlse.fr/files/scemama/curl-7.30.0.ermine.tar.bz2",
|
||||
description=" curl",
|
||||
default_path=join(QP_ROOT_BIN, "curl"))
|
||||
|
||||
zlib = Info(
|
||||
url='http://zlib.net/zlib-1.2.8.tar.gz',
|
||||
description=' zlib',
|
||||
default_path=join(QP_ROOT_INSTALL, "zlib"))
|
||||
|
||||
path = Info(
|
||||
url='ftp://ftp.gnu.org/gnu/patch/patch-2.7.5.tar.gz',
|
||||
description=' path',
|
||||
default_path=join(QP_ROOT_BIN, "patch"))
|
||||
|
||||
irpf90 = Info(
|
||||
url='{head}/scemama/irpf90/archive/v1.6.6.tar.gz'.format(**path_github),
|
||||
description=' irpf90',
|
||||
default_path=join(QP_ROOT_BIN, "irpf90"))
|
||||
|
||||
docopt = Info(
|
||||
url='{head}/docopt/docopt/{tail}'.format(**path_github),
|
||||
description=' docop',
|
||||
default_path=join(QP_ROOT_INSTALL, "docopt"))
|
||||
|
||||
resultsFile = Info(
|
||||
url='{head}/LCPQ/resultsFile/{tail}'.format(**path_github),
|
||||
description=' resultsFile',
|
||||
default_path=join(QP_ROOT_INSTALL, "resultsFile"))
|
||||
|
||||
ninja = Info(
|
||||
url='{head}/martine/ninja/{tail}'.format(**path_github),
|
||||
description=' nina',
|
||||
default_path=join(QP_ROOT_BIN, "ninja"))
|
||||
|
||||
emsl = Info(
|
||||
url='{head}/LCPQ/EMSL_Basis_Set_Exchange_Local/{tail}'.format(**
|
||||
path_github),
|
||||
description=' emsl',
|
||||
default_path=join(QP_ROOT_INSTALL, "emsl"))
|
||||
|
||||
ezfio = Info(
|
||||
url='{head}/LCPQ/EZFIO/{tail}'.format(**path_github),
|
||||
description=' EZFIO',
|
||||
default_path=join(QP_ROOT_INSTALL, "EZFIO"))
|
||||
|
||||
d_info = dict()
|
||||
|
||||
for m in ["ocaml", "m4", "curl", "zlib", "path", "irpf90", "docopt",
|
||||
"resultsFile", "ninja", "emsl", "ezfio"]:
|
||||
exec ("d_info['{0}']={0}".format(m))
|
||||
|
||||
l_need = []
|
||||
|
||||
|
||||
# _
|
||||
# |_ ._ _ _|_ o _ ._
|
||||
# | |_| | | (_ |_ | (_) | |
|
||||
#
|
||||
def check_output(*popenargs, **kwargs):
|
||||
"""Run command with arguments and return its output as a byte string.
|
||||
|
||||
Backported from Python 2.7 as it's implemented as pure python on stdlib.
|
||||
|
||||
>>> check_output(['/usr/bin/python', '--version'])
|
||||
Python 2.6.2
|
||||
"""
|
||||
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
|
||||
output, unused_err = process.communicate()
|
||||
retcode = process.poll()
|
||||
if retcode:
|
||||
cmd = kwargs.get("args")
|
||||
if cmd is None:
|
||||
cmd = popenargs[0]
|
||||
error = subprocess.CalledProcessError(retcode, cmd)
|
||||
error.output = output
|
||||
raise error
|
||||
return output
|
||||
|
||||
|
||||
def check_python():
|
||||
req_version = (2, 6)
|
||||
cur_version = sys.version_info
|
||||
|
||||
# Check python
|
||||
if cur_version >= req_version:
|
||||
l_installed["python"] = ""
|
||||
else:
|
||||
print "To old version (need >2.5). Abort"
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def check_availabiliy(binary):
|
||||
|
||||
if binary == "python":
|
||||
check_python()
|
||||
|
||||
try:
|
||||
return check_output(["which", binary])
|
||||
except subprocess.CalledProcessError:
|
||||
default_path = d_info[binary].default_path
|
||||
if os.path.exists(default_path):
|
||||
return default_path
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
def splitext(path):
|
||||
for ext in ['.tar.gz', '.tar.bz2']:
|
||||
if path.endswith(ext):
|
||||
return path[:-len(ext)], path[-len(ext):]
|
||||
return os.path.splitext(path)
|
||||
|
||||
|
||||
l_installed = dict()
|
||||
|
||||
print """
|
||||
_
|
||||
/ |_ _ _ | o ._ _
|
||||
\_ | | (/_ (_ |< | | | (_|
|
||||
_|
|
||||
"""
|
||||
|
||||
# Check all the other
|
||||
length = max( [ len(i) for i in d_dependency ] )
|
||||
fmt = "%"+str(length)+"s"
|
||||
for i in d_dependency.keys():
|
||||
print "Checking if %s is avalaible..."%( i.center(length) ),
|
||||
|
||||
r = check_availabiliy(i)
|
||||
if r:
|
||||
print "[ OK ]"
|
||||
l_installed[i] = r.strip()
|
||||
else:
|
||||
print "Will compile it"
|
||||
l_need.append(i)
|
||||
|
||||
# Expend the need_stuff for all the genealogy
|
||||
|
||||
d_need_genealogy = dict()
|
||||
|
||||
for need in l_need:
|
||||
d_need_genealogy[need] = None
|
||||
for childen in d_dependency[need]:
|
||||
if childen not in l_installed:
|
||||
d_need_genealogy[childen] = None
|
||||
|
||||
l_need_genealogy = d_need_genealogy.keys()
|
||||
|
||||
print """
|
||||
__
|
||||
(_ ._ _ ._ _ _. ._
|
||||
__) |_| | | | | | | (_| | \/
|
||||
/
|
||||
"""
|
||||
|
||||
print "You have already installed :"
|
||||
def f( (a1,a2), (key,value) ):
|
||||
return tuple(max(x,len(y)) for (x,y) in [(a1,key), (a2,value)] )
|
||||
fmt_tuple =reduce(f, l_installed.iteritems(), (0,0))
|
||||
for k,v in l_installed.iteritems():
|
||||
fmt = "{0:<%d} : {1:<%d}"%fmt_tuple
|
||||
print fmt.format( k, v )
|
||||
|
||||
print """
|
||||
___
|
||||
| ._ _ _|_ _. | | _. _|_ o _ ._
|
||||
_|_ | | _> |_ (_| | | (_| |_ | (_) | |
|
||||
|
||||
"""
|
||||
|
||||
if l_need_genealogy:
|
||||
print "You need to install:"
|
||||
pprint.pprint(l_need_genealogy)
|
||||
else:
|
||||
print "Nothing to do."
|
||||
finalize()
|
||||
|
||||
if "ninja" in l_need_genealogy:
|
||||
|
||||
print """
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# I n s t a l l _ n i n j a #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
"""
|
||||
url = d_info["ninja"].url
|
||||
extension = splitext(url)[1]
|
||||
path_archive = "Downloads/{0}{1}".format("ninja", extension)
|
||||
|
||||
l_cmd = ["cd install &&",
|
||||
"wget {0} -O {1} -o /dev/null &&".format(url, path_archive),
|
||||
"./scripts/install_ninja.sh 2> /dev/null &&", "cd -"]
|
||||
|
||||
check_output(" ".join(l_cmd), shell=True)
|
||||
|
||||
print "Done"
|
||||
l_need_genealogy.remove("ninja")
|
||||
|
||||
print """
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# C r e a t i n g _ n i n j a #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
"""
|
||||
|
||||
|
||||
def create_rule():
|
||||
|
||||
l_rules = [
|
||||
"rule download", " command = wget ${url} -O ${out} -o /dev/null",
|
||||
" description = Downloading ${descr}", "", "rule install",
|
||||
" command = ./scripts/install_${target}.sh > _build/${target}.log 2>&1",
|
||||
" description = Installing ${descr}", ""
|
||||
]
|
||||
|
||||
return l_rules
|
||||
|
||||
l_string = create_rule()
|
||||
|
||||
l_build = []
|
||||
|
||||
for need in l_need_genealogy:
|
||||
|
||||
if need == "ocaml":
|
||||
continue
|
||||
|
||||
url = d_info[need].url
|
||||
extension = splitext(url)[1]
|
||||
|
||||
archive_path = "Downloads/{0}{1}".format(need, extension)
|
||||
|
||||
descr = d_info[need].description
|
||||
|
||||
# Build to dowload
|
||||
l_build += ["build {0}: download".format(archive_path),
|
||||
" url = {0}".format(url),
|
||||
" descr = {0}".format(descr), ""]
|
||||
|
||||
# Build to install
|
||||
l_dependancy = [d_info[i].default_path for i in d_dependency[need] if i in l_need_genealogy]
|
||||
|
||||
l_build += ["build {0}: install {1} {2}".format(d_info[need].default_path,
|
||||
archive_path,
|
||||
" ".join(l_dependancy)),
|
||||
" target = {0}".format(need),
|
||||
" descr = {0}".format(descr), ""]
|
||||
|
||||
l_string += l_build
|
||||
|
||||
path = join(QP_ROOT_INSTALL, "build.ninja")
|
||||
with open(path, "w+") as f:
|
||||
f.write("\n".join(l_string))
|
||||
|
||||
print "Done"
|
||||
print "You can check {0}".format(path)
|
||||
|
||||
print """
|
||||
# ~#~#~#~#~#~#~#~#~ #
|
||||
# R u n _ n i n j a #
|
||||
# ~#~#~#~#~#~#~#~#~ #
|
||||
"""
|
||||
|
||||
if [i for i in l_need_genealogy if i not in "ocaml"]:
|
||||
subprocess.check_call("ninja -C install", shell=True)
|
||||
|
||||
print "Done"
|
||||
|
||||
if "ocaml" in l_need_genealogy:
|
||||
|
||||
print """
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# I n s t a l l _ o c a m l #
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
"""
|
||||
url = d_info["ocaml"].url
|
||||
extension = splitext(url)[1]
|
||||
path_archive = "Downloads/{0}{1}".format("ocaml", extension)
|
||||
|
||||
l_cmd = ["cd install &&",
|
||||
"wget {0} -O {1} -o /dev/null &&".format(url, path_archive),
|
||||
"./scripts/install_ocaml.sh"]
|
||||
|
||||
os.system(" ".join(l_cmd))
|
||||
|
||||
print "Done"
|
||||
l_need_genealogy.remove("ocaml")
|
||||
|
||||
|
||||
print """
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# C r e a t e q u a n t u m _ p a c k a g e . r c
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
"""
|
||||
|
||||
python_path = [join(QP_ROOT, "scripts"), join(QP_ROOT, "install")]
|
||||
|
||||
l_python = [join(QP_ROOT, "scripts")]
|
||||
for dir_ in python_path:
|
||||
for folder in os.listdir(dir_):
|
||||
path = join(dir_, folder)
|
||||
if os.path.isdir(path):
|
||||
l_python.append(path)
|
||||
|
||||
|
||||
def find_path(bin_):
|
||||
try:
|
||||
locate = l_installed[bin_]
|
||||
except KeyError:
|
||||
locate = d_info[bin_].default_path
|
||||
return locate
|
||||
|
||||
|
||||
l_rc = [
|
||||
'export QP_ROOT={0}'.format(QP_ROOT),
|
||||
'export QP_EZFIO={0}'.format(find_path('ezfio')),
|
||||
'export IRPF90={0}'.format(find_path("irpf90")),
|
||||
'export NINJA={0}'.format(find_path("ninja")),
|
||||
'export QP_PYTHON={0}'.format(":".join(l_python)),
|
||||
"",
|
||||
'export PYTHONPATH="${PYTHONPATH}":"${QP_PYTHON}"',
|
||||
'export PATH="${PATH}":"${QP_PYTHON}":"${QP_ROOT}"/bin:"${QP_ROOT}"/ocaml',
|
||||
'export LD_LIBRARY_PATH="${QP_ROOT}"/lib:"${LD_LIBRARY_PATH}"',
|
||||
'export LIBRARY_PATH="${QP_ROOT}"/lib:"${LIBRARY_PATH}"', ""
|
||||
'source ${HOME}/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true',
|
||||
""
|
||||
]
|
||||
|
||||
path = join(QP_ROOT, "quantum_package.rc")
|
||||
with open(path, "w+") as f:
|
||||
f.write("\n".join(l_rc))
|
||||
|
||||
print "Done."
|
||||
finalize()
|
@ -589,7 +589,7 @@ Documentation
|
||||
If true, The One body DM is calculated with ignoring the Double<->Doubles extra diag elements
|
||||
|
||||
|
||||
`pouet <http://github.com/LCPQ/quantum_package/tree/master/src/Determinants/program_beginer_determinants.irp.f#L1>`_
|
||||
`pouet <http://github.com/LCPQ/quantum_package/tree/master/src/Determinants/program_initial_determinants.irp.f#L1>`_
|
||||
Undocumented
|
||||
|
||||
|
||||
@ -783,7 +783,7 @@ Documentation
|
||||
be set before calling this function.
|
||||
|
||||
|
||||
`routine <http://github.com/LCPQ/quantum_package/tree/master/src/Determinants/program_beginer_determinants.irp.f#L7>`_
|
||||
`routine <http://github.com/LCPQ/quantum_package/tree/master/src/Determinants/program_initial_determinants.irp.f#L7>`_
|
||||
Undocumented
|
||||
|
||||
|
||||
|
@ -20,3 +20,8 @@ default: Huckel
|
||||
type: double precision
|
||||
doc: Calculated HF energy
|
||||
interface: output
|
||||
|
||||
[energy_sdfsdf]
|
||||
type: double precision
|
||||
doc: Calculated HF energy
|
||||
interface: output
|
||||
|
Loading…
Reference in New Issue
Block a user