U á€C^»ã @sÖddlmZddlZddlZddlmZddlmZmZddl Z ddl m Z ddl m Z ddl mZejd d defd d defd d defdddefdddefd�ddd„ƒZdd„Zdd„Zd ¡Zd ¡Zd ¡ZdS) é)Úunicode_literalsN)ÚPath)ÚmsgÚ get_raw_inputé)Úpath2str)Úutil)ÚaboutzDirectory with model dataÚ positionalzOutput parent directoryzPath to meta.jsonÚoptionÚmz$Create meta.json, even if one existsÚflagÚcz4Force overwriting existing model in output directoryÚf)Ú input_dirÚ output_dirÚ meta_pathÚ create_metaÚforceFc CsÚt |¡}t |¡}t |¡}|r*| ¡s:tjd|dd�|rF| ¡sVtjd|dd�|rr| ¡srtjd|dd�|p||d}| ¡r®t |¡}|s¢t d|¡n t ||tƒ}dD].}||ksÊ||d kr²tjd   |¡d dd�q²|d d |d} | d|d} || } | | } |  ¡�rR|�r6t   t | ƒ¡ntjddj t | ƒd�dd�tj| dd�t  t |ƒt | | ƒ¡t| dtj|dd�ƒt| dtƒt| dtƒt| dtƒt d  | ¡| ¡t d¡dS)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)ÚlangÚnameÚversionÚz"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_pathÚexistsrÚfailÚis_fileÚsrslyÚ read_jsonZgoodÚ generate_metaÚformatÚshutilÚrmtreerrÚmkdirÚcopytreeÚ create_fileZ json_dumpsÚTEMPLATE_SETUPÚTEMPLATE_MANIFESTÚ TEMPLATE_INITÚtext) rrrrrZ input_pathZ output_pathÚmetaÚkeyZ model_nameZ model_name_vZ main_pathÚ package_path©r2ú4/tmp/pip-install-6_kvzl1k/spacy/spacy/cli/package.pyÚpackagesX         ý þûr4cCs | ¡|jddd� |¡dS)NÚwzutf-8)Úencoding)ZtouchÚopenÚwrite)Ú file_pathÚcontentsr2r2r3r*Psr*c Cs@|pi}dd| dd¡fdd| dd¡fdd| dd ¡fd d d tjfd d| d d¡fdd| dd¡fdd| dd¡fdd| dd¡fdd| dd¡fg }t t|ƒ¡}|j|d<|jjt |jj ƒ|jj j |jj j dœ|d<|  d¡| d¡|D]0\}}}t||ƒ} | dk�r|�r|n| ||<qôtjdk�r=%s,<3.0.0Ú descriptionzModel descriptionFÚauthorZAuthorÚemailz Author emailÚurlzAuthor websiteÚlicenseZLicensez CC BY-SA 3.0Zpipeline)ÚwidthÚvectorsÚkeysrrCzGenerating meta.jsonzzEnter the package settings for your model. The following information will be read from your model data: pipeline, vectors.rZspacyÚparent_package)Úgetr Ú __version__rZload_model_from_pathrZ pipe_namesZvocabZvectors_lengthÚlenrCZn_keysrÚdividerr.rÚ __title__) Z model_pathZ existing_metarr/ÚsettingsZnlpZsettingÚdescÚdefaultÚresponser2r2r3r$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 Ú annotationsÚstrÚboolr4r*r$Ústripr+r,r-r2r2r2r3Ús*          û :"D