Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add https://github.com/witsch/PythonTidy as a submodule in order to a…

…void the extra installation and subprocess overhead
  • Loading branch information...
commit 0557d0f8bb67379da40e1758cd23a0d72824ad92 1 parent 6c587c0
@witsch authored
Showing with 36 additions and 19 deletions.
  1. +3 −0  .gitmodules
  2. +1 −0  PythonTidy
  3. +0 −19 PythonTidy.py
  4. +32 −0 Tidy.py
View
3  .gitmodules
@@ -0,0 +1,3 @@
+[submodule "PythonTidy"]
+ path = PythonTidy
+ url = git://github.com/witsch/PythonTidy.git
1  PythonTidy
@@ -0,0 +1 @@
+Subproject commit d07c4bc69b0ab06016d050658cecdffefb232207
View
19 PythonTidy.py
@@ -1,19 +0,0 @@
-from sublime_plugin import TextCommand
-from sublime import Region
-from subprocess import Popen, PIPE
-from os.path import expanduser, exists
-
-
-cmd = ['pythontidy']
-config = expanduser('~/.pythontidy.xml')
-if exists(config):
- cmd.extend(['-c', config])
-
-
-class python_tidy(TextCommand):
- def run(self, edit):
- view = self.view
- region = Region(0L, view.size())
- tidy = Popen(cmd, bufsize=-1, stdin=PIPE, stdout=PIPE, stderr=PIPE)
- output, error = tidy.communicate(view.substr(region))
- view.replace(edit, region, output)
View
32 Tidy.py
@@ -0,0 +1,32 @@
+from sublime_plugin import TextCommand
+from sublime import Region
+from os.path import abspath, expanduser, exists
+from StringIO import StringIO
+from sys import path
+
+
+# tweak path to allow importing PythonTidy from the git submodule
+extra = abspath('PythonTidy')
+path.insert(0, extra)
+import PythonTidy
+import PythonTidyWrapper
+path.remove(extra)
+
+
+def setup():
+ xml = expanduser('~/.pythontidy.xml')
+ if exists(xml):
+ config = PythonTidyWrapper.Config(file=xml)
+ config.to_pythontidy_namespace()
+
+
+class python_tidy(TextCommand):
+
+ def run(self, edit):
+ setup()
+ view = self.view
+ region = Region(0L, view.size())
+ source = StringIO(view.substr(region))
+ output = StringIO()
+ PythonTidy.tidy_up(source, output)
+ view.replace(edit, region, output.getvalue())
Please sign in to comment.
Something went wrong with that request. Please try again.