mirror of
https://github.com/kennethreitz-archive/python-build.git
synced 2026-06-05 23:30:18 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e033edcda0 |
@@ -8,3 +8,4 @@
|
|||||||
pythonbrew.egg-info
|
pythonbrew.egg-info
|
||||||
dist
|
dist
|
||||||
__pycache__
|
__pycache__
|
||||||
|
*.swp
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
* 0.9
|
||||||
|
- Added `buildout` command.
|
||||||
|
- Added `venv` command.
|
||||||
|
|
||||||
* 0.8
|
* 0.8
|
||||||
- Fixed issue #21 Added Ubuntu 11.04(Natty) support
|
- Fixed issue #21 Added Ubuntu 11.04(Natty) support
|
||||||
- Fixed issue #24 non-framework python27 now defines environ properly. Thanks npinto.
|
- Fixed issue #24 non-framework python27 now defines environ properly. Thanks npinto.
|
||||||
@@ -7,7 +11,7 @@
|
|||||||
- Fixed bug: `pythonbrew off` need not have removed the symlink in bin directory
|
- Fixed bug: `pythonbrew off` need not have removed the symlink in bin directory
|
||||||
- Added --no-test option to the install command
|
- Added --no-test option to the install command
|
||||||
- Added --verbose option to the install command
|
- Added --verbose option to the install command
|
||||||
- `pythonbrew clean` has been renamed. Added `pythonbrew cleanup` instead.
|
- `pythonbrew clean` has been removed. Added `pythonbrew cleanup` instead.
|
||||||
|
|
||||||
* 0.7.3
|
* 0.7.3
|
||||||
- Improved symlink command
|
- Improved symlink command
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ Use the specified python in current shell::
|
|||||||
Runs a named python file against specified and/or all pythons::
|
Runs a named python file against specified and/or all pythons::
|
||||||
|
|
||||||
pythonbrew py test.py
|
pythonbrew py test.py
|
||||||
pythonbrew py -v test.py # Show running python version
|
pythonbrew py -v test.py # Show verbose output
|
||||||
pythonbrew py -p 2.7.2 -p 3.2 test.py # Use the specified pythons
|
pythonbrew py -p 2.7.2 -p 3.2 test.py # Use the specified pythons
|
||||||
|
|
||||||
List the installed pythons::
|
List the installed pythons::
|
||||||
@@ -88,6 +88,18 @@ Create/Remove a symbolic link to python (in a directory on your $PATH)::
|
|||||||
pythonbrew symlink pip # Create a symbolic link to the specified script in bin directory
|
pythonbrew symlink pip # Create a symbolic link to the specified script in bin directory
|
||||||
pythonbrew symlink -r # Remove a symbolic link
|
pythonbrew symlink -r # Remove a symbolic link
|
||||||
|
|
||||||
|
Runs the buildout with specified or current using python::
|
||||||
|
|
||||||
|
pythonbrew buildout
|
||||||
|
pythonbrew buildout -p 2.6.6
|
||||||
|
|
||||||
|
Create isolated python environments::
|
||||||
|
|
||||||
|
pythonbrew venv create proj
|
||||||
|
pythonbrew venv list
|
||||||
|
pythonbrew venv use proj
|
||||||
|
pythonbrew venv delete proj
|
||||||
|
|
||||||
Show version::
|
Show version::
|
||||||
|
|
||||||
pythonbrew version
|
pythonbrew version
|
||||||
@@ -125,12 +137,20 @@ update
|
|||||||
|
|
||||||
off
|
off
|
||||||
Disable pythonbrew.
|
Disable pythonbrew.
|
||||||
|
|
||||||
|
symlink
|
||||||
|
Create/Remove a symbolic link to python (in a directory on your $PATH)
|
||||||
|
|
||||||
|
buildout
|
||||||
|
Runs the buildout with specified or current using python.
|
||||||
|
|
||||||
|
venv
|
||||||
|
Create isolated python environments.
|
||||||
|
|
||||||
version
|
version
|
||||||
Show version.
|
Show version.
|
||||||
|
|
||||||
See more details below::
|
See more details below:
|
||||||
|
|
||||||
pythonbrew help <command>
|
pythonbrew help <command>
|
||||||
|
|
||||||
LICENCE
|
LICENCE
|
||||||
|
|||||||
+24
-4
@@ -51,7 +51,7 @@ Use the specified python in current shell::
|
|||||||
Runs a named python file against specified and/or all pythons::
|
Runs a named python file against specified and/or all pythons::
|
||||||
|
|
||||||
pythonbrew py test.py
|
pythonbrew py test.py
|
||||||
pythonbrew py -v test.py # Show running python version
|
pythonbrew py -v test.py # Show verbose output
|
||||||
pythonbrew py -p 2.7.2 -p 3.2 test.py # Use the specified pythons
|
pythonbrew py -p 2.7.2 -p 3.2 test.py # Use the specified pythons
|
||||||
|
|
||||||
List the installed pythons::
|
List the installed pythons::
|
||||||
@@ -88,6 +88,18 @@ Create/Remove a symbolic link to python (in a directory on your $PATH)::
|
|||||||
pythonbrew symlink pip # Create a symbolic link to the specified script in bin directory
|
pythonbrew symlink pip # Create a symbolic link to the specified script in bin directory
|
||||||
pythonbrew symlink -r # Remove a symbolic link
|
pythonbrew symlink -r # Remove a symbolic link
|
||||||
|
|
||||||
|
Runs the buildout with specified or current using python::
|
||||||
|
|
||||||
|
pythonbrew buildout
|
||||||
|
pythonbrew buildout -p 2.6.6
|
||||||
|
|
||||||
|
Create isolated python environments::
|
||||||
|
|
||||||
|
pythonbrew venv create proj
|
||||||
|
pythonbrew venv list
|
||||||
|
pythonbrew venv use proj
|
||||||
|
pythonbrew venv delete proj
|
||||||
|
|
||||||
Show version::
|
Show version::
|
||||||
|
|
||||||
pythonbrew version
|
pythonbrew version
|
||||||
@@ -125,12 +137,20 @@ update
|
|||||||
|
|
||||||
off
|
off
|
||||||
Disable pythonbrew.
|
Disable pythonbrew.
|
||||||
|
|
||||||
|
symlink
|
||||||
|
Create/Remove a symbolic link to python (in a directory on your $PATH)
|
||||||
|
|
||||||
|
buildout
|
||||||
|
Runs the buildout with specified or current using python.
|
||||||
|
|
||||||
|
venv
|
||||||
|
Create isolated python environments.
|
||||||
|
|
||||||
version
|
version
|
||||||
Show version.
|
Show version.
|
||||||
|
|
||||||
See more details below::
|
See more details below:
|
||||||
|
|
||||||
pythonbrew help <command>
|
pythonbrew help <command>
|
||||||
|
|
||||||
LICENCE
|
LICENCE
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
from pythonbrew.basecommand import Command
|
||||||
|
from pythonbrew.define import PATH_PYTHONS, BOOTSTRAP_DLSITE, PATH_DISTS
|
||||||
|
from pythonbrew.util import Package, get_using_python_pkgname, Link, is_installed
|
||||||
|
from pythonbrew.log import logger
|
||||||
|
from pythonbrew.downloader import Downloader
|
||||||
|
|
||||||
|
class BuildoutCommand(Command):
|
||||||
|
name = "buildout"
|
||||||
|
usage = "%prog"
|
||||||
|
summary = "Runs the buildout with specified or current using python"
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(BuildoutCommand, self).__init__()
|
||||||
|
self.parser.add_option(
|
||||||
|
"-p", "--python",
|
||||||
|
dest="python",
|
||||||
|
default=None,
|
||||||
|
help="Use the specified version of python.",
|
||||||
|
metavar='VERSION'
|
||||||
|
)
|
||||||
|
|
||||||
|
def run_command(self, options, args):
|
||||||
|
if options.python:
|
||||||
|
pkgname = Package(options.python).name
|
||||||
|
else:
|
||||||
|
pkgname = get_using_python_pkgname()
|
||||||
|
if not is_installed(pkgname):
|
||||||
|
logger.info('%s is not installed.' % pkgname)
|
||||||
|
sys.exit(1)
|
||||||
|
logger.info('Using %s' % pkgname)
|
||||||
|
|
||||||
|
# build a path
|
||||||
|
python = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
|
||||||
|
|
||||||
|
# Download bootstrap.py
|
||||||
|
download_url = BOOTSTRAP_DLSITE
|
||||||
|
filename = Link(download_url).filename
|
||||||
|
bootstrap = os.path.join(PATH_DISTS, filename)
|
||||||
|
try:
|
||||||
|
d = Downloader()
|
||||||
|
d.download(filename, download_url, bootstrap)
|
||||||
|
except:
|
||||||
|
logger.error("Failed to download. `%s`" % download_url)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Using bootstrap.py
|
||||||
|
if subprocess.call([python, bootstrap, '-d']):
|
||||||
|
logger.error('Failed to bootstrap.')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Using buildout
|
||||||
|
subprocess.call(['./bin/buildout'])
|
||||||
|
|
||||||
|
BuildoutCommand()
|
||||||
@@ -3,7 +3,8 @@ import re
|
|||||||
from pythonbrew.basecommand import Command
|
from pythonbrew.basecommand import Command
|
||||||
from pythonbrew.define import PYTHON_VERSION_URL, LATEST_VERSIONS_OF_PYTHON,\
|
from pythonbrew.define import PYTHON_VERSION_URL, LATEST_VERSIONS_OF_PYTHON,\
|
||||||
PATH_PYTHONS
|
PATH_PYTHONS
|
||||||
from pythonbrew.util import Package, get_current_python_path
|
from pythonbrew.util import Package, get_using_python_pkgname,\
|
||||||
|
get_using_python_path
|
||||||
from pythonbrew.log import logger
|
from pythonbrew.log import logger
|
||||||
|
|
||||||
class ListCommand(Command):
|
class ListCommand(Command):
|
||||||
@@ -36,15 +37,14 @@ class ListCommand(Command):
|
|||||||
|
|
||||||
def installed(self, options, args):
|
def installed(self, options, args):
|
||||||
logger.info('# installed pythons')
|
logger.info('# installed pythons')
|
||||||
cur = get_current_python_path()
|
cur = get_using_python_pkgname()
|
||||||
for d in sorted(os.listdir(PATH_PYTHONS)):
|
for d in sorted(os.listdir(PATH_PYTHONS)):
|
||||||
if cur and os.path.samefile(cur, os.path.join(PATH_PYTHONS, d, 'bin','python')):
|
if cur and cur == d:
|
||||||
logger.info('%s (*)' % d)
|
logger.info('%s (*)' % d)
|
||||||
cur = None
|
|
||||||
else:
|
else:
|
||||||
logger.info('%s' % d)
|
logger.info('%s' % d)
|
||||||
if cur:
|
if not cur:
|
||||||
logger.info('%s (*)' % cur)
|
logger.info('%s (*)' % get_using_python_path())
|
||||||
|
|
||||||
def available_install(self, options, args):
|
def available_install(self, options, args):
|
||||||
logger.info('# available install pythons')
|
logger.info('# available install pythons')
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
from pythonbrew.basecommand import Command
|
from pythonbrew.basecommand import Command
|
||||||
from pythonbrew.define import PATH_PYTHONS, PATH_BIN
|
from pythonbrew.define import PATH_PYTHONS, PATH_BIN
|
||||||
from pythonbrew.util import Package, set_current_path
|
from pythonbrew.util import Package, set_current_path, is_installed
|
||||||
from pythonbrew.log import logger
|
from pythonbrew.log import logger
|
||||||
|
|
||||||
class SwitchCommand(Command):
|
class SwitchCommand(Command):
|
||||||
@@ -16,11 +16,10 @@ class SwitchCommand(Command):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pkg = Package(args[0])
|
pkg = Package(args[0])
|
||||||
pkgname = pkg.name
|
pkgname = pkg.name
|
||||||
pkgdir = os.path.join(PATH_PYTHONS, pkgname)
|
if not is_installed(pkgname):
|
||||||
if not os.path.isdir(pkgdir):
|
|
||||||
logger.info("`%s` is not installed." % pkgname)
|
logger.info("`%s` is not installed." % pkgname)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
pkgbin = os.path.join(pkgdir,'bin')
|
pkgbin = os.path.join(PATH_PYTHONS,pkgname,'bin')
|
||||||
|
|
||||||
set_current_path('%s:%s' % (PATH_BIN, pkgbin))
|
set_current_path('%s:%s' % (PATH_BIN, pkgbin))
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
from pythonbrew.basecommand import Command
|
from pythonbrew.basecommand import Command
|
||||||
from pythonbrew.define import PATH_PYTHONS, PATH_BIN
|
from pythonbrew.define import PATH_PYTHONS, PATH_BIN, PATH_VENVS
|
||||||
from pythonbrew.util import off, rm_r, Package, get_current_python_path, unlink
|
from pythonbrew.util import off, rm_r, Package, get_using_python_pkgname, unlink,\
|
||||||
|
is_installed
|
||||||
from pythonbrew.log import logger
|
from pythonbrew.log import logger
|
||||||
|
|
||||||
class UninstallCommand(Command):
|
class UninstallCommand(Command):
|
||||||
@@ -16,10 +17,11 @@ class UninstallCommand(Command):
|
|||||||
pkg = Package(arg)
|
pkg = Package(arg)
|
||||||
pkgname = pkg.name
|
pkgname = pkg.name
|
||||||
pkgpath = os.path.join(PATH_PYTHONS, pkgname)
|
pkgpath = os.path.join(PATH_PYTHONS, pkgname)
|
||||||
if not os.path.isdir(pkgpath):
|
venvpath = os.path.join(PATH_VENVS, pkgname)
|
||||||
|
if not is_installed(pkgname):
|
||||||
logger.info("`%s` is not installed." % pkgname)
|
logger.info("`%s` is not installed." % pkgname)
|
||||||
continue
|
continue
|
||||||
if get_current_python_path() == os.path.join(pkgpath,'bin','python'):
|
if get_using_python_pkgname() == pkgname:
|
||||||
off()
|
off()
|
||||||
for d in os.listdir(PATH_BIN):
|
for d in os.listdir(PATH_BIN):
|
||||||
# remove symlink
|
# remove symlink
|
||||||
@@ -30,6 +32,7 @@ class UninstallCommand(Command):
|
|||||||
if os.path.isfile(tgtpath) and os.path.samefile(path, tgtpath):
|
if os.path.isfile(tgtpath) and os.path.samefile(path, tgtpath):
|
||||||
unlink(path)
|
unlink(path)
|
||||||
rm_r(pkgpath)
|
rm_r(pkgpath)
|
||||||
|
rm_r(venvpath)
|
||||||
else:
|
else:
|
||||||
self.parser.print_help()
|
self.parser.print_help()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,158 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from pythonbrew.basecommand import Command
|
||||||
|
from pythonbrew.define import PATH_PYTHONS, PATH_VENVS, PATH_ETC_VENV
|
||||||
|
from pythonbrew.util import Subprocess, Package,\
|
||||||
|
is_installed, get_installed_pythons_pkgname, get_using_python_pkgname
|
||||||
|
from pythonbrew.log import logger
|
||||||
|
|
||||||
|
class VenvCommand(Command):
|
||||||
|
name = "venv"
|
||||||
|
usage = "%prog [create|use|delete|list] [project]"
|
||||||
|
summary = "Create isolated python environments"
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(VenvCommand, self).__init__()
|
||||||
|
self.parser.add_option(
|
||||||
|
"-p", "--python",
|
||||||
|
dest="python",
|
||||||
|
default=None,
|
||||||
|
help="Use the specified version of python.",
|
||||||
|
metavar='VERSION'
|
||||||
|
)
|
||||||
|
self.parser.add_option(
|
||||||
|
"-a", "--all",
|
||||||
|
dest="all",
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help="Show the all python environments.",
|
||||||
|
metavar='VERSION'
|
||||||
|
)
|
||||||
|
self.template_env = """export VIRTUALENVWRAPPER_PYTHON=%(venv_py)s
|
||||||
|
export VIRTUALENVWRAPPER_VIRTUALENV=%(venv_venv)s
|
||||||
|
export WORKON_HOME=%(workon_home)s
|
||||||
|
export VIRTUALENVWRAPPER_HOOK_DIR=%(workon_home)s
|
||||||
|
export VIRTUALENVWRAPPER_LOG_DIR=%(workon_home)s
|
||||||
|
source %(venv_sh)s
|
||||||
|
"""
|
||||||
|
|
||||||
|
def run_command(self, options, args):
|
||||||
|
if not args:
|
||||||
|
logger.error('Unrecognized command line argument: ( see: \'pythonbrew help venv\' )')
|
||||||
|
sys.exit(1)
|
||||||
|
cmd = args[0]
|
||||||
|
if not cmd in ('create', 'delete', 'use', 'list'):
|
||||||
|
logger.error('Unrecognized command line argument: ( see: \'pythonbrew help venv\' )')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# find python2
|
||||||
|
venv_pkgname = None
|
||||||
|
for pkgname in reversed(get_installed_pythons_pkgname()):
|
||||||
|
# virtualenvwrapper require Python2
|
||||||
|
venv_pkgver = Package(pkgname).version
|
||||||
|
if venv_pkgver >= '2.4' and venv_pkgver < '3':
|
||||||
|
venv_pkgname = pkgname
|
||||||
|
break
|
||||||
|
if not venv_pkgname:
|
||||||
|
logger.error('Can not create virtual environment before installing a python2. Try \'pythonbrew install <python2.4 - 2.7>\'.')
|
||||||
|
sys.exit(1)
|
||||||
|
venv_dir = os.path.join(PATH_PYTHONS, venv_pkgname)
|
||||||
|
venv_bin = os.path.join(venv_dir, 'bin')
|
||||||
|
|
||||||
|
# target python interpreter
|
||||||
|
if options.python:
|
||||||
|
pkgname = Package(options.python).name
|
||||||
|
if not is_installed(pkgname):
|
||||||
|
logger.error('%s is not installed.' % pkgname)
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
pkgname = get_using_python_pkgname()
|
||||||
|
if not pkgname:
|
||||||
|
logger.error('Can not use venv command before using a python. Try \'pythonbrew switch <some python>\'.')
|
||||||
|
sys.exit(1)
|
||||||
|
self._pkgname = pkgname
|
||||||
|
self._target_py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
|
||||||
|
self._workon_home = os.path.join(PATH_VENVS, pkgname)
|
||||||
|
self._venv_py = os.path.join(venv_bin, 'python')
|
||||||
|
self._venv_venv = os.path.join(venv_bin, 'virtualenv')
|
||||||
|
self._venv_sh = os.path.join(venv_bin, 'virtualenvwrapper.sh')
|
||||||
|
|
||||||
|
# has virtualenv & virtualenvwrapper?
|
||||||
|
if not self._venv_venv or not self._venv_sh:
|
||||||
|
logger.info('Installing virtualenv into %s' % venv_dir)
|
||||||
|
s = Subprocess(verbose=True)
|
||||||
|
s.shell('%s %s %s' % (os.path.join(venv_bin,'pip'), 'install', 'virtualenvwrapper'))
|
||||||
|
|
||||||
|
# Create a shell script
|
||||||
|
try:
|
||||||
|
self.__getattribute__('run_command_%s' % cmd)(options, args)
|
||||||
|
except:
|
||||||
|
logger.error('`%s` command not found.' % cmd)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def run_command_create(self, options, args):
|
||||||
|
output = [self.template_env % {'venv_py': self._venv_py,
|
||||||
|
'venv_venv': self._venv_venv,
|
||||||
|
'workon_home': self._workon_home,
|
||||||
|
'venv_sh': self._venv_sh}]
|
||||||
|
for arg in args[1:]:
|
||||||
|
output.append("""echo '# Create `%(arg)s` environment into %(workon_home)s'
|
||||||
|
mkvirtualenv -p '%(target_py)s' '%(arg)s'
|
||||||
|
""" % {'arg': arg,
|
||||||
|
'workon_home': self._workon_home,
|
||||||
|
'target_py': self._target_py})
|
||||||
|
self._write(''.join(output))
|
||||||
|
|
||||||
|
def run_command_delete(self, options, args):
|
||||||
|
output = [self.template_env % {'venv_py': self._venv_py,
|
||||||
|
'venv_venv': self._venv_venv,
|
||||||
|
'workon_home': self._workon_home,
|
||||||
|
'venv_sh': self._venv_sh}]
|
||||||
|
for arg in args[1:]:
|
||||||
|
output.append("""echo '# Delete `%(arg)s` environment in %(workon_home)s'
|
||||||
|
rmvirtualenv '%(arg)s'
|
||||||
|
""" % {'arg': arg,
|
||||||
|
'workon_home': self._workon_home})
|
||||||
|
self._write(''.join(output))
|
||||||
|
|
||||||
|
def run_command_use(self, options, args):
|
||||||
|
if len(args) < 2:
|
||||||
|
logger.error("Unrecognized command line argument: ( 'pythonbrew venv use <project>' )")
|
||||||
|
sys.exit(1)
|
||||||
|
template = self.template_env + """echo '# Using `%(arg)s` environment (found in %(workon_home)s)'
|
||||||
|
echo '# To leave an environment, simply run `deactivate`'
|
||||||
|
workon '%(arg)s'
|
||||||
|
"""
|
||||||
|
self._write(template % {'venv_py': self._venv_py,
|
||||||
|
'venv_venv': self._venv_venv,
|
||||||
|
'workon_home': self._workon_home,
|
||||||
|
'venv_sh': self._venv_sh,
|
||||||
|
'arg': args[1]})
|
||||||
|
|
||||||
|
def run_command_list(self, options, args):
|
||||||
|
template = self.template_env + """echo '# virtualenv for %(pkgname)s (found in %(workon_home)s)'
|
||||||
|
workon
|
||||||
|
"""
|
||||||
|
if options.all:
|
||||||
|
output = []
|
||||||
|
for pkgname in get_installed_pythons_pkgname():
|
||||||
|
workon_home = os.path.join(PATH_VENVS, pkgname)
|
||||||
|
output.append(template % {'venv_py': self._venv_py,
|
||||||
|
'venv_venv': self._venv_venv,
|
||||||
|
'workon_home': workon_home,
|
||||||
|
'venv_sh': self._venv_sh,
|
||||||
|
'pkgname': pkgname})
|
||||||
|
self._write(''.join(output))
|
||||||
|
else:
|
||||||
|
self._write(template % {'venv_py': self._venv_py,
|
||||||
|
'venv_venv': self._venv_venv,
|
||||||
|
'workon_home': self._workon_home,
|
||||||
|
'venv_sh': self._venv_sh,
|
||||||
|
'pkgname': self._pkgname})
|
||||||
|
|
||||||
|
def _write(self, src):
|
||||||
|
fp = open(PATH_ETC_VENV, 'w')
|
||||||
|
fp.write(src)
|
||||||
|
fp.close()
|
||||||
|
|
||||||
|
VenvCommand()
|
||||||
@@ -6,7 +6,7 @@ except:
|
|||||||
import configparser as ConfigParser
|
import configparser as ConfigParser
|
||||||
|
|
||||||
# pythonbrew version
|
# pythonbrew version
|
||||||
VERSION = "0.8"
|
VERSION = "0.9"
|
||||||
|
|
||||||
# pythonbrew root path
|
# pythonbrew root path
|
||||||
ROOT = os.environ.get("PYTHONBREW_ROOT")
|
ROOT = os.environ.get("PYTHONBREW_ROOT")
|
||||||
@@ -23,6 +23,7 @@ PATH_DISTS = os.path.join(ROOT,"dists")
|
|||||||
PATH_ETC = os.path.join(ROOT,"etc")
|
PATH_ETC = os.path.join(ROOT,"etc")
|
||||||
PATH_BIN = os.path.join(ROOT,"bin")
|
PATH_BIN = os.path.join(ROOT,"bin")
|
||||||
PATH_LOG = os.path.join(ROOT,"log")
|
PATH_LOG = os.path.join(ROOT,"log")
|
||||||
|
PATH_VENVS = os.path.join(ROOT, "venvs")
|
||||||
PATH_SCRIPTS = os.path.join(ROOT,"scripts")
|
PATH_SCRIPTS = os.path.join(ROOT,"scripts")
|
||||||
PATH_SCRIPTS_PYTHONBREW = os.path.join(PATH_SCRIPTS,"pythonbrew")
|
PATH_SCRIPTS_PYTHONBREW = os.path.join(PATH_SCRIPTS,"pythonbrew")
|
||||||
PATH_SCRIPTS_PYTHONBREW_COMMANDS = os.path.join(PATH_SCRIPTS_PYTHONBREW,"commands")
|
PATH_SCRIPTS_PYTHONBREW_COMMANDS = os.path.join(PATH_SCRIPTS_PYTHONBREW,"commands")
|
||||||
@@ -40,6 +41,7 @@ PATH_BIN_PYTHONBREW = os.path.join(PATH_BIN,'pythonbrew')
|
|||||||
PATH_ETC_CURRENT = os.path.join(PATH_ETC,'current')
|
PATH_ETC_CURRENT = os.path.join(PATH_ETC,'current')
|
||||||
PATH_ETC_TEMP = os.path.join(PATH_ETC,'temp')
|
PATH_ETC_TEMP = os.path.join(PATH_ETC,'temp')
|
||||||
PATH_ETC_CONFIG = os.path.join(PATH_ETC,'config.cfg')
|
PATH_ETC_CONFIG = os.path.join(PATH_ETC,'config.cfg')
|
||||||
|
PATH_ETC_VENV = os.path.join(PATH_ETC, 'venv.run')
|
||||||
|
|
||||||
# read config.cfg
|
# read config.cfg
|
||||||
config = ConfigParser.SafeConfigParser()
|
config = ConfigParser.SafeConfigParser()
|
||||||
@@ -53,6 +55,9 @@ def _get_or_default(section, option, default=''):
|
|||||||
# setuptools download
|
# setuptools download
|
||||||
DISTRIBUTE_SETUP_DLSITE = _get_or_default('distribute', 'url')
|
DISTRIBUTE_SETUP_DLSITE = _get_or_default('distribute', 'url')
|
||||||
|
|
||||||
|
# buildout bootstrap download
|
||||||
|
BOOTSTRAP_DLSITE = _get_or_default('bootstrap', 'url')
|
||||||
|
|
||||||
# pythonbrew download
|
# pythonbrew download
|
||||||
PYTHONBREW_UPDATE_URL_MASTER = _get_or_default('pythonbrew', 'master')
|
PYTHONBREW_UPDATE_URL_MASTER = _get_or_default('pythonbrew', 'master')
|
||||||
PYTHONBREW_UPDATE_URL_DEVELOP = _get_or_default('pythonbrew', 'develop')
|
PYTHONBREW_UPDATE_URL_DEVELOP = _get_or_default('pythonbrew', 'develop')
|
||||||
|
|||||||
@@ -61,6 +61,17 @@ __pythonbrew_update()
|
|||||||
[[ $? == 0 ]] && __pythonbrew_reload
|
[[ $? == 0 ]] && __pythonbrew_reload
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__pythonbrew_venv()
|
||||||
|
{
|
||||||
|
command pythonbrew "$@"
|
||||||
|
if [[ $? == 0 ]] ; then
|
||||||
|
if [[ -s "$PATH_ETC/venv.run" ]] ; then
|
||||||
|
source "$PATH_ETC/venv.run"
|
||||||
|
cat /dev/null > "$PATH_ETC/venv.run"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
__pythonbrew_find_command()
|
__pythonbrew_find_command()
|
||||||
{
|
{
|
||||||
command_name=""
|
command_name=""
|
||||||
@@ -84,6 +95,7 @@ pythonbrew()
|
|||||||
switch) __pythonbrew_switch "$@" ;;
|
switch) __pythonbrew_switch "$@" ;;
|
||||||
off) __pythonbrew_off "$@" ;;
|
off) __pythonbrew_off "$@" ;;
|
||||||
update) __pythonbrew_update "$@" ;;
|
update) __pythonbrew_update "$@" ;;
|
||||||
|
venv) __pythonbrew_venv "$@" ;;
|
||||||
*) command pythonbrew "$@" ;;
|
*) command pythonbrew "$@" ;;
|
||||||
esac
|
esac
|
||||||
builtin hash -r
|
builtin hash -r
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
[distribute]
|
[distribute]
|
||||||
url = http://python-distribute.org/distribute_setup.py
|
url = http://python-distribute.org/distribute_setup.py
|
||||||
|
|
||||||
|
[bootstrap]
|
||||||
|
url = http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py
|
||||||
|
|
||||||
[pythonbrew]
|
[pythonbrew]
|
||||||
master = https://github.com/utahta/pythonbrew/tarball/master
|
master = https://github.com/utahta/pythonbrew/tarball/master
|
||||||
develop = https://github.com/utahta/pythonbrew/tarball/develop
|
develop = https://github.com/utahta/pythonbrew/tarball/develop
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from pythonbrew.define import PATH_BUILD, PATH_BIN, PATH_DISTS, PATH_PYTHONS,\
|
|||||||
PATH_ETC, PATH_SCRIPTS, PATH_SCRIPTS_PYTHONBREW,\
|
PATH_ETC, PATH_SCRIPTS, PATH_SCRIPTS_PYTHONBREW,\
|
||||||
PATH_SCRIPTS_PYTHONBREW_COMMANDS, PATH_BIN_PYTHONBREW,\
|
PATH_SCRIPTS_PYTHONBREW_COMMANDS, PATH_BIN_PYTHONBREW,\
|
||||||
ROOT, PATH_LOG, PATH_PATCHES, PATH_ETC_CONFIG,\
|
ROOT, PATH_LOG, PATH_PATCHES, PATH_ETC_CONFIG,\
|
||||||
PATH_SCRIPTS_PYTHONBREW_INSTALLER
|
PATH_SCRIPTS_PYTHONBREW_INSTALLER, PATH_VENVS
|
||||||
import stat
|
import stat
|
||||||
|
|
||||||
class PythonbrewInstaller(object):
|
class PythonbrewInstaller(object):
|
||||||
@@ -22,6 +22,7 @@ class PythonbrewInstaller(object):
|
|||||||
makedirs(PATH_ETC)
|
makedirs(PATH_ETC)
|
||||||
makedirs(PATH_BIN)
|
makedirs(PATH_BIN)
|
||||||
makedirs(PATH_LOG)
|
makedirs(PATH_LOG)
|
||||||
|
makedirs(PATH_VENVS)
|
||||||
|
|
||||||
# create script directories
|
# create script directories
|
||||||
rm_r(PATH_SCRIPTS)
|
rm_r(PATH_SCRIPTS)
|
||||||
|
|||||||
+42
-15
@@ -9,7 +9,8 @@ import platform
|
|||||||
import urllib
|
import urllib
|
||||||
import subprocess
|
import subprocess
|
||||||
import shlex
|
import shlex
|
||||||
from pythonbrew.define import PATH_BIN, PATH_ETC_CURRENT
|
import select
|
||||||
|
from pythonbrew.define import PATH_BIN, PATH_ETC_CURRENT, PATH_PYTHONS
|
||||||
from pythonbrew.exceptions import ShellCommandException
|
from pythonbrew.exceptions import ShellCommandException
|
||||||
from pythonbrew.log import logger
|
from pythonbrew.log import logger
|
||||||
|
|
||||||
@@ -93,12 +94,8 @@ def is_python32(version):
|
|||||||
return version >= '3.2' and version < '3.3'
|
return version >= '3.2' and version < '3.3'
|
||||||
|
|
||||||
def makedirs(path):
|
def makedirs(path):
|
||||||
try:
|
if not os.path.exists(path):
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
except OSError:
|
|
||||||
e = sys.exc_info()[1]
|
|
||||||
if errno.EEXIST != e.errno:
|
|
||||||
raise
|
|
||||||
|
|
||||||
def symlink(src, dst):
|
def symlink(src, dst):
|
||||||
try:
|
try:
|
||||||
@@ -212,12 +209,29 @@ def extract_downloadfile(content_type, download_file, target_dir):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_current_python_path():
|
def get_using_python_path():
|
||||||
"""return: python path or ''
|
|
||||||
"""
|
|
||||||
p = subprocess.Popen('command -v python', stdout=subprocess.PIPE, shell=True)
|
p = subprocess.Popen('command -v python', stdout=subprocess.PIPE, shell=True)
|
||||||
return to_str(p.communicate()[0].strip())
|
return to_str(p.communicate()[0].strip())
|
||||||
|
|
||||||
|
def get_using_python_pkgname():
|
||||||
|
"""return: Python-<VERSION> or None"""
|
||||||
|
path = get_using_python_path()
|
||||||
|
for d in sorted(os.listdir(PATH_PYTHONS)):
|
||||||
|
if path and os.path.samefile(path, os.path.join(PATH_PYTHONS, d, 'bin','python')):
|
||||||
|
return d
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_installed_pythons_pkgname():
|
||||||
|
"""Get the installed python versions list."""
|
||||||
|
return [d for d in sorted(os.listdir(PATH_PYTHONS))]
|
||||||
|
|
||||||
|
def is_installed(name):
|
||||||
|
pkgname = Package(name).name
|
||||||
|
pkgdir = os.path.join(PATH_PYTHONS, pkgname)
|
||||||
|
if not os.path.isdir(pkgdir):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def set_current_path(path):
|
def set_current_path(path):
|
||||||
fp = open(PATH_ETC_CURRENT, 'w')
|
fp = open(PATH_ETC_CURRENT, 'w')
|
||||||
fp.write('PATH_PYTHONBREW="%s"\n' % (path))
|
fp.write('PATH_PYTHONBREW="%s"\n' % (path))
|
||||||
@@ -254,6 +268,16 @@ def is_str(val):
|
|||||||
return isinstance(val, str)
|
return isinstance(val, str)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def bltin_any(iter):
|
||||||
|
try:
|
||||||
|
return any(iter)
|
||||||
|
except:
|
||||||
|
# python2.4
|
||||||
|
for it in iter:
|
||||||
|
if it:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
class Subprocess(object):
|
class Subprocess(object):
|
||||||
def __init__(self, log=None, cwd=None, verbose=False, debug=False):
|
def __init__(self, log=None, cwd=None, verbose=False, debug=False):
|
||||||
self._log = log
|
self._log = log
|
||||||
@@ -285,13 +309,16 @@ class Subprocess(object):
|
|||||||
fp = ((self._log and open(self._log, 'a')) or None)
|
fp = ((self._log and open(self._log, 'a')) or None)
|
||||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self._cwd)
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self._cwd)
|
||||||
while p.returncode is None:
|
while p.returncode is None:
|
||||||
|
while bltin_any(select.select([p.stdout], [], [])):
|
||||||
|
line = to_str(p.stdout.readline())
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
if self._verbose:
|
||||||
|
logger.info(line.strip())
|
||||||
|
if fp:
|
||||||
|
fp.write(line)
|
||||||
|
fp.flush()
|
||||||
p.poll()
|
p.poll()
|
||||||
line = to_str(p.stdout.readline())
|
|
||||||
if self._verbose:
|
|
||||||
logger.info(line.strip())
|
|
||||||
if fp:
|
|
||||||
fp.write(line)
|
|
||||||
fp.flush()
|
|
||||||
if fp:
|
if fp:
|
||||||
fp.close()
|
fp.close()
|
||||||
return p.returncode
|
return p.returncode
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
0.8
|
0.9
|
||||||
+2
-3
@@ -2,17 +2,16 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
PYTHONBREW_ROOT = '/tmp/pythonbrew.test'
|
PYTHONBREW_ROOT = '/tmp/pythonbrew.test'
|
||||||
TESTPY_FILE = '/tmp/pythonbrew_test.py'
|
|
||||||
TESTPY_VERSION = ['2.4.6', '2.5.5', '2.6.6', '3.2']
|
TESTPY_VERSION = ['2.4.6', '2.5.5', '2.6.6', '3.2']
|
||||||
def cleanall():
|
def cleanall():
|
||||||
if os.path.isdir(PYTHONBREW_ROOT):
|
if os.path.isdir(PYTHONBREW_ROOT):
|
||||||
shutil.rmtree(PYTHONBREW_ROOT)
|
shutil.rmtree(PYTHONBREW_ROOT)
|
||||||
if os.path.isfile(TESTPY_FILE):
|
|
||||||
os.remove(TESTPY_FILE)
|
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
os.environ['PYTHONBREW_ROOT'] = PYTHONBREW_ROOT
|
os.environ['PYTHONBREW_ROOT'] = PYTHONBREW_ROOT
|
||||||
cleanall()
|
cleanall()
|
||||||
|
from pythonbrew.installer import install_pythonbrew
|
||||||
|
install_pythonbrew()
|
||||||
|
|
||||||
def teardown():
|
def teardown():
|
||||||
cleanall()
|
cleanall()
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
def test_install_pythonbrew():
|
|
||||||
from pythonbrew.installer import install_pythonbrew
|
|
||||||
install_pythonbrew()
|
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
from tests import TESTPY_FILE
|
from tests import PYTHONBREW_ROOT
|
||||||
|
import os
|
||||||
|
|
||||||
|
TESTPY_FILE = os.path.join(PYTHONBREW_ROOT, 'etc', 'testfile.py')
|
||||||
|
|
||||||
class PyOptions(object):
|
class PyOptions(object):
|
||||||
pythons = []
|
pythons = []
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
from tests import PYTHONBREW_ROOT
|
||||||
|
import os
|
||||||
|
|
||||||
|
BUILDOUT_DIR = os.path.join(PYTHONBREW_ROOT, 'etc', 'buildout')
|
||||||
|
BUILDOUT_CONF = os.path.join(BUILDOUT_DIR, 'buildout.cfg')
|
||||||
|
|
||||||
|
def _create_buildout_cfg():
|
||||||
|
if not os.path.isdir(BUILDOUT_DIR):
|
||||||
|
os.makedirs(BUILDOUT_DIR)
|
||||||
|
fp = open(BUILDOUT_CONF, 'w')
|
||||||
|
fp.write("""[buildout]
|
||||||
|
parts = test
|
||||||
|
develop =
|
||||||
|
|
||||||
|
[test]
|
||||||
|
recipe =
|
||||||
|
eggs =""")
|
||||||
|
fp.close()
|
||||||
|
|
||||||
|
class BuildoutOptions(object):
|
||||||
|
python = '2.6.6'
|
||||||
|
|
||||||
|
def test_buildout():
|
||||||
|
from pythonbrew.commands.buildout import BuildoutCommand
|
||||||
|
|
||||||
|
# Runs the buildout
|
||||||
|
_create_buildout_cfg()
|
||||||
|
os.chdir(BUILDOUT_DIR)
|
||||||
|
c = BuildoutCommand()
|
||||||
|
c.run_command(BuildoutOptions(), [])
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
class VenvOptions(object):
|
||||||
|
python = '2.6.6'
|
||||||
|
all = False
|
||||||
|
|
||||||
|
def test_venv():
|
||||||
|
from pythonbrew.commands.venv import VenvCommand
|
||||||
|
c = VenvCommand()
|
||||||
|
c.run_command(VenvOptions(), ['create', 'aaa'])
|
||||||
|
c.run_command(VenvOptions(), ['list'])
|
||||||
|
c.run_command(VenvOptions(), ['use', 'aaa'])
|
||||||
|
c.run_command(VenvOptions(), ['delete', 'aaa'])
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
def test_clean():
|
||||||
|
from pythonbrew.commands.cleanup import CleanupCommand
|
||||||
|
c = CleanupCommand()
|
||||||
|
c.run_command(None, None)
|
||||||
Reference in New Issue
Block a user