Skip to content

Commit 6601932

Browse files
fix ImportError: No module named 'six' #13 on Windows, fix evaluate_javascript feature also in non-project files
1 parent cdca01e commit 6601932

File tree

8 files changed

+161
-33
lines changed

8 files changed

+161
-33
lines changed

_generated_2018_01_14_at_01_20_41.py renamed to _generated_2018_01_14_at_17_26_33.py

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from shutil import copyfile
44
from threading import Timer
55

6-
PLUGIN_VERSION = "0.13.0"
6+
PLUGIN_VERSION = "0.13.1"
77

88
PACKAGE_PATH = os.path.abspath(os.path.dirname(__file__))
99
PACKAGE_NAME = os.path.basename(PACKAGE_PATH)
@@ -245,9 +245,7 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_
245245
)
246246

247247
if sublime.platform() == "windows" and use_fp_temp:
248-
if not fp.closed:
249-
fp.close()
250-
os.unlink(fp.name)
248+
os.remove(fp.name)
251249

252250
# reset the PATH environment variable
253251
os.environ.update(old_env)
@@ -299,9 +297,7 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_
299297
os.environ.update(old_env)
300298

301299
if sublime.platform() == "windows" and use_fp_temp:
302-
if not fp.closed:
303-
fp.close()
304-
os.unlink(fp.name)
300+
os.remove(fp.name)
305301

306302
try:
307303
result = json.loads(output.decode("utf-8", "ignore")) if is_output_json else output.decode("utf-8", "ignore")
@@ -323,9 +319,7 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_
323319

324320
if use_fp_temp :
325321
if sublime.platform() == "windows":
326-
if not fp.closed:
327-
fp.close()
328-
os.unlink(fp.name)
322+
os.remove(fp.name)
329323
else:
330324
fp.close()
331325
return [False, None]
@@ -339,9 +333,7 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_
339333

340334
if use_fp_temp :
341335
if sublime.platform() == "windows":
342-
if not fp.closed:
343-
fp.close()
344-
os.unlink(fp.name)
336+
os.remove(fp.name)
345337
else:
346338
fp.close()
347339
return [False, None]
@@ -436,7 +428,6 @@ def getCurrentNPMVersion(self) :
436428

437429
import sublime, sublime_plugin
438430
import re, urllib, shutil, traceback, threading, time, os, hashlib, json, multiprocessing, shlex
439-
from six import iteritems
440431

441432
class Util(object) :
442433

@@ -1002,7 +993,7 @@ def _nested_lookup(key, values, document, wild=False):
1002993
yield result
1003994

1004995
if isinstance(document, dict):
1005-
for k, v in iteritems(document):
996+
for k, v in document.items():
1006997
if values and v in values and (key == k or (wild and key.lower() in k.lower())):
1007998
yield document
1008999
elif not values and key == k or (wild and key.lower() in k.lower()):
@@ -1621,7 +1612,7 @@ def on_load(self, view):
16211612

16221613

16231614
import sublime, sublime_plugin
1624-
import shlex, json
1615+
import shlex, json, os
16251616

16261617
class manage_cliCommand(sublime_plugin.WindowCommand):
16271618

@@ -1636,6 +1627,7 @@ class manage_cliCommand(sublime_plugin.WindowCommand):
16361627
isNode = False
16371628
isNpm = False
16381629
isBinPath = False
1630+
alsoNonProject = False
16391631

16401632
def run(self, **kwargs):
16411633

@@ -1665,6 +1657,34 @@ def run(self, **kwargs):
16651657
self.command = ["$(which "+shlex.quote(self.path_cli)+")"]
16661658
self.path_cli = self.settings["project_settings"]["node_js_custom_path"] or javascriptCompletions.get("node_js_custom_path")
16671659

1660+
if not self.command:
1661+
self.command = kwargs.get("command")
1662+
else:
1663+
self.command += kwargs.get("command")
1664+
1665+
self.prepare_command(**kwargs)
1666+
1667+
elif self.alsoNonProject:
1668+
1669+
self.working_directory = os.path.expanduser("~")
1670+
1671+
if self.isNode:
1672+
self.path_cli = javascriptCompletions.get("node_js_custom_path") or NODE_JS_EXEC
1673+
elif self.isNpm:
1674+
if self.settings["project_settings"]["use_yarn"]:
1675+
self.path_cli = javascriptCompletions.get("yarn_custom_path") or YARN_EXEC
1676+
else:
1677+
self.path_cli = javascriptCompletions.get("npm_custom_path") or NPM_EXEC
1678+
else:
1679+
self.path_cli = javascriptCompletions.get(self.custom_name+"_custom_path") if javascriptCompletions.get(self.custom_name+"_custom_path") else self.cli
1680+
1681+
if sublime.platform() != "windows" and javascriptCompletions.get("node_js_custom_path"):
1682+
if os.path.isabs(self.path_cli) :
1683+
self.command = [shlex.quote(self.path_cli)]
1684+
else:
1685+
self.command = ["$(which "+shlex.quote(self.path_cli)+")"]
1686+
self.path_cli = javascriptCompletions.get("node_js_custom_path")
1687+
16681688

16691689
if not self.command:
16701690
self.command = kwargs.get("command")
@@ -1676,6 +1696,7 @@ def run(self, **kwargs):
16761696
else :
16771697
sublime.error_message("Error: can't get project settings")
16781698

1699+
16791700
def prepare_command(self):
16801701
pass
16811702

@@ -4738,6 +4759,7 @@ class navigate_flow_errorsCommand(navigate_regionsCommand, sublime_plugin.TextCo
47384759
class evaluate_javascriptCommand(manage_cliCommand):
47394760

47404761
isNode = True
4762+
alsoNonProject = True
47414763

47424764
def prepare_command(self, **kwargs):
47434765

changelog/0.13.1.txt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
v0.13.1
2+
3+
## Fixes
4+
5+
- fix ImportError: No module named 'six' #13 on Windows
6+
- fix evaluate_javascript feature also in non-project files
7+
8+
9+
10+
=================================================================
11+
** THIS PLUGIN IS IN BETA! Thanks for your support in advance! **
12+
=================================================================
13+
14+
If you like it, remember to star it ⭐ on GitHub: https://github.com/pichillilorenzo/JavaScriptEnhancements
15+
16+
** USAGE **
17+
===========
18+
19+
See how it works on the Wiki: 👉👉 https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki 👈👈
20+
21+
22+
** WHAT IS THIS? **
23+
===================
24+
25+
This plugin uses Flow (javascript static type checker from Facebook) under the hood.
26+
27+
It offers better javascript autocomplete and a lot of features about creating,
28+
developing and managing javascript projects, such as:
29+
30+
- Cordova projects (run cordova emulate, build, compile, serve, etc. directly from Sublime Text!)
31+
- Ionic v1 and v2 projects (same as Cordova projects!)
32+
- Angular v1 and v2 projects
33+
- React projects (only about the creation for the moment)
34+
- React Native projects (only about the creation for the moment. I will add also NativeScript support)
35+
- Express projects (only about the creation for the moment)
36+
- Yeoman generators
37+
- Local bookmarks project
38+
- JavaScript real-time errors
39+
- etc.
40+
41+
You could use it also in existing projects (see the Wiki - https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki/Using-it-with-an-existing-project)!
42+
43+
It turns Sublime Text into a JavaScript IDE like!
44+
45+
This project is based on my other Sublime Text plugin JavaScript Completions (https://github.com/pichillilorenzo/JavaScript-Completions)
46+
47+
** NOTE **
48+
If you want use this plugin, you may want uninstall/disable the JavaScript Completions plugin, if installed.
49+
50+
** OS SUPPORTED NOW **
51+
======================
52+
53+
👉 Linux (64-bit)
54+
👉 Mac OS X
55+
👉 Windows (64-bit): released without the use of TerminalView plugin. For each feature (like also creating a project) will be used the cmd.exe shell (so during the creation of a project don't close it until it finishes!). Unfortunately the TerminalView plugin supports only Linux-based OS 😞. Has someone any advice or idea about that? Is there something similar to the TerminalView plugin for Windows?? Thanks!
56+
57+
❗❗ Dependencies ❗❗
58+
=======================
59+
60+
In order to work properly, this plugin has some dependencies:
61+
62+
👉 Sublime Text 3 (build 3124 or newer)
63+
👉 Node.js and npm (https://nodejs.org or nvm (https://github.com/creationix/nvm))
64+
👉 TerminalView (only for Linux and Mac OS X) sublime text plugin (https://github.com/Wramberg/TerminalView)
65+
66+
Not required, but useful for typescript files (Flow wont work on this type of files):
67+
68+
👉 TypeScript sublime text plugin (https://github.com/Microsoft/TypeScript-Sublime-Plugin)
69+
70+
** Flow Requirements **
71+
=======================
72+
73+
It use [Flow](https://github.com/facebook/flow) for type checking and auto-completions.
74+
75+
👉 Mac OS X
76+
👉 Linux (64-bit)
77+
👉 Windows (64-bit)
78+
79+
Email me for any questions or doubts about this new project on: pichillilorenzo@gmail.com
80+
81+
Thanks for your support! 😄😄
82+
83+
MIT License

helper/evaluate_javascript_command.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
class evaluate_javascriptCommand(manage_cliCommand):
55

66
isNode = True
7+
alsoNonProject = True
78

89
def prepare_command(self, **kwargs):
910

helper/node/main.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_
114114
)
115115

116116
if sublime.platform() == "windows" and use_fp_temp:
117-
if not fp.closed:
118-
fp.close()
119-
os.unlink(fp.name)
117+
os.remove(fp.name)
120118

121119
# reset the PATH environment variable
122120
os.environ.update(old_env)
@@ -168,9 +166,7 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_
168166
os.environ.update(old_env)
169167

170168
if sublime.platform() == "windows" and use_fp_temp:
171-
if not fp.closed:
172-
fp.close()
173-
os.unlink(fp.name)
169+
os.remove(fp.name)
174170

175171
try:
176172
result = json.loads(output.decode("utf-8", "ignore")) if is_output_json else output.decode("utf-8", "ignore")
@@ -192,9 +188,7 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_
192188

193189
if use_fp_temp :
194190
if sublime.platform() == "windows":
195-
if not fp.closed:
196-
fp.close()
197-
os.unlink(fp.name)
191+
os.remove(fp.name)
198192
else:
199193
fp.close()
200194
return [False, None]
@@ -208,9 +202,7 @@ def execute_check_output(self, command, command_args, is_from_bin=False, use_fp_
208202

209203
if use_fp_temp :
210204
if sublime.platform() == "windows":
211-
if not fp.closed:
212-
fp.close()
213-
os.unlink(fp.name)
205+
os.remove(fp.name)
214206
else:
215207
fp.close()
216208
return [False, None]

helper/util/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import sublime, sublime_plugin
22
import re, urllib, shutil, traceback, threading, time, os, hashlib, json, multiprocessing, shlex
3-
from six import iteritems
43

54
class Util(object) :
65

@@ -566,7 +565,7 @@ def _nested_lookup(key, values, document, wild=False):
566565
yield result
567566

568567
if isinstance(document, dict):
569-
for k, v in iteritems(document):
568+
for k, v in document.items():
570569
if values and v in values and (key == k or (wild and key.lower() in k.lower())):
571570
yield document
572571
elif not values and key == k or (wild and key.lower() in k.lower()):

make/_init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from shutil import copyfile
44
from threading import Timer
55

6-
PLUGIN_VERSION = "0.13.0"
6+
PLUGIN_VERSION = "0.13.1"
77

88
PACKAGE_PATH = os.path.abspath(os.path.dirname(__file__))
99
PACKAGE_NAME = os.path.basename(PACKAGE_PATH)

messages.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"0.11.0": "changelog/0.11.0.txt",
1010
"0.11.1": "changelog/0.11.1.txt",
1111
"0.11.11": "changelog/0.11.11.txt",
12-
"0.13.0": "changelog/0.13.0.txt"
12+
"0.13.0": "changelog/0.13.0.txt",
13+
"0.13.1": "changelog/0.13.1.txt"
1314
}

project/manage_cli/manage_cli_command.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sublime, sublime_plugin
2-
import shlex, json
2+
import shlex, json, os
33

44
class manage_cliCommand(sublime_plugin.WindowCommand):
55

@@ -14,6 +14,7 @@ class manage_cliCommand(sublime_plugin.WindowCommand):
1414
isNode = False
1515
isNpm = False
1616
isBinPath = False
17+
alsoNonProject = False
1718

1819
def run(self, **kwargs):
1920

@@ -43,6 +44,34 @@ def run(self, **kwargs):
4344
self.command = ["$(which "+shlex.quote(self.path_cli)+")"]
4445
self.path_cli = self.settings["project_settings"]["node_js_custom_path"] or javascriptCompletions.get("node_js_custom_path")
4546

47+
if not self.command:
48+
self.command = kwargs.get("command")
49+
else:
50+
self.command += kwargs.get("command")
51+
52+
self.prepare_command(**kwargs)
53+
54+
elif self.alsoNonProject:
55+
56+
self.working_directory = os.path.expanduser("~")
57+
58+
if self.isNode:
59+
self.path_cli = javascriptCompletions.get("node_js_custom_path") or NODE_JS_EXEC
60+
elif self.isNpm:
61+
if self.settings["project_settings"]["use_yarn"]:
62+
self.path_cli = javascriptCompletions.get("yarn_custom_path") or YARN_EXEC
63+
else:
64+
self.path_cli = javascriptCompletions.get("npm_custom_path") or NPM_EXEC
65+
else:
66+
self.path_cli = javascriptCompletions.get(self.custom_name+"_custom_path") if javascriptCompletions.get(self.custom_name+"_custom_path") else self.cli
67+
68+
if sublime.platform() != "windows" and javascriptCompletions.get("node_js_custom_path"):
69+
if os.path.isabs(self.path_cli) :
70+
self.command = [shlex.quote(self.path_cli)]
71+
else:
72+
self.command = ["$(which "+shlex.quote(self.path_cli)+")"]
73+
self.path_cli = javascriptCompletions.get("node_js_custom_path")
74+
4675

4776
if not self.command:
4877
self.command = kwargs.get("command")
@@ -54,6 +83,7 @@ def run(self, **kwargs):
5483
else :
5584
sublime.error_message("Error: can't get project settings")
5685

86+
5787
def prepare_command(self):
5888
pass
5989

0 commit comments

Comments
 (0)