2
2
from __future__ import unicode_literals
3
3
4
4
import plac
5
- < << << << HEAD
6
- import os
7
- import subprocess
8
- import sys
9
- import ujson
10
-
11
- from .link import link
12
- from ._messages import Messages
13
- from ..util import prints , get_package_path
14
- from ..compat import url_read , HTTPError
15
- == == == =
16
5
import requests
17
6
import os
18
7
import subprocess
21
10
from ._messages import Messages
22
11
from .link import link
23
12
from ..util import prints , get_package_path
24
- > >> >> >> 14 d9007efd2ca457c6e6549d5599e460e198904c
25
13
from .. import about
26
14
27
15
28
16
@plac .annotations (
29
17
model = ("model to download, shortcut or name)" , "positional" , None , str ),
30
18
direct = ("force direct download. Needs model name with version and won't "
31
- << < << << HEAD
32
- "perform compatibility check" , "flag" , "d" , bool ))
33
- def download (model , direct = False ):
34
- == == == =
35
19
"perform compatibility check" , "flag" , "d" , bool ),
36
20
pip_args = ("additional arguments to be passed to `pip install` when "
37
21
"installing the model" ))
38
22
def download (model , direct = False , * pip_args ):
39
- > >> >> >> 14 d9007efd2ca457c6e6549d5599e460e198904c
40
23
"""
41
24
Download compatible model from default download path using pip. Model
42
25
can be shortcut, model name or, if --direct flag is set, full model name
43
26
with version.
44
27
"""
45
28
if direct :
46
- < << << << HEAD
47
- dl = download_model ('{m}/{m}.tar.gz' .format (m = model ))
48
- == == == =
49
29
dl = download_model ('{m}/{m}.tar.gz#egg={m}' .format (m = model ), pip_args )
50
- >> >> >> > 14 d9007efd2ca457c6e6549d5599e460e198904c
51
30
else :
52
31
shortcuts = get_json (about .__shortcuts__ , "available shortcuts" )
53
32
model_name = shortcuts .get (model , model )
54
33
compatibility = get_compatibility ()
55
34
version = get_version (model_name , compatibility )
56
- < << << << HEAD
57
- dl = download_model ('{m}-{v}/{m}-{v}.tar.gz' .format (m = model_name ,
58
- v = version ))
59
- == == == =
60
35
dl = download_model ('{m}-{v}/{m}-{v}.tar.gz#egg={m}=={v}'
61
36
.format (m = model_name , v = version ), pip_args )
62
- >> >> >> > 14 d9007efd2ca457c6e6549d5599e460e198904c
63
37
if dl != 0 : # if download subprocess doesn't return 0, exit
64
38
sys .exit (dl )
65
39
try :
@@ -68,12 +42,7 @@ def download(model, direct=False, *pip_args):
68
42
# package, which fails if model was just installed via
69
43
# subprocess
70
44
package_path = get_package_path (model_name )
71
- << << << < HEAD
72
- link (model_name , model , force = True ,
73
- model_path = package_path )
74
- == == == =
75
45
link (model_name , model , force = True , model_path = package_path )
76
- >> >> >> > 14 d9007efd2ca457c6e6549d5599e460e198904c
77
46
except :
78
47
# Dirty, but since spacy.download and the auto-linking is
79
48
# mostly a convenience wrapper, it's best to show a success
@@ -82,20 +51,11 @@ def download(model, direct=False, *pip_args):
82
51
83
52
84
53
def get_json (url , desc ):
85
- << << << < HEAD
86
- try :
87
- data = url_read (url )
88
- except HTTPError as e :
89
- prints (Messages .M004 .format (desc , about .__version__ ),
90
- title = Messages .M003 .format (e .code , e .reason ), exits = 1 )
91
- return ujson .loads (data )
92
- == == == =
93
54
r = requests .get (url )
94
55
if r .status_code != 200 :
95
56
prints (Messages .M004 .format (desc = desc , version = about .__version__ ),
96
57
title = Messages .M003 .format (code = r .status_code ), exits = 1 )
97
58
return r .json ()
98
- >> >> >> > 14 d9007efd2ca457c6e6549d5599e460e198904c
99
59
100
60
101
61
def get_compatibility ():
@@ -117,18 +77,10 @@ def get_version(model, comp):
117
77
return comp [model ][0 ]
118
78
119
79
120
- < << << << HEAD
121
- def download_model (filename ):
122
- download_url = about .__download_url__ + '/' + filename
123
- return subprocess .call (
124
- [sys .executable , '-m' , 'pip' , 'install' , '--no-cache-dir' , '--no-deps' ,
125
- download_url ], env = os .environ .copy ())
126
- == == == =
127
80
def download_model (filename , user_pip_args = None ):
128
81
download_url = about .__download_url__ + '/' + filename
129
82
pip_args = ['--no-cache-dir' , '--no-deps' ]
130
83
if user_pip_args :
131
84
pip_args .extend (user_pip_args )
132
85
cmd = [sys .executable , '-m' , 'pip' , 'install' ] + pip_args + [download_url ]
133
86
return subprocess .call (cmd , env = os .environ .copy ())
134
- > >> >> >> 14 d9007efd2ca457c6e6549d5599e460e198904c
0 commit comments