Esempio n. 1
0
def install(path=None, force=False, code=True, no_progress_bars=False, **kwargs):
    log = logging.getLogger(__name__.split(".")[-1])
    if not code:
        log.info("Code not requested. Nothing to do.")
        return True
    log.info("Installing pre-requisites...")
    exit_status = pip_install("cython")
    if exit_status:
        log.error("Could not install pre-requisite: cython")
        return False
    log.info("Downloading classy...")
    success = download_github_release(
        os.path.join(path, "code"), classy_repo_name, classy_repo_version,
        repo_rename=classy_repo_rename, no_progress_bars=no_progress_bars)
    if not success:
        log.error("Could not download classy.")
        return False
    classy_path = os.path.join(path, "code", classy_repo_rename)
    log.info("Compiling classy...")
    from subprocess import Popen, PIPE
    process_make = Popen(["make"], cwd=classy_path, stdout=PIPE, stderr=PIPE)
    out, err = process_make.communicate()
    if process_make.returncode:
        log.info(out)
        log.info(err)
        log.error("Compilation failed!")
        return False
    return True
Esempio n. 2
0
def install_clik(path, no_progress_bars=False):
    log = get_logger("clik")
    log.info("Installing pre-requisites...")
    for req in ("cython", "astropy"):
        exit_status = pip_install(req)
        if exit_status:
            raise LoggedError(log, "Failed installing '%s'.", req)
    log.info("Downloading...")
    click_url = pla_url_prefix + '152000'
    if not download_file(click_url,
                         path,
                         decompress=True,
                         no_progress_bars=no_progress_bars,
                         logger=log):
        log.error("Not possible to download clik.")
        return False
    source_dir = get_clik_source_folder(path)
    log.info('Installing from directory %s' % source_dir)
    cwd = os.getcwd()
    try:
        os.chdir(source_dir)
        log.info("Configuring... (and maybe installing dependencies...)")
        flags = ["--install_all_deps", "--extra_lib=m"
                 ]  # missing for some reason in some systems, but harmless
        if not execute([sys.executable, "waf", "configure"] + flags):
            log.error("Configuration failed!")
            return False
        log.info("Compiling...")
        if not execute([sys.executable, "waf", "install"]):
            log.error("Compilation failed!")
            return False
    finally:
        os.chdir(cwd)
    log.info("Finished!")
    return True
Esempio n. 3
0
 def install(cls, path=None, force=False, code=True, no_progress_bars=False, **kwargs):
     log = logging.getLogger(cls.__name__)
     if not code:
         log.info("Code not requested. Nothing to do.")
         return True
     log.info("Installing pre-requisites...")
     exit_status = pip_install("cython")
     if exit_status:
         log.error("Could not install pre-requisite: cython")
         return False
     log.info("Downloading classy...")
     success = download_github_release(
         os.path.join(path, "code"), cls.classy_repo_name, cls.classy_repo_version,
         repo_rename=cls.__name__, no_progress_bars=no_progress_bars, logger=log)
     if not success:
         log.error("Could not download classy.")
         return False
     classy_path = cls.get_path(path)
     log.info("Compiling classy...")
     from subprocess import Popen, PIPE
     env = deepcopy(os.environ)
     env.update({"PYTHON": sys.executable})
     process_make = Popen(["make"], cwd=classy_path, stdout=PIPE, stderr=PIPE, env=env)
     out, err = process_make.communicate()
     if process_make.returncode:
         log.info(out)
         log.info(err)
         log.error("Compilation failed!")
         return False
     return True
Esempio n. 4
0
 def install(cls,
             path=None,
             force=False,
             code=True,
             no_progress_bars=False,
             **kwargs):
     log = logging.getLogger(cls.__name__)
     if not code:
         log.info("Code not requested. Nothing to do.")
         return True
     log.info("Installing pre-requisites...")
     exit_status = pip_install("cython")
     if exit_status:
         log.error("Could not install pre-requisite: cython")
         return False
     log.info("Downloading classy...")
     success = download_github_release(os.path.join(path, "code"),
                                       cls._classy_repo_name,
                                       cls._classy_repo_version,
                                       repo_rename=cls.__name__,
                                       no_progress_bars=no_progress_bars,
                                       logger=log)
     if not success:
         log.error("Could not download classy.")
         return False
     # Compilation
     # gcc check after downloading, in case the user wants to change the compiler by
     # hand in the Makefile
     classy_path = cls.get_path(path)
     if not check_gcc_version(cls._classy_min_gcc_version,
                              error_returns=False):
         log.error(
             "Your gcc version is too low! CLASS would probably compile, "
             "but it would leak memory when running a chain. Please use a "
             "gcc version newer than %s. You can still compile CLASS by hand, "
             "maybe changing the compiler in the Makefile. CLASS has been "
             "downloaded into %r", cls._classy_min_gcc_version, classy_path)
         return False
     log.info("Compiling classy...")
     from subprocess import Popen, PIPE
     env = deepcopy(os.environ)
     env.update({"PYTHON": sys.executable})
     process_make = Popen(["make"],
                          cwd=classy_path,
                          stdout=PIPE,
                          stderr=PIPE,
                          env=env)
     out, err = process_make.communicate()
     if process_make.returncode:
         log.info(out)
         log.info(err)
         log.error("Compilation failed!")
         return False
     return True
Esempio n. 5
0
def install_clik(path, no_progress_bars=False):
    log = logging.getLogger("clik")
    log.info("Installing pre-requisites...")
    for req in ("cython", "astropy"):
        exit_status = pip_install(req)
        if exit_status:
            raise LoggedError(log, "Failed installing '%s'.", req)
    log.info("Downloading...")
    click_url = pla_url_prefix + '151912'
    if not download_file(click_url,
                         path,
                         decompress=True,
                         no_progress_bars=no_progress_bars,
                         logger=log):
        log.error("Not possible to download clik.")
        return False
    source_dir = get_clik_source_folder(path)
    log.info('Installing from directory %s' % source_dir)
    # The following code patches a problem with the download source of cfitsio.
    # Left here in case the FTP server breaks again.
    if True:  # should be fixed: maybe a ping to the FTP server???
        log.info("Patching origin of cfitsio")
        cfitsio_filename = os.path.join(source_dir, "waf_tools", "cfitsio.py")
        with open(cfitsio_filename, "r") as cfitsio_file:
            lines = cfitsio_file.readlines()
            i_offending = next(i for i, l in enumerate(lines)
                               if ".tar.gz" in l)
            lines[i_offending] = lines[i_offending].replace(
                "ftp://heasarc.gsfc.nasa.gov/software/fitsio/c/cfitsio3280.tar.gz",
                "https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio3280.tar.gz"
            )
        with open(cfitsio_filename, "w") as cfitsio_file:
            cfitsio_file.write("".join(lines))
    cwd = os.getcwd()
    try:
        os.chdir(source_dir)
        log.info("Configuring... (and maybe installing dependencies...)")
        flags = ["--install_all_deps", "--extra_lib=m"
                 ]  # missing for some reason in some systems, but harmless
        if not execute([sys.executable, "waf", "configure"] + flags):
            log.error("Configuration failed!")
            return False
        log.info("Compiling...")
        if not execute([sys.executable, "waf", "install"]):
            log.error("Compilation failed!")
            return False
    finally:
        os.chdir(cwd)
    log.info("Finished!")
    return True
def install_clik(path, no_progress_bars=False):
    log = logging.getLogger("clik")
    log.info("Installing pre-requisites...")
    for req in ("cython", "astropy"):
        exit_status = pip_install(req)
        if exit_status:
            log.error("Failed installing '%s'.", req)
            raise HandledException
    log.info("Downloading...")
    click_url = 'https://cdn.cosmologist.info/cosmobox/plc-2.1_py3.tar.bz2'
    if not download_file(click_url, path, decompress=True,
                         no_progress_bars=no_progress_bars, logger=log):
        log.error("Not possible to download clik.")
        return False
    source_dir = os.path.join(path, os.listdir(path)[0])
    log.info('Installing from directory %s' % source_dir)
    if True:  # should be fixed
        log.info("Patching origin of cfitsio")
        cfitsio_filename = os.path.join(source_dir, "waf_tools", "cfitsio.py")
        with open(cfitsio_filename, "r") as cfitsio_file:
            lines = cfitsio_file.readlines()
            i_offending = next(i for i, l in enumerate(lines) if ".tar.gz" in l)
            lines[i_offending] = (
                "  atl.installsmthg_pre(ctx,"
                "'http://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio3280.tar.gz',"
                "'cfitsio3280.tar.gz')\n")
        with open(cfitsio_filename, "w") as cfitsio_file:
            cfitsio_file.write("".join(lines))
    cwd = os.getcwd()
    try:
        os.chdir(source_dir)
        log.info("Configuring... (and maybe installing dependencies...)")
        if not execute([sys.executable, "waf", "configure", "--install_all_deps"]):
            log.error("Configuration failed!")
            return False

        log.info("Compiling...")
        if not execute([sys.executable, "waf", "install"]):
            log.error("Compilation failed!")
            return False
    finally:
        os.chdir(cwd)
    log.info("Finished!")
    return True
Esempio n. 7
0
def install_clik(path, no_progress_bars=False):
    log = logging.getLogger("clik")
    # Checking gcc < 6
    from subprocess import Popen, PIPE
    process = Popen(["gcc", "-v"], stdout=PIPE, stderr=PIPE)
    out, err = process.communicate()
    prefix = "gcc version"
    try:
        version = [line for line in err.split("\n") if line.startswith(prefix)]
        version = version[0][len(prefix):].split()[0]
        major = version.split(".")[0]
        if int(major) > 5:
            log.error(
                "GCC version > 5: unfortunately, the Planck likelihood won't work!"
            )
            return False
    except:
        log.error(
            "Could not identify the GCC version. Notice that the Planck likelihood "
            "works for GCC <= 5 only.")
    for req in ("cython", "pyfits"):
        from importlib import import_module
        try:
            import_module(req)
        except ImportError:
            log.info("clik: installing requisite '%s'...", req)
            exit_status = pip_install(req)
            if exit_status:
                log.error("Failed installing requisite '%s'.", req)
                raise HandledException
    log.info("clik: downlowading...")
    if not download_from_planck(
            "1904", path, no_progress_bars=no_progress_bars, name="clik"):
        log.error("Not possible to download clik.")
        return False
    log.info("clik: patching origin of cfitsio")
    cfitsio_filename = os.path.join(path, "plc-2.0/waf_tools/cfitsio.py")
    with open(cfitsio_filename, "r") as cfitsio_file:
        lines = cfitsio_file.readlines()
        i_offending = next(i for i, l in enumerate(lines) if ".tar.gz" in l)
        lines[i_offending] = (
            "  atl.installsmthg_pre(ctx,"
            "'http://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio3280.tar.gz',"
            "'cfitsio3280.tar.gz')\n")
    with open(cfitsio_filename, "w") as cfitsio_file:
        cfitsio_file.write("".join(lines))
    log.info("clik: configuring... (and maybe installing dependencies...)")
    cwd = os.getcwd()
    os.chdir(os.path.join(path, "plc-2.0"))
    try:
        process = Popen(["./waf", "configure", "--install_all_deps"],
                        stdout=PIPE,
                        stderr=PIPE)
        out, err = process.communicate()
        if err or not out.split("\n")[-2].startswith(
                "'configure' finished successfully"):
            print(out)
            print(err)
            log.error("Configuration failed!")
            return False
        log.info("clik: compiling...")
        process2 = Popen(["./waf", "install"], stdout=PIPE, stderr=PIPE)
        out2, err2 = process2.communicate()
        # We don't check that err2" is empty, because harmless warnings are included there.
        if not out2.split("\n")[-2].startswith(
                "'install' finished successfully"):
            print(out2)
            print(err2)
            log.error("Compilation failed!")
            return False
    finally:
        os.chdir(cwd)
    log.info("clik: finished!")
    return True