mirror of
https://github.com/kennethreitz-archive/python-build.git
synced 2026-06-05 07:16:14 +00:00
v1.1
This commit is contained in:
@@ -9,3 +9,4 @@ pythonbrew.egg-info
|
||||
dist
|
||||
__pycache__
|
||||
*.swp
|
||||
.idea
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
* 1.1
|
||||
- Added --framework, --universal and --static options to install command.
|
||||
|
||||
* 1.0
|
||||
- Added systemwide install support. (issue #31)
|
||||
- Fixed issue #41 Handle venv binary with the symlink command.
|
||||
|
||||
@@ -173,6 +173,11 @@ See more details below
|
||||
Changelog
|
||||
=========
|
||||
|
||||
1.1 (2011-08-29)
|
||||
----------------
|
||||
|
||||
- Added --framework, --universal and --static options to install command.
|
||||
|
||||
1.0 (2011-08-08)
|
||||
----------------
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ from pythonbrew.basecommand import Command
|
||||
from pythonbrew.installer.pythoninstaller import PythonInstaller,\
|
||||
PythonInstallerMacOSX
|
||||
from pythonbrew.util import is_macosx
|
||||
from pythonbrew.exceptions import UnknownVersionException,\
|
||||
AlreadyInstalledException, NotSupportedVersionException
|
||||
|
||||
class InstallCommand(Command):
|
||||
name = "install"
|
||||
@@ -61,7 +59,28 @@ class InstallCommand(Command):
|
||||
default=0,
|
||||
help="Enable parallel make."
|
||||
)
|
||||
|
||||
self.parser.add_option(
|
||||
"--framework",
|
||||
dest="framework",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Build (MacOSX|Darwin) framework."
|
||||
)
|
||||
self.parser.add_option(
|
||||
"--universal",
|
||||
dest="universal",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Build for both 32 & 64 bit Intel."
|
||||
)
|
||||
self.parser.add_option(
|
||||
"--static",
|
||||
dest="static",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Build static libraries."
|
||||
)
|
||||
|
||||
def run_command(self, options, args):
|
||||
if not args:
|
||||
self.parser.print_help()
|
||||
@@ -74,11 +93,7 @@ class InstallCommand(Command):
|
||||
else:
|
||||
p = PythonInstaller(arg, options)
|
||||
p.install()
|
||||
except UnknownVersionException:
|
||||
except:
|
||||
continue
|
||||
except AlreadyInstalledException:
|
||||
continue
|
||||
except NotSupportedVersionException:
|
||||
continue
|
||||
|
||||
|
||||
InstallCommand()
|
||||
|
||||
@@ -6,7 +6,7 @@ from pythonbrew.define import PATH_DISTS, VERSION, ROOT,\
|
||||
from pythonbrew.log import logger
|
||||
from pythonbrew.downloader import Downloader, get_pythonbrew_update_url,\
|
||||
get_stable_version, get_headerinfo_from_url
|
||||
from pythonbrew.util import rm_r, extract_downloadfile, Link, is_gzip, Subprocess
|
||||
from pythonbrew.util import rm_r, extract_downloadfile, Link, is_gzip, Subprocess, Version
|
||||
|
||||
class UpdateCommand(Command):
|
||||
name = "update"
|
||||
@@ -75,7 +75,7 @@ class UpdateCommand(Command):
|
||||
else:
|
||||
version = get_stable_version()
|
||||
# check for version
|
||||
if not options.force and version <= VERSION:
|
||||
if not options.force and Version(version) <= VERSION:
|
||||
logger.info("You are already running the installed latest version of pythonbrew.")
|
||||
return
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ except:
|
||||
import configparser as ConfigParser
|
||||
|
||||
# pythonbrew version
|
||||
VERSION = "1.0"
|
||||
VERSION = "1.1"
|
||||
|
||||
# pythonbrew installer root path
|
||||
INSTALLER_ROOT = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
@@ -181,5 +181,7 @@ latest = True
|
||||
|
||||
[Python-3.2]
|
||||
url = http://www.python.org/ftp/python/3.2/Python-3.2.tgz
|
||||
latest = True
|
||||
|
||||
[Python-3.2.1]
|
||||
url = http://www.python.org/ftp/python/3.2.1/Python-3.2.1.tgz
|
||||
latest = True
|
||||
|
||||
@@ -2,12 +2,13 @@ import os
|
||||
import sys
|
||||
import shutil
|
||||
import mimetypes
|
||||
import re
|
||||
from pythonbrew.util import makedirs, symlink, Package, is_url, Link,\
|
||||
unlink, is_html, Subprocess, rm_r,\
|
||||
is_python25, is_python24, is_python26, is_python27,\
|
||||
extract_downloadfile, is_archive_file, path_to_fileurl, is_file,\
|
||||
fileurl_to_path, is_python30, is_python31, is_python32,\
|
||||
get_macosx_deployment_target
|
||||
get_macosx_deployment_target, Version
|
||||
from pythonbrew.define import PATH_BUILD, PATH_DISTS, PATH_PYTHONS,\
|
||||
ROOT, PATH_LOG, DISTRIBUTE_SETUP_DLSITE,\
|
||||
PATH_PATCHES_MACOSX_PYTHON25, PATH_PATCHES_MACOSX_PYTHON24,\
|
||||
@@ -16,7 +17,7 @@ from pythonbrew.downloader import get_python_version_url, Downloader,\
|
||||
get_headerinfo_from_url
|
||||
from pythonbrew.log import logger
|
||||
from pythonbrew.exceptions import UnknownVersionException,\
|
||||
AlreadyInstalledException, NotSupportedVersionException
|
||||
NotSupportedVersionException
|
||||
|
||||
class PythonInstaller(object):
|
||||
"""Python installer
|
||||
@@ -45,11 +46,21 @@ class PythonInstaller(object):
|
||||
self.install_dir = os.path.join(PATH_PYTHONS, pkg.name)
|
||||
self.build_dir = os.path.join(PATH_BUILD, pkg.name)
|
||||
self.download_file = os.path.join(PATH_DISTS, filename)
|
||||
|
||||
|
||||
self.options = options
|
||||
self.logfile = os.path.join(PATH_LOG, 'build.log')
|
||||
self.patches = []
|
||||
|
||||
if Version(self.pkg.version) >= '3.1':
|
||||
self.configure_options = ['--with-computed-gotos']
|
||||
else:
|
||||
self.configure_options = []
|
||||
|
||||
def install(self):
|
||||
# cleanup
|
||||
if os.path.isdir(self.build_dir):
|
||||
shutil.rmtree(self.build_dir)
|
||||
|
||||
|
||||
# get content type.
|
||||
if is_file(self.download_url):
|
||||
path = fileurl_to_path(self.download_url)
|
||||
@@ -61,16 +72,11 @@ class PythonInstaller(object):
|
||||
# note: maybe got 404 or 503 http status code.
|
||||
logger.error("Invalid content-type: `%s`" % self.content_type)
|
||||
return
|
||||
|
||||
self.options = options
|
||||
self.logfile = os.path.join(PATH_LOG, 'build.log')
|
||||
self.configure_options = ''
|
||||
self.patches = []
|
||||
|
||||
def install(self):
|
||||
if os.path.isdir(self.install_dir):
|
||||
logger.info("You are already installed `%s`" % self.pkg.name)
|
||||
raise AlreadyInstalledException
|
||||
return
|
||||
|
||||
self.download_and_extract()
|
||||
logger.info("\nThis could take a while. You can run the following command on another shell to track the status:")
|
||||
logger.info(" tail -f %s\n" % self.logfile)
|
||||
@@ -114,7 +120,7 @@ class PythonInstaller(object):
|
||||
sys.exit(1)
|
||||
|
||||
def patch(self):
|
||||
version = self.pkg.version
|
||||
version = Version(self.pkg.version)
|
||||
# for ubuntu 11.04(Natty)
|
||||
if is_python24(version):
|
||||
patch_dir = os.path.join(PATH_PATCHES_ALL, "python24")
|
||||
@@ -170,7 +176,10 @@ class PythonInstaller(object):
|
||||
|
||||
def configure(self):
|
||||
s = Subprocess(log=self.logfile, cwd=self.build_dir, verbose=self.options.verbose)
|
||||
s.check_call("./configure --prefix=%s %s %s" % (self.install_dir, self.options.configure, self.configure_options))
|
||||
cmd = "./configure --prefix=%s %s %s" % (self.install_dir, self.options.configure, ' '.join(self.configure_options))
|
||||
if self.options.verbose:
|
||||
logger.log(cmd)
|
||||
s.check_call(cmd)
|
||||
|
||||
def make(self):
|
||||
jobs = self.options.jobs
|
||||
@@ -185,7 +194,7 @@ class PythonInstaller(object):
|
||||
s.check_call("make test")
|
||||
|
||||
def make_install(self):
|
||||
version = self.pkg.version
|
||||
version = Version(self.pkg.version)
|
||||
if version == "1.5.2" or version == "1.6.1":
|
||||
makedirs(self.install_dir)
|
||||
s = Subprocess(log=self.logfile, cwd=self.build_dir, verbose=self.options.verbose)
|
||||
@@ -193,14 +202,27 @@ class PythonInstaller(object):
|
||||
|
||||
def symlink(self):
|
||||
install_dir = os.path.realpath(self.install_dir)
|
||||
if self.options.framework:
|
||||
# create symlink bin -> /path/to/Frameworks/Python.framework/Versions/?.?/bin
|
||||
bin_dir = os.path.join(install_dir, 'bin')
|
||||
if os.path.exists(bin_dir):
|
||||
rm_r(bin_dir)
|
||||
m = re.match(r'\d\.\d', self.pkg.version)
|
||||
if m:
|
||||
version = m.group(0)
|
||||
symlink(os.path.join(install_dir,'Frameworks','Python.framework','Versions',version,'bin'),
|
||||
os.path.join(bin_dir))
|
||||
|
||||
path_python = os.path.join(install_dir,'bin','python')
|
||||
if not os.path.isfile(path_python):
|
||||
path_python3 = os.path.join(install_dir,'bin','python3')
|
||||
path_python3_0 = os.path.join(install_dir,'bin','python3.0')
|
||||
if os.path.isfile(path_python3):
|
||||
symlink(path_python3, path_python)
|
||||
elif os.path.isfile(path_python3_0):
|
||||
symlink(path_python3_0, path_python)
|
||||
src = None
|
||||
for d in os.listdir(os.path.join(install_dir,'bin')):
|
||||
if re.match(r'python\d\.\d', d):
|
||||
src = d
|
||||
break
|
||||
if src:
|
||||
path_src = os.path.join(install_dir,'bin',src)
|
||||
symlink(path_src, path_python)
|
||||
|
||||
def install_setuptools(self):
|
||||
options = self.options
|
||||
@@ -237,14 +259,26 @@ class PythonInstallerMacOSX(PythonInstaller):
|
||||
super(PythonInstallerMacOSX, self).__init__(arg, options)
|
||||
|
||||
# check for version
|
||||
version = self.pkg.version
|
||||
version = Version(self.pkg.version)
|
||||
if version < '2.6' and (version != '2.4.6' and version < '2.5.5'):
|
||||
logger.error("`%s` is not supported on MacOSX Snow Leopard" % self.pkg.name)
|
||||
raise NotSupportedVersionException
|
||||
# set configure options
|
||||
target = get_macosx_deployment_target()
|
||||
if target:
|
||||
self.configure_options = 'MACOSX_DEPLOYMENT_TARGET=%s' % target
|
||||
self.configure_options.append('MACOSX_DEPLOYMENT_TARGET=%s' % target)
|
||||
|
||||
# set build options
|
||||
if options.framework and options.static:
|
||||
logger.error("Can't specify both framework and static.")
|
||||
raise Exception
|
||||
if options.framework:
|
||||
self.configure_options.append('--enable-framework=%s' % os.path.join(self.install_dir, 'Frameworks'))
|
||||
elif not options.static:
|
||||
self.configure_options.append('--enable-shared')
|
||||
if options.universal:
|
||||
self.configure_options.append('--enable-universalsdk=/')
|
||||
self.configure_options.append('--with-universal-archs=intel')
|
||||
|
||||
# note: skip `make test` to avoid hanging test_threading.
|
||||
if is_python25(version) or is_python24(version):
|
||||
@@ -252,7 +286,7 @@ class PythonInstallerMacOSX(PythonInstaller):
|
||||
|
||||
def patch(self):
|
||||
# note: want an interface to the source patching functionality. like a patchperl.
|
||||
version = self.pkg.version
|
||||
version = Version(self.pkg.version)
|
||||
if is_python24(version):
|
||||
patch_dir = PATH_PATCHES_MACOSX_PYTHON24
|
||||
self._add_patches_to_list(patch_dir, ['patch-configure', 'patch-Makefile.pre.in',
|
||||
|
||||
+86
-9
@@ -72,26 +72,31 @@ def get_macosx_deployment_target():
|
||||
return m.group(1)
|
||||
return None
|
||||
|
||||
def _py_version_cmp(v, v1, v2):
|
||||
if is_str(v):
|
||||
v = Version(v)
|
||||
return v >= v1 and v < v2
|
||||
|
||||
def is_python24(version):
|
||||
return version >= '2.4' and version < '2.5'
|
||||
return _py_version_cmp(version, '2.4', '2.5')
|
||||
|
||||
def is_python25(version):
|
||||
return version >= '2.5' and version < '2.6'
|
||||
return _py_version_cmp(version, '2.5', '2.6')
|
||||
|
||||
def is_python26(version):
|
||||
return version >= '2.6' and version < '2.7'
|
||||
return _py_version_cmp(version, '2.6', '2.7')
|
||||
|
||||
def is_python27(version):
|
||||
return version >= '2.7' and version < '2.8'
|
||||
return _py_version_cmp(version, '2.7', '2.8')
|
||||
|
||||
def is_python30(version):
|
||||
return version >= '3.0' and version < '3.1'
|
||||
return _py_version_cmp(version, '3.0', '3.1')
|
||||
|
||||
def is_python31(version):
|
||||
return version >= '3.1' and version < '3.2'
|
||||
return _py_version_cmp(version, '3.1', '3.2')
|
||||
|
||||
def is_python32(version):
|
||||
return version >= '3.2' and version < '3.3'
|
||||
return _py_version_cmp(version, '3.2', '3.3')
|
||||
|
||||
def makedirs(path):
|
||||
if not os.path.exists(path):
|
||||
@@ -220,6 +225,8 @@ def get_using_python_pkgname():
|
||||
"""return: Python-<VERSION> or None"""
|
||||
path = get_using_python_path()
|
||||
for d in sorted(os.listdir(PATH_PYTHONS)):
|
||||
if not os.path.exists(os.path.join(PATH_PYTHONS, d, 'bin','python')):
|
||||
continue
|
||||
if path and os.path.samefile(path, os.path.join(PATH_PYTHONS, d, 'bin','python')):
|
||||
return d
|
||||
return None
|
||||
@@ -286,6 +293,9 @@ def bltin_any(iter):
|
||||
return True
|
||||
return False
|
||||
|
||||
#-----------------------------
|
||||
# class
|
||||
#-----------------------------
|
||||
class Subprocess(object):
|
||||
def __init__(self, log=None, cwd=None, verbose=False, debug=False):
|
||||
self._log = log
|
||||
@@ -355,7 +365,7 @@ class Package(object):
|
||||
if alias:
|
||||
self.name = 'Python-%s' % alias
|
||||
self.alias = alias
|
||||
|
||||
|
||||
class Link(object):
|
||||
def __init__(self, url):
|
||||
self._url = url
|
||||
@@ -374,4 +384,71 @@ class Link(object):
|
||||
def base_url(self):
|
||||
return posixpath.basename(self._url.split('#', 1)[0].split('?', 1)[0])
|
||||
|
||||
|
||||
class Version(object):
|
||||
"""version compare
|
||||
"""
|
||||
def __init__(self, v):
|
||||
self._version = v
|
||||
self._p = self._parse_version(v)
|
||||
|
||||
def __lt__(self, o):
|
||||
if is_str(o):
|
||||
o = self._parse_version(o)
|
||||
return self._p < o
|
||||
|
||||
def __le__(self, o):
|
||||
if is_str(o):
|
||||
o = self._parse_version(o)
|
||||
return self._p <= o
|
||||
|
||||
def __eq__(self, o):
|
||||
if is_str(o):
|
||||
o = self._parse_version(o)
|
||||
return self._p == o
|
||||
|
||||
def __ne__(self, o):
|
||||
if is_str(o):
|
||||
o = self._parse_version(o)
|
||||
return self._p != o
|
||||
|
||||
def __gt__(self, o):
|
||||
if is_str(o):
|
||||
o = self._parse_version(o)
|
||||
return self._p > o
|
||||
|
||||
def __ge__(self, o):
|
||||
if is_str(o):
|
||||
o = self._parse_version(o)
|
||||
return self._p >= o
|
||||
|
||||
def _parse_version(self, s):
|
||||
"""see pkg_resouce.parse_version
|
||||
"""
|
||||
component_re = re.compile(r'(\d+ | [a-z]+ | \.| -)', re.VERBOSE)
|
||||
replace = {'pre':'c', 'preview':'c','-':'final-','rc':'c','dev':'@'}.get
|
||||
|
||||
def _parse_version_parts(s):
|
||||
for part in component_re.split(s):
|
||||
part = replace(part,part)
|
||||
if not part or part=='.':
|
||||
continue
|
||||
if part[:1] in '0123456789':
|
||||
yield part.zfill(8) # pad for numeric comparison
|
||||
else:
|
||||
yield '*'+part
|
||||
yield '*final' # ensure that alpha/beta/candidate are before final
|
||||
|
||||
parts = []
|
||||
for part in _parse_version_parts(s.lower()):
|
||||
if part.startswith('*'):
|
||||
if part<'*final': # remove '-' before a prerelease tag
|
||||
while parts and parts[-1]=='*final-': parts.pop()
|
||||
# remove trailing zeros from each series of numeric parts
|
||||
while parts and parts[-1]=='00000000':
|
||||
parts.pop()
|
||||
parts.append(part)
|
||||
return tuple(parts)
|
||||
|
||||
def __repr__(self):
|
||||
return self._version
|
||||
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
1.0
|
||||
1.1
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
PYTHONBREW_ROOT = '/tmp/pythonbrew.test'
|
||||
TESTPY_VERSION = ['2.4.6', '2.5.5', '2.6.6', '3.2']
|
||||
def cleanall():
|
||||
if os.path.isdir(PYTHONBREW_ROOT):
|
||||
shutil.rmtree(PYTHONBREW_ROOT)
|
||||
|
||||
def setup():
|
||||
os.environ['PYTHONBREW_ROOT'] = PYTHONBREW_ROOT
|
||||
cleanall()
|
||||
from pythonbrew.installer import install_pythonbrew
|
||||
install_pythonbrew()
|
||||
|
||||
def teardown():
|
||||
cleanall()
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
class UpdateOptions(object):
|
||||
master = False
|
||||
develop = False
|
||||
config = False
|
||||
force = False
|
||||
|
||||
def test_update():
|
||||
from pythonbrew.commands.update import UpdateCommand
|
||||
c = UpdateCommand()
|
||||
c.run_command(UpdateOptions(), None)
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
def test_help():
|
||||
from pythonbrew.commands.help import HelpCommand
|
||||
c = HelpCommand()
|
||||
c.run_command(None, None)
|
||||
@@ -1,4 +0,0 @@
|
||||
def test_version():
|
||||
from pythonbrew.commands.version import VersionCommand
|
||||
c = VersionCommand()
|
||||
c.run_command(None, None)
|
||||
@@ -1,18 +0,0 @@
|
||||
from tests import TESTPY_VERSION
|
||||
|
||||
class InstallOptions(object):
|
||||
force = True
|
||||
no_test = True
|
||||
verbose = False
|
||||
configure = ""
|
||||
no_setuptools = False
|
||||
alias = None
|
||||
jobs = 2
|
||||
|
||||
def test_install():
|
||||
from pythonbrew.commands.install import InstallCommand
|
||||
py_version = TESTPY_VERSION.pop(0)
|
||||
c = InstallCommand()
|
||||
c.run_command(InstallOptions(), [py_version]) # pybrew install -f -j2 2.4.6
|
||||
c.run_command(InstallOptions(), TESTPY_VERSION) # pybrew install -f -j2 2.5.6 2.6.6 3.2
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
from tests import TESTPY_VERSION
|
||||
|
||||
def test_switch():
|
||||
from pythonbrew.commands.switch import SwitchCommand
|
||||
for py_version in TESTPY_VERSION:
|
||||
c = SwitchCommand()
|
||||
c.run_command(None, [py_version])
|
||||
@@ -1,7 +0,0 @@
|
||||
from tests import TESTPY_VERSION
|
||||
|
||||
def test_use():
|
||||
from pythonbrew.commands.use import UseCommand
|
||||
for py_version in TESTPY_VERSION:
|
||||
c = UseCommand()
|
||||
c.run_command(None, [py_version])
|
||||
@@ -1,4 +0,0 @@
|
||||
def test_off():
|
||||
from pythonbrew.commands.off import OffCommand
|
||||
c = OffCommand()
|
||||
c.run_command(None, None)
|
||||
@@ -1,8 +0,0 @@
|
||||
class ListOptions(object):
|
||||
all_versions = False
|
||||
known = False
|
||||
|
||||
def test_list():
|
||||
from pythonbrew.commands.list import ListCommand
|
||||
c = ListCommand()
|
||||
c.run_command(ListOptions(), None)
|
||||
@@ -1,22 +0,0 @@
|
||||
from tests import PYTHONBREW_ROOT
|
||||
import os
|
||||
|
||||
TESTPY_FILE = os.path.join(PYTHONBREW_ROOT, 'etc', 'testfile.py')
|
||||
|
||||
class PyOptions(object):
|
||||
pythons = []
|
||||
verbose = False
|
||||
bin = "python"
|
||||
options = ""
|
||||
|
||||
def _create_pyfile():
|
||||
fp = open(TESTPY_FILE, 'w')
|
||||
fp.write("print('test')")
|
||||
fp.close()
|
||||
|
||||
def test_py():
|
||||
from pythonbrew.commands.py import PyCommand
|
||||
_create_pyfile()
|
||||
|
||||
c = PyCommand()
|
||||
c.run_command(PyOptions(), [TESTPY_FILE])
|
||||
@@ -1,31 +0,0 @@
|
||||
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(), [])
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
class VenvOptions(object):
|
||||
python = '2.6.6'
|
||||
all = False
|
||||
no_site_packages = False
|
||||
|
||||
def test_venv():
|
||||
import os
|
||||
from pythonbrew.commands.venv import VenvCommand
|
||||
from pythonbrew.util import Subprocess
|
||||
from pythonbrew.define import PATH_HOME_ETC_VENV
|
||||
s = Subprocess()
|
||||
c = VenvCommand()
|
||||
c.run_command(VenvOptions(), ['init'])
|
||||
c.run_command(VenvOptions(), ['create', 'aaa'])
|
||||
s.shell('source %s' % PATH_HOME_ETC_VENV)
|
||||
c.run_command(VenvOptions(), ['list'])
|
||||
c.run_command(VenvOptions(), ['use', 'aaa'])
|
||||
c.run_command(VenvOptions(), ['delete', 'aaa'])
|
||||
s.shell('source %s' % PATH_HOME_ETC_VENV)
|
||||
# finish
|
||||
os.unlink(PATH_HOME_ETC_VENV)
|
||||
@@ -1,7 +0,0 @@
|
||||
from tests import TESTPY_VERSION
|
||||
|
||||
def test_uninstall():
|
||||
from pythonbrew.commands.uninstall import UninstallCommand
|
||||
for py_version in TESTPY_VERSION:
|
||||
c = UninstallCommand()
|
||||
c.run_command(None, [py_version])
|
||||
@@ -1,4 +0,0 @@
|
||||
def test_clean():
|
||||
from pythonbrew.commands.cleanup import CleanupCommand
|
||||
c = CleanupCommand()
|
||||
c.run_command(None, None)
|
||||
@@ -0,0 +1,138 @@
|
||||
# coding=utf-8
|
||||
#---------------------------------------------------------------------------
|
||||
# Copyright 2011 utahta
|
||||
#---------------------------------------------------------------------------
|
||||
import os
|
||||
import shutil
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Settings
|
||||
#---------------------------------------------------------------------------
|
||||
PYTHONBREW_ROOT = '/tmp/pythonbrew.test'
|
||||
TESTPY_VERSION = ['2.4.6', '2.5.5', '2.6.6', '3.2']
|
||||
|
||||
def _cleanall():
|
||||
if os.path.isdir(PYTHONBREW_ROOT):
|
||||
shutil.rmtree(PYTHONBREW_ROOT)
|
||||
|
||||
def _install_pythonbrew():
|
||||
from pythonbrew.installer import install_pythonbrew
|
||||
install_pythonbrew()
|
||||
|
||||
def setup():
|
||||
os.environ['PYTHONBREW_ROOT'] = PYTHONBREW_ROOT
|
||||
_cleanall()
|
||||
_install_pythonbrew()
|
||||
|
||||
def teardown():
|
||||
_cleanall()
|
||||
|
||||
class Options(object):
|
||||
def __init__(self, opts):
|
||||
for (k,v) in opts.items():
|
||||
setattr(self, k, v)
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Test
|
||||
#---------------------------------------------------------------------------
|
||||
def test_00_update():
|
||||
from pythonbrew.commands.update import UpdateCommand
|
||||
c = UpdateCommand()
|
||||
c.run_command(Options({'master':False, 'develop':False, 'config':False, 'force':False}),
|
||||
None)
|
||||
|
||||
def test_01_help():
|
||||
from pythonbrew.commands.help import HelpCommand
|
||||
c = HelpCommand()
|
||||
c.run_command(None, None)
|
||||
|
||||
def test_02_version():
|
||||
from pythonbrew.commands.version import VersionCommand
|
||||
c = VersionCommand()
|
||||
c.run_command(None, None)
|
||||
|
||||
def test_03_install():
|
||||
from pythonbrew.commands.install import InstallCommand
|
||||
py_version = TESTPY_VERSION.pop(0)
|
||||
o = Options({'force':True, 'no_test':True, 'verbose':False, 'configure':"",
|
||||
'no_setuptools': False, 'alias':None, 'jobs':2,
|
||||
'framework':False, 'universal':False, 'static':False})
|
||||
c = InstallCommand()
|
||||
c.run_command(o, [py_version]) # pybrew install -f -j2 2.4.6
|
||||
c.run_command(o, TESTPY_VERSION) # pybrew install -f -j2 2.5.6 2.6.6 3.2
|
||||
|
||||
def test_04_switch():
|
||||
from pythonbrew.commands.switch import SwitchCommand
|
||||
for py_version in TESTPY_VERSION:
|
||||
c = SwitchCommand()
|
||||
c.run_command(None, [py_version])
|
||||
|
||||
def test_05_use():
|
||||
from pythonbrew.commands.use import UseCommand
|
||||
for py_version in TESTPY_VERSION:
|
||||
c = UseCommand()
|
||||
c.run_command(None, [py_version])
|
||||
|
||||
def test_06_off():
|
||||
from pythonbrew.commands.off import OffCommand
|
||||
c = OffCommand()
|
||||
c.run_command(None, None)
|
||||
|
||||
def test_07_list():
|
||||
from pythonbrew.commands.list import ListCommand
|
||||
c = ListCommand()
|
||||
c.run_command(Options({'all_versions':False, 'known':False}),
|
||||
None)
|
||||
|
||||
def test_08_py():
|
||||
from pythonbrew.commands.py import PyCommand
|
||||
TESTPY_FILE = os.path.join(PYTHONBREW_ROOT, 'etc', 'testfile.py')
|
||||
fp = open(TESTPY_FILE, 'w')
|
||||
fp.write("print('test')")
|
||||
fp.close()
|
||||
# Runs the python script
|
||||
c = PyCommand()
|
||||
c.run_command(Options({'pythons':[], 'verbose':False, 'bin':"python", 'options':""}),
|
||||
[TESTPY_FILE])
|
||||
|
||||
def test_09_buildout():
|
||||
from pythonbrew.commands.buildout import BuildoutCommand
|
||||
BUILDOUT_DIR = os.path.join(PYTHONBREW_ROOT, 'etc', 'buildout')
|
||||
BUILDOUT_CONF = os.path.join(BUILDOUT_DIR, '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()
|
||||
# Runs the buildout
|
||||
os.chdir(BUILDOUT_DIR)
|
||||
c = BuildoutCommand()
|
||||
c.run_command(Options({'python':'2.6.6'}), [])
|
||||
|
||||
def test_10_venv():
|
||||
from pythonbrew.commands.venv import VenvCommand
|
||||
c = VenvCommand()
|
||||
o = Options({'python':'2.6.6', 'all':False, 'no_site_packages':False})
|
||||
c.run_command(o, ['init'])
|
||||
c.run_command(o, ['create', 'aaa'])
|
||||
c.run_command(o, ['list'])
|
||||
c.run_command(o, ['use', 'aaa'])
|
||||
c.run_command(o, ['delete', 'aaa'])
|
||||
|
||||
def test_11_uninstall():
|
||||
from pythonbrew.commands.uninstall import UninstallCommand
|
||||
for py_version in TESTPY_VERSION:
|
||||
c = UninstallCommand()
|
||||
c.run_command(None, [py_version])
|
||||
|
||||
def test_12_clean():
|
||||
from pythonbrew.commands.cleanup import CleanupCommand
|
||||
c = CleanupCommand()
|
||||
c.run_command(None, None)
|
||||
|
||||
Reference in New Issue
Block a user