Permalink
Browse files

Push extract of sys.path from python bin into stickytape package

  • Loading branch information...
1 parent 2e2b82b commit b9b5dcfcfcc1fc3c42b75d397017072f75b104d2 @mwilliamson committed Nov 22, 2012
Showing with 16 additions and 16 deletions.
  1. +2 −12 scripts/stickytape
  2. +14 −4 stickytape/__init__.py
View
@@ -9,20 +9,10 @@ import stickytape
def main():
args = _parse_args()
output_file = _open_output(args)
- python_paths = args.add_python_path + _read_sys_path_from_python_bin(args.python_binary)
- output = stickytape.script(args.script,python_paths )
+ output = stickytape.script(
+ args.script, args.add_python_path, args.python_binary)
output_file.write(output)
-def _read_sys_path_from_python_bin(binary_path):
- if binary_path is None:
- return []
- else:
- output = subprocess.check_output(
- [binary_path, "-c", "import sys;\nfor path in sys.path: print path"],
- env={}
- )
- return [line.strip() for line in output.split("\n") if line.strip()]
-
def _open_output(args):
if args.output_file is None:
return sys.stdout
View
@@ -2,17 +2,27 @@
import re
import codecs
-def script(path, python_paths=[]):
- output = []
+def script(path, add_python_paths=[], python_binary=None):
+ python_paths = [os.path.dirname(path)] + add_python_paths + _read_sys_path_from_python_bin(python_binary)
- sys_path = [os.path.dirname(path)] + python_paths
+ output = []
output.append(_read_shebang(path))
output.append(_prelude())
- output.append(_generate_module_writers(path, sys_path))
+ output.append(_generate_module_writers(path, python_paths))
output.append(_indent(open(path).read()))
return "".join(output)
+def _read_sys_path_from_python_bin(binary_path):
+ if binary_path is None:
+ return []
+ else:
+ output = subprocess.check_output(
+ [binary_path, "-c", "import sys;\nfor path in sys.path: print path"],
+ env={}
+ )
+ return [line.strip() for line in output.split("\n") if line.strip()]
+
def _indent(string):
return " " + string.replace("\n", "\n ")

0 comments on commit b9b5dcf

Please sign in to comment.