34
34
from ConfigParser import SafeConfigParser as ConfigParser
35
35
# noinspection PyCompatibility
36
36
import urllib2
37
+
37
38
iteritems = operator .methodcaller ('iteritems' )
38
39
import httplib
40
+
39
41
IncompleteRead = httplib .IncompleteRead
40
42
except ImportError : # pragma: no cover (py3 only)
41
43
from configparser import ConfigParser
42
44
# noinspection PyUnresolvedReferences
43
45
import urllib .request as urllib2
46
+
44
47
iteritems = operator .methodcaller ('items' )
45
48
import http
49
+
46
50
IncompleteRead = http .client .IncompleteRead
47
51
48
52
from pkg_resources import parse_version
59
63
60
64
ignore_ssl_certs = False
61
65
66
+
62
67
# ---------------------------------------------------------
63
68
# Utils
64
69
@@ -69,19 +74,19 @@ def to_utf8(text):
69
74
if not text or is_PY3 :
70
75
return text
71
76
72
- try : # unicode or pure ascii
77
+ try : # unicode or pure ascii
73
78
return text .encode ("utf8" )
74
79
except UnicodeDecodeError :
75
- try : # successful UTF-8 decode means it's pretty sure UTF-8
80
+ try : # successful UTF-8 decode means it's pretty sure UTF-8
76
81
text .decode ("utf8" )
77
82
return text
78
83
except UnicodeDecodeError :
79
- try : # get desperate; and yes, this has a western hemisphere bias
84
+ try : # get desperate; and yes, this has a western hemisphere bias
80
85
return text .decode ("cp1252" ).encode ("utf8" )
81
86
except UnicodeDecodeError :
82
87
pass
83
88
84
- return text # return unchanged, hope for the best
89
+ return text # return unchanged, hope for the best
85
90
86
91
87
92
class Config (object ):
@@ -120,7 +125,7 @@ def _load(cls, configfiles, verbose=False):
120
125
121
126
for attr , val in iteritems (vars (cls )):
122
127
if attr .startswith ('_' ) or not \
123
- ini_file .has_option (section , attr ):
128
+ ini_file .has_option (section , attr ):
124
129
continue
125
130
126
131
if isinstance (val , bool ):
@@ -133,6 +138,10 @@ def _load(cls, configfiles, verbose=False):
133
138
os .path .basename (configfile ), attr , val ))
134
139
setattr (cls , attr , val )
135
140
141
+ if os .path .exists (".node-version" ):
142
+ with open (".node-version" , "r" ) as v_file :
143
+ setattr (cls , "node" , v_file .readlines (1 )[0 ].strip ())
144
+
136
145
@classmethod
137
146
def _dump (cls ):
138
147
"""
@@ -190,6 +199,7 @@ def emit(self, record):
190
199
fs = "%s" if getattr (record , "continued" , False ) else "%s\n "
191
200
self .stream .write (fs % to_utf8 (msg ))
192
201
self .flush ()
202
+
193
203
logging .StreamHandler .emit = emit
194
204
195
205
# create console handler and set level to debug
@@ -223,11 +233,11 @@ def parse_args(check=True):
223
233
parser .add_option (
224
234
'-n' , '--node' , dest = 'node' , metavar = 'NODE_VER' , default = Config .node ,
225
235
help = 'The node.js version to use, e.g., '
226
- '--node=0.4.3 will use the node-v0.4.3 '
227
- 'to create the new environment. '
228
- 'The default is last stable version (`latest`). '
229
- 'Use `lts` to use the latest LTS release. '
230
- 'Use `system` to use system-wide node.' )
236
+ '--node=0.4.3 will use the node-v0.4.3 '
237
+ 'to create the new environment. '
238
+ 'The default is the version specified in `.node-version` if exists, or last stable version (`latest`). '
239
+ 'Use `lts` to use the latest LTS release. '
240
+ 'Use `system` to use system-wide node.' )
231
241
232
242
parser .add_option (
233
243
'--mirror' ,
@@ -238,12 +248,12 @@ def parse_args(check=True):
238
248
parser .add_option (
239
249
'-j' , '--jobs' , dest = 'jobs' , default = Config .jobs ,
240
250
help = 'Sets number of parallel commands at node.js compilation. '
241
- 'The default is 2 jobs.' )
251
+ 'The default is 2 jobs.' )
242
252
243
253
parser .add_option (
244
254
'--load-average' , dest = 'load_average' ,
245
255
help = 'Sets maximum load average for executing parallel commands '
246
- 'at node.js compilation.' )
256
+ 'at node.js compilation.' )
247
257
248
258
parser .add_option (
249
259
'--without-ssl' , dest = 'without_ssl' ,
@@ -284,7 +294,7 @@ def parse_args(check=True):
284
294
parser .add_option (
285
295
'-C' , '--config-file' , dest = 'config_file' , default = None ,
286
296
help = "Load a different file than '~/.nodeenvrc'. "
287
- "Pass an empty string for no config (use built-in defaults)." )
297
+ "Pass an empty string for no config (use built-in defaults)." )
288
298
289
299
parser .add_option (
290
300
'-r' , '--requirements' ,
@@ -309,16 +319,16 @@ def parse_args(check=True):
309
319
'--with-npm' , dest = 'with_npm' ,
310
320
action = 'store_true' , default = Config .with_npm ,
311
321
help = 'Build without installing npm into the new virtual environment. '
312
- 'Required for node.js < 0.6.3. By default, the npm included with '
313
- 'node.js is used. Under Windows, this defaults to true.' )
322
+ 'Required for node.js < 0.6.3. By default, the npm included with '
323
+ 'node.js is used. Under Windows, this defaults to true.' )
314
324
315
325
parser .add_option (
316
326
'--npm' , dest = 'npm' ,
317
327
metavar = 'NPM_VER' , default = Config .npm ,
318
328
help = 'The npm version to use, e.g., '
319
- '--npm=0.3.18 will use the npm-0.3.18.tgz '
320
- 'tarball to install. '
321
- 'The default is last available version (`latest`).' )
329
+ '--npm=0.3.18 will use the npm-0.3.18.tgz '
330
+ 'tarball to install. '
331
+ 'The default is last available version (`latest`).' )
322
332
323
333
parser .add_option (
324
334
'--no-npm-clean' , dest = 'no_npm_clean' ,
@@ -516,21 +526,21 @@ def is_x86_64_musl():
516
526
517
527
def get_node_bin_url (version ):
518
528
archmap = {
519
- 'x86' : 'x86' , # Windows Vista 32
520
- 'i686' : 'x86' ,
529
+ 'x86' : 'x86' , # Windows Vista 32
530
+ 'i686' : 'x86' ,
521
531
'x86_64' : 'x64' , # Linux Ubuntu 64
522
- 'amd64' : 'x64' , # FreeBSD 64bits
523
- 'AMD64' : 'x64' , # Windows Server 2012 R2 (x64)
524
- 'armv6l' : 'armv6l' , # arm
532
+ 'amd64' : 'x64' , # FreeBSD 64bits
533
+ 'AMD64' : 'x64' , # Windows Server 2012 R2 (x64)
534
+ 'armv6l' : 'armv6l' , # arm
525
535
'armv7l' : 'armv7l' ,
526
536
'armv8l' : 'armv7l' ,
527
537
'aarch64' : 'arm64' ,
528
538
'arm64' : 'arm64' ,
529
539
'arm64/v8' : 'arm64' ,
530
540
'armv8' : 'arm64' ,
531
541
'armv8.4' : 'arm64' ,
532
- 'ppc64le' : 'ppc64le' , # Power PC
533
- 's390x' : 's390x' , # IBM S390x
542
+ 'ppc64le' : 'ppc64le' , # Power PC
543
+ 's390x' : 's390x' , # IBM S390x
534
544
}
535
545
sysinfo = {
536
546
'system' : platform .system ().lower (),
@@ -585,8 +595,8 @@ def download_node_src(node_url, src_dir, opt):
585
595
586
596
with ctx as archive :
587
597
node_ver = re .escape (opt .node )
588
- rexp_string = r"node-v%s[^/]*/(README\.md|CHANGELOG\.md|LICENSE)" \
589
- % node_ver
598
+ rexp_string = r"node-v%s[^/]*/(README\.md|CHANGELOG\.md|LICENSE)" \
599
+ % node_ver
590
600
extract_list = [
591
601
member
592
602
for member in members (archive )
@@ -605,6 +615,7 @@ def urlopen(url):
605
615
return urllib2 .urlopen (req , context = context )
606
616
return urllib2 .urlopen (req )
607
617
618
+
608
619
# ---------------------------------------------------------
609
620
# Virtual environment functions
610
621
@@ -1334,7 +1345,6 @@ def main():
1334
1345
fi
1335
1346
"""
1336
1347
1337
-
1338
1348
ACTIVATE_FISH = """
1339
1349
1340
1350
# This file must be used with "source bin/activate.fish" *from fish*
0 commit comments