<commit_before>"""
@file
@brief Customize a Windows Setup for these teachings
"""

import os
import shutil

from pyquickhelper import remove_folder


def last_function(innosetup, folders, verbose=False, fLOG=print):
    """
    applies last modifications to the setup

    @param          innosetup   innosetup script which defines the setup
    @param          folders     dictionary with keys *workspace*, *python*, *tools*, *build*, *docs*
    @param          verbose     verbose
    @param          fLOG        logging function
    """
    from pymyinstall import unzip_files
    from pymyinstall.win_installer.win_setup_r import r_run_script
    
    work = folders["workspace"]
    python = folders["python"]
    python = folders["tools"]
    build = os.path.join(folders["build"], "custom_ensae_teaching_cs")
    docs = os.path.join(work, "docs")
    logs = folders["logs"]
    this = os.path.abspath(os.path.dirname(__file__))
    doc_annee = [os.path.join(this, "..", "..", "..", "_doc", "notebooks", "td1a"),
                 os.path.join(
        this, "..", "..", "..", "_doc", "notebooks", "td2a"),
        os.path.join(
        this, "..", "..", "..", "_doc", "notebooks", "td3a"),
    ]

    if not os.path.exists(build):
        os.mkdir(build)

    # folders
    fLOG("folders:", folders)
    fLOG("innosetup:", innosetup)

    # docs
    fLOG("--- cleaning creating folder", docs)
    if os.path.exists(docs):
        remove_folder(docs)
    os.mkdir(docs)

    # R_install
    fLOG("--- R install")
    r_script = os.path.join(os.path.dirname(__file__), "R_install.r")
    if os.path.exists(r_script):
        r_run_script(os.path.join(tools, "R"), dest, os.path.join(
            logs, "r_ensae_teaching_cs.install.log.txt"))

    # documentation
    fLOG("--- documentation, TDs +++")
    for ipy in os.listdir(dist):
        if ipy.endswith("ipynb"):
            if verbose:
                fLOG("copy ", ipy)
            full = os.path.join(dist, ipy)
            shutil.copy(full, docs)

    # others packages not from Microsoft
    from pymyinstall import ModuleInstall
    from pymyinstall.win_installer.win_packages import win_install_package_other_python, is_package_installed

    # modules
    modules = [ModuleInstall("pyquickhelper", "pip"),
               ModuleInstall("pyensae", "pip"),
               ModuleInstall("pyrsslocal", "pip"),
               ModuleInstall("code_beatrix", "pip"),
               ModuleInstall("pymmails", "pip"),
               ModuleInstall("pymyinstall", "pip"),
               ModuleInstall("ensae_teaching_cs", "pip"),
               ModuleInstall("actuariat_python", "pip"),
               ]

    # new packages
    fLOG("--- download new packages")
    pack = []
    for mod in modules:
        mname = mod.mname if mod.mname is not None else mod.name<commit_msg>update setup<commit_after>"""
@file
@brief Customize a Windows Setup for these teachings
"""

import os
import shutil

from pyquickhelper import remove_folder


def last_function(innosetup, folders, verbose=False, fLOG=print):
    """
    applies last modifications to the setup

    @param          innosetup   innosetup script which defines the setup
    @param          folders     dictionary with keys *workspace*, *python*, *tools*, *build*, *docs*
    @param          verbose     verbose
    @param          fLOG        logging function
    """
    from pymyinstall import unzip_files
    from pymyinstall.win_installer.win_setup_r import r_run_script
    
    work = folders["workspace"]
    python = folders["python"]
    tools = folders["tools"]
    build = os.path.join(folders["build"], "custom_ensae_teaching_cs")
    docs = os.path.join(work, "docs")
    logs = folders["logs"]
    this = os.path.abspath(os.path.dirname(__file__))
    doc_annee = [os.path.join(this, "..", "..", "..", "_doc", "notebooks", "td1a"),
                 os.path.join(
        this, "..", "..", "..", "_doc", "notebooks", "td2a"),
        os.path.join(
        this, "..", "..", "..", "_doc", "notebooks", "td3a"),
    ]

    if not os.path.exists(build):
        os.mkdir(build)

    # folders
    fLOG("folders:", folders)
    fLOG("innosetup:", innosetup)

    # docs
    fLOG("--- cleaning creating folder", docs)
    if os.path.exists(docs):
        remove_folder(docs)
    os.mkdir(docs)

    # R_install
    fLOG("--- R install")
    r_script = os.path.join(os.path.dirname(__file__), "R_install.r")
    if os.path.exists(r_script):
        r_run_script(os.path.join(tools, "R"), dest, os.path.join(
            logs, "r_ensae_teaching_cs.install.log.txt"))

    # documentation
    fLOG("--- documentation, TDs +++")
    for dist in doc_annee:
        end = os.path.split(dist)[-1]
        to = os.path.join(docs, end)
        if not os.path.exists(to):
            os.mkdir(to)
        for ipy in os.listdir(dist):
            if ipy.endswith("ipynb"):
                if verbose:
                    fLOG("copy ", ipy)
                full = os.path.join(dist, ipy)
                shutil.copy(full, to)

    # others packages not from Microsoft
    from pymyinstall import ModuleInstall
    from pymyinstall.win_installer.win_packages import win_install_package_other_python, is_package_installed

    # modules
    modules = [ModuleInstall("pyquickhelper", "pip"),
               ModuleInstall("pyensae", "pip"),
               ModuleInstall("pyrsslocal", "pip"),
               ModuleInstall("code_beatrix", "pip"),
               ModuleInstall("pymmails", "pip"),
               ModuleInstall("pymyinstall", "pip"),
               ModuleInstall("ensae_teaching_cs", "pip"),
               ModuleInstall("actuariat_python", "pip"),
               ]

    # new packages
    fLOG("--- download new packages")
    pack = []
    for mod in modules:
        mname = mod.mname if mod.mname is not None else mod.name
{'fraction_non_alphanumeric': 0.13980150581793294, 'fraction_numerical': 0.0011978097193702942, 'mean_word_length': 2.404193360512522, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3516726', 'n_tokens_mistral': 1902, 'n_tokens_neox': 1802, 'n_words': 409}