<commit_before># -*- coding: utf-8 -*-

"""
scikit-ci-addons is a command line tool and a set of scripts useful to install
prerequisites for building Python extension on CI services.
"""

import os
import shutil
import sys

from subprocess import check_call

__author__ = 'The scikit-build team'
__email__ = '<EMAIL>'
__version__ = '0.5.0'


def addons():
    """Return all available addons."""

    addons = []

    for dirname, dirnames, filenames in os.walk(home()):

        for v in list(dirnames):
            dirnames.remove(v)
        dirnames += ['anyci', 'appveyor', 'circle', 'travis']

        if dirname == home():
            continue

        for filename in filenames:
            if filename in ['__init__.py']:
                continue
            addon_path = os.path.join(dirname, filename)
            addons.append(os.path.relpath(addon_path, home()))

    return addons


def home():
    """Return directory where all addons can be found."""
    return os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))


def path(addon_name):
    """Return path of ``addon_name``.

    This is particularly useful when the selected addon is not a python
    script and is expected to be used an input to an other tool."""

    addon_path = tmp_addon_path = os.path.join(home(), addon_name)
    if not os.path.exists(tmp_addon_path):
        tmp_addon_path += '.py'
    if not os.path.exists(tmp_addon_path):
        raise RuntimeError("Could not find addon: %s" % addon_path)
    return tmp_addon_path


def install(dst_path, force=False):
    """Copy addons into ``dst_path``.

    By default, existing addons are *NOT* overwritten. Specifying ``force``
    allow to overwrite them.
    """
    dst_path = os.path.normpath(os.path.abspath(dst_path))
    if dst_path == os.path.normpath(home()):
        print("skipping install: target directory already contains addons")
        exit()
    for addon in addons():
        dst_addon_path = os.path.join(dst_path, addon)
        dst_addon_dir = os.path.split(dst_addon_path)[0]
        if not os.path.exists(dst_addon_dir):
            os.makedirs(dst_addon_dir)
        src_addon_path = os.path.join(home(), addon)
        extra = ""
        do_copy = True
        if os.path.exists(dst_addon_path):
            extra = " (skipped)"
            do_copy = False
            if force:
                extra = " (overwritten)"
                do_copy = True
        if do_copy:
            shutil.copy(src_addon_path, dst_addon_path)
        print(dst_addon_path + extra)


def execute(addon_name, arguments=[]):
    """Execute ``addon_name`` with ``arguments``.

    Executable addons are python script.
    """
    cmd = [sys.executable, path(addon_name)] + arguments
    check_call(cmd)<commit_msg>ci_addons: Fix spelling of add-on(s) in docstrings<commit_after># -*- coding: utf-8 -*-

"""
scikit-ci-addons is a command line tool and a set of scripts useful to install
prerequisites for building Python extension on CI services.
"""

import os
import shutil
import sys

from subprocess import check_call

__author__ = 'The scikit-build team'
__email__ = '<EMAIL>'
__version__ = '0.5.0'


def addons():
    """Return all available add-ons."""

    addons = []

    for dirname, dirnames, filenames in os.walk(home()):

        for v in list(dirnames):
            dirnames.remove(v)
        dirnames += ['anyci', 'appveyor', 'circle', 'travis']

        if dirname == home():
            continue

        for filename in filenames:
            if filename in ['__init__.py']:
                continue
            addon_path = os.path.join(dirname, filename)
            addons.append(os.path.relpath(addon_path, home()))

    return addons


def home():
    """Return directory where all add-ons can be found."""
    return os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))


def path(addon_name):
    """Return path of ``addon_name``.

    This is particularly useful when the selected add-on is not a python
    script and is expected to be used an input to an other tool."""

    addon_path = tmp_addon_path = os.path.join(home(), addon_name)
    if not os.path.exists(tmp_addon_path):
        tmp_addon_path += '.py'
    if not os.path.exists(tmp_addon_path):
        raise RuntimeError("Could not find addon: %s" % addon_path)
    return tmp_addon_path


def install(dst_path, force=False):
    """Copy add-ons into ``dst_path``.

    By default, existing add-ons are *NOT* overwritten. Specifying ``force``
    allow to overwrite them.
    """
    dst_path = os.path.normpath(os.path.abspath(dst_path))
    if dst_path == os.path.normpath(home()):
        print("skipping install: target directory already contains addons")
        exit()
    for addon in addons():
        dst_addon_path = os.path.join(dst_path, addon)
        dst_addon_dir = os.path.split(dst_addon_path)[0]
        if not os.path.exists(dst_addon_dir):
            os.makedirs(dst_addon_dir)
        src_addon_path = os.path.join(home(), addon)
        extra = ""
        do_copy = True
        if os.path.exists(dst_addon_path):
            extra = " (skipped)"
            do_copy = False
            if force:
                extra = " (overwritten)"
                do_copy = True
        if do_copy:
            shutil.copy(src_addon_path, dst_addon_path)
        print(dst_addon_path + extra)


def execute(addon_name, arguments=[]):
    """Execute ``addon_name`` with ``arguments``.

    Executable add-ons are python script.
    """
    cmd = [sys.executable, path(addon_name)] + arguments
    check_call(cmd)
{'fraction_non_alphanumeric': 0.11762596377980994, 'fraction_numerical': 0.0017930787161556392, 'mean_word_length': 2.626788036410923, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2058309', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1769, 'n_words': 479}