<commit_before># coding: utf8
from __future__ import unicode_literals

import json
import shutil
from pathlib import Path

from .. import about
from .. import util


def package(input_dir, output_dir, force):
    input_path = Path(input_dir)
    output_path = Path(output_dir)
    check_dirs(input_path, output_path)

    meta = generate_meta()
    model_name = meta['lang'] + '_' + meta['name']
    model_name_v = model_name + '-' + meta['version']
    main_path = output_path / model_name_v
    package_path = main_path / model_name

    Path.mkdir(package_path, parents=True)
    shutil.copytree(input_path, package_path / model_name_v)
    create_file(main_path / 'meta.json', json.dumps(meta, indent=2))
    create_file(main_path / 'setup.py', TEMPLATE_SETUP.strip())
    create_file(main_path / 'MANIFEST.in', TEMPLATE_MANIFEST.strip())
    create_file(package_path / '__init__.py', TEMPLATE_INIT.strip())

    util.print_msg(
        main_path.as_posix(),
        "To build the package, run python setup.py sdist in that directory.",
        title="Successfully created package {p}".format(p=model_name_v))


def check_dirs(input_path, output_path):
    if not input_path.exists():
        util.sys_exit(input_path.as_poisx(), title="Model directory not found")
    if not output_path.exists():
        util.sys_exit(output_path.as_posix(), title="Output directory not found")


def create_file(file_path, contents):
    file_path.touch()
    file_path.write_text(contents, encoding='utf-8')


def generate_meta():
    settings = [('lang', 'Model language', 'en'),
                ('name', 'Model name', 'model'),
                ('version', 'Model version', '0.0.0'),
                ('spacy_version', 'Required spaCy version', '>=2.0.0,<3.0.0'),
                ('description', 'Model description', False),<commit_msg>Move directory check and overwriting/creating dirs to own function<commit_after># coding: utf8
from __future__ import unicode_literals

import json
import shutil
from pathlib import Path

from .. import about
from .. import util


def package(input_dir, output_dir, force):
    input_path = Path(input_dir)
    output_path = Path(output_dir)
    check_dirs(input_path, output_path)

    meta = generate_meta()
    model_name = meta['lang'] + '_' + meta['name']
    model_name_v = model_name + '-' + meta['version']
    main_path = output_path / model_name_v
    package_path = main_path / model_name

    create_dirs(package_path, force)
    shutil.copytree(input_path, package_path / model_name_v)
    create_file(main_path / 'meta.json', json.dumps(meta, indent=2))
    create_file(main_path / 'setup.py', TEMPLATE_SETUP.strip())
    create_file(main_path / 'MANIFEST.in', TEMPLATE_MANIFEST.strip())
    create_file(package_path / '__init__.py', TEMPLATE_INIT.strip())

    util.print_msg(
        main_path.as_posix(),
        "To build the package, run python setup.py sdist in that directory.",
        title="Successfully created package {p}".format(p=model_name_v))


def check_dirs(input_path, output_path):
    if not input_path.exists():
        util.sys_exit(input_path.as_poisx(), title="Model directory not found")
    if not output_path.exists():
        util.sys_exit(output_path.as_posix(), title="Output directory not found")


def create_dirs(package_path, force):
    if package_path.exists():
        if force:
            shutil.rmtree(package_path)
        else:
            util.sys_exit(package_path.as_posix(),
                "Please delete the directory and try again.",
                title="Package directory already exists")
    Path.mkdir(package_path, parents=True)


def create_file(file_path, contents):
    file_path.touch()
    file_path.write_text(contents, encoding='utf-8')


def generate_meta():
    settings = [('lang', 'Model language', 'en'),
                ('name', 'Model name', 'model'),
                ('version', 'Model version', '0.0.0'),
                ('spacy_version', 'Required spaCy version', '>=2.0.0,<3.0.0'),
                ('description', 'Model description', False),
{'fraction_non_alphanumeric': 0.1269410894749815, 'fraction_numerical': 0.005915701257086517, 'mean_word_length': 3.508888888888889, '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': '7208326', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1281, 'n_words': 288}