U C^ @sddlmZddlZddlZddlmZddlmZmZddl Z ddl m Z ddl m Z ddl mZejd d defd d defd d defdddefdddefddddZddZddZdZdZdZdS) )unicode_literalsN)Path)msg get_raw_input)path2str)util)aboutzDirectory with model data positionalzOutput parent directoryzPath to meta.jsonoptionmz$Create meta.json, even if one existsflagcz4Force overwriting existing model in output directoryf) input_dir output_dir meta_path create_metaforceFc Cst|}t|}t|}|r*|s:tjd|dd|rF|sVtjd|dd|rr|srtjd|dd|p||d}|rt|}|std|n t ||t}dD].}||ks||d krtjd |d ddq|d d |d} | d|d} || } | | } | rR|r6t t | ntjddj t | dddtj| ddt t |t | | t| dtj|ddt| dtt| dtt| dttd | | tddS)au Generate Python package for model data, including meta and required installation files. A new directory will be created in the specified output directory, and model data will be copied over. If --create-meta is set and a meta.json already exists in the output directory, the existing values will be used as the defaults in the command-line prompt. zCan't locate model data)ZexitszOutput directory not foundzCan't find model meta.jsonz meta.jsonzLoaded meta.json from file)langnameversionz"No '{}' setting found in meta.jsonz/This setting is required to build your package.r_r-rz Package directory already existszgPlease delete the directory and try again, or use the `--force` flag to overwrite existing directories.)pathT)parentsr)indentzsetup.pyz MANIFEST.inz __init__.pyz!Successfully created package '{}'zDTo build the package, run `python setup.py sdist` in this directory.N)rZ ensure_pathexistsrfailis_filesrsly read_jsonZgood generate_metaformatshutilrmtreerrmkdircopytree create_fileZ json_dumpsTEMPLATE_SETUPTEMPLATE_MANIFEST TEMPLATE_INITtext) rrrrrZ input_pathZ output_pathmetakeyZ model_nameZ model_name_vZ main_path package_pathr24/tmp/pip-install-6_kvzl1k/spacy/spacy/cli/package.pypackagesX          r4cCs ||jddd|dS)Nwzutf-8)encoding)Ztouchopenwrite) file_pathcontentsr2r2r3r*Psr*c Cs@|pi}dd|ddfdd|ddfdd|dd fd d d tjfd d|d dfdd|ddfdd|ddfdd|ddfdd|ddfg }tt|}|j|d<|jjt |jj |jj j |jj j d|d<| d|d|D]0\}}}t||} | dkr|r|n| ||<qtjdkr=%s,<3.0.0 descriptionzModel descriptionFauthorZAuthoremailz Author emailurlzAuthor websitelicenseZLicensez CC BY-SA 3.0Zpipeline)widthvectorskeysrrCzGenerating meta.jsonzzEnter the package settings for your model. The following information will be read from your model data: pipeline, vectors.rZspacyparent_package)getr __version__rZload_model_from_pathrZ pipe_namesZvocabZvectors_lengthlenrCZn_keysrdividerr.r __title__) Z model_pathZ existing_metarr/settingsZnlpZsettingdescdefaultresponser2r2r3r$Us8        r$a #!/usr/bin/env python # coding: utf8 from __future__ import unicode_literals import io import json from os import path, walk from shutil import copy from setuptools import setup def load_meta(fp): with io.open(fp, encoding='utf8') as f: return json.load(f) def list_files(data_dir): output = [] for root, _, filenames in walk(data_dir): for filename in filenames: if not filename.startswith('.'): output.append(path.join(root, filename)) output = [path.relpath(p, path.dirname(data_dir)) for p in output] output.append('meta.json') return output def list_requirements(meta): parent_package = meta.get('parent_package', 'spacy') requirements = [parent_package + meta['spacy_version']] if 'setup_requires' in meta: requirements += meta['setup_requires'] if 'requirements' in meta: requirements += meta['requirements'] return requirements def setup_package(): root = path.abspath(path.dirname(__file__)) meta_path = path.join(root, 'meta.json') meta = load_meta(meta_path) model_name = str(meta['lang'] + '_' + meta['name']) model_dir = path.join(model_name, model_name + '-' + meta['version']) copy(meta_path, path.join(model_name)) copy(meta_path, model_dir) setup( name=model_name, description=meta['description'], author=meta['author'], author_email=meta['email'], url=meta['url'], version=meta['version'], license=meta['license'], packages=[model_name], package_data={model_name: list_files(model_dir)}, install_requires=list_requirements(meta), zip_safe=False, ) if __name__ == '__main__': setup_package() z include meta.json a% # coding: utf8 from __future__ import unicode_literals from pathlib import Path from spacy.util import load_model_from_init_py, get_model_meta __version__ = get_model_meta(Path(__file__).parent)['version'] def load(**overrides): return load_model_from_init_py(__file__, **overrides) )NFF) __future__rZplacr&pathlibrZwasabirrr"compatrrrr annotationsstrboolr4r*r$stripr+r,r-r2r2r2r3s*           :"D