Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #76 from wting/fix_74_pythonpath

Set $pythonpath when using use or switch
  • Loading branch information...
commit 9269df630e7e29f7df032c6adadb0d7de1b25283 2 parents 8a3ee68 + 05c9609
@utahta authored
View
10 pythonbrew/commands/switch.py
@@ -9,20 +9,22 @@ class SwitchCommand(Command):
name = "switch"
usage = "%prog VERSION"
summary = "Permanently use the specified python as default"
-
+
def run_command(self, options, args):
if not args:
self.parser.print_help()
sys.exit(1)
+
pkg = Package(args[0])
pkgname = pkg.name
if not is_installed(pkgname):
logger.error("`%s` is not installed." % pkgname)
sys.exit(1)
pkgbin = os.path.join(PATH_PYTHONS,pkgname,'bin')
-
- set_current_path(pkgbin)
-
+ pkglib = os.path.join(PATH_PYTHONS,pkgname,'lib')
+
+ set_current_path(pkgbin,pkglib)
+
logger.info("Switched to %s" % pkgname)
SwitchCommand()
View
13 pythonbrew/commands/use.py
@@ -9,7 +9,7 @@ class UseCommand(Command):
name = "use"
usage = "%prog VERSION"
summary = "Use the specified python in current shell"
-
+
def run_command(self, options, args):
if not args:
self.parser.print_help()
@@ -22,14 +22,15 @@ def run_command(self, options, args):
logger.error("`%s` is not installed." % pkgname)
sys.exit(1)
pkgbin = os.path.join(pkgdir,'bin')
-
- self._set_temp(pkgbin)
-
+ pkglib = os.path.join(pkgdir,'lib')
+
+ self._set_temp(pkgbin,pkglib)
+
logger.info("Using `%s`" % pkgname)
- def _set_temp(self, path):
+ def _set_temp(self, bin_path, lib_path):
fp = open(PATH_HOME_ETC_TEMP, 'w')
- fp.write('deactivate &> /dev/null\nPATH_PYTHONBREW_TEMP="%s"\n' % (path))
+ fp.write('deactivate &> /dev/null\nPATH_PYTHONBREW_TEMP="%s"\nPATH_PYTHONBREW_TEMP_LIB="%s"\n' % (bin_path, lib_path))
fp.close()
UseCommand()
View
1  pythonbrew/define.py
@@ -23,6 +23,7 @@
PATH_DISTS = os.path.join(ROOT,"dists")
PATH_ETC = os.path.join(ROOT,"etc")
PATH_BIN = os.path.join(ROOT,"bin")
+PATH_LIB = os.path.join(ROOT,"lib")
PATH_LOG = os.path.join(ROOT,"log")
PATH_VENVS = os.path.join(ROOT, "venvs")
PATH_SCRIPTS = os.path.join(ROOT,"scripts")
View
6 pythonbrew/etc/bashrc
@@ -18,12 +18,14 @@ PY_PYTHONBREW="$PATH_ROOT/bin/pythonbrew"
__pythonbrew_set_default()
{
PATH_PYTHONBREW="$PATH_ROOT/bin"
+ PATH_PYTHONBREW_LIB="$PATH_ROOT/lib"
}
__pythonbrew_set_path()
{
PATH_WITHOUT_PYTHONBREW=$(printf "$PATH" | awk -v RS=: -v ORS=: "/${PATH_ROOT//\//\/}/ {next} {print}" | sed -e 's#:$##')
export PATH=$PATH_PYTHONBREW:$PATH_WITHOUT_PYTHONBREW
+ export PYTHONPATH=$PATH_PYTHONBREW_LIB
}
__pythonbrew_set_temp_path()
@@ -31,6 +33,7 @@ __pythonbrew_set_temp_path()
if [[ -s "$PATH_HOME_ETC/temp" ]] ; then
source "$PATH_HOME_ETC/temp"
PATH_PYTHONBREW="$PATH_ROOT/bin:$PATH_PYTHONBREW_TEMP"
+ PATH_PYTHONBREW_LIB="$PATH_PYTHONBREW_TEMP_LIB"
else
__pythonbrew_set_default
fi
@@ -42,6 +45,7 @@ __pythonbrew_set_current_path()
if [[ -s "$PATH_HOME_ETC/current" ]] ; then
source "$PATH_HOME_ETC/current"
PATH_PYTHONBREW="$PATH_ROOT/bin:$PATH_PYTHONBREW_CURRENT"
+ PATH_PYTHONBREW_LIB="$PATH_PYTHONBREW_CURRENT_LIB"
else
__pythonbrew_set_default
fi
@@ -96,7 +100,7 @@ __pythonbrew_find_command()
--*) continue;;
-*) continue;;
*)
- command_name=$arg
+ command_name=$arg
break
;;
esac
View
32 pythonbrew/util.py
@@ -10,7 +10,7 @@
import subprocess
import shlex
import select
-from pythonbrew.define import PATH_BIN, PATH_HOME_ETC_CURRENT, PATH_PYTHONS, PATH_VENVS
+from pythonbrew.define import PATH_BIN, PATH_LIB, PATH_HOME_ETC_CURRENT, PATH_PYTHONS, PATH_VENVS
from pythonbrew.exceptions import ShellCommandException
from pythonbrew.log import logger
@@ -107,7 +107,7 @@ def symlink(src, dst):
os.symlink(src, dst)
except:
pass
-
+
def unlink(path):
try:
os.unlink(path)
@@ -115,7 +115,7 @@ def unlink(path):
e = sys.exc_info()[1]
if errno.ENOENT != e.errno:
raise
-
+
def rm_r(path):
"""like rm -r command."""
if os.path.isdir(path):
@@ -124,7 +124,7 @@ def rm_r(path):
unlink(path)
def off():
- set_current_path(PATH_BIN)
+ set_current_path(PATH_BIN,PATH_LIB)
def split_leading_dir(path):
path = str(path)
@@ -249,10 +249,10 @@ def is_installed(name):
return False
return True
-def set_current_path(path):
- fp = open(PATH_HOME_ETC_CURRENT, 'w')
- fp.write('deactivate &> /dev/null\nPATH_PYTHONBREW_CURRENT="%s"\n' % (path))
- fp.close()
+def set_current_path(path_bin,path_lib):
+ fp = open(PATH_HOME_ETC_CURRENT, 'w')
+ fp.write('deactivate &> /dev/null\nPATH_PYTHONBREW_CURRENT="%s"\nPATH_PYTHONBREW_CURRENT_LIB="%s"\n' % (path_bin, path_lib))
+ fp.close()
def path_to_fileurl(path):
path = os.path.normcase(os.path.abspath(path))
@@ -309,10 +309,10 @@ def __init__(self, log=None, cwd=None, verbose=False, debug=False):
self._cwd = cwd
self._verbose = verbose
self._debug = debug
-
+
def chdir(self, cwd):
self._cwd = cwd
-
+
def shell(self, cmd):
if self._debug:
logger.log(cmd)
@@ -326,13 +326,13 @@ def shell(self, cmd):
returncode = subprocess.call(cmd, shell=True, cwd=self._cwd)
if returncode:
raise ShellCommandException('%s: failed to `%s`' % (returncode, cmd))
-
+
def call(self, cmd):
if is_str(cmd):
cmd = shlex.split(cmd)
if self._debug:
logger.log(cmd)
-
+
fp = ((self._log and open(self._log, 'a')) or None)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self._cwd)
while p.returncode is None:
@@ -349,7 +349,7 @@ def call(self, cmd):
if fp:
fp.close()
return p.returncode
-
+
def check_call(self, cmd):
returncode = self.call(cmd)
if returncode:
@@ -372,11 +372,11 @@ def __init__(self, name, alias=None):
if alias:
self.name = 'Python-%s' % alias
self.alias = alias
-
+
class Link(object):
def __init__(self, url):
self._url = url
-
+
@property
def filename(self):
url = self._url
@@ -386,7 +386,7 @@ def filename(self):
name = posixpath.basename(url)
assert name, ('URL %r produced no filename' % url)
return name
-
+
@property
def base_url(self):
return posixpath.basename(self._url.split('#', 1)[0].split('?', 1)[0])
Please sign in to comment.
Something went wrong with that request. Please try again.