diff --git a/.gitignore b/.gitignore index 1e2444e..1306759 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ pythonbrew.egg-info dist __pycache__ +*.swp diff --git a/ChangeLog b/ChangeLog index b6e3837..f61a9d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +* 0.9 + - Added `buildout` command. + - Added `venv` command. + * 0.8 - Fixed issue #21 Added Ubuntu 11.04(Natty) support - 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 - Added --no-test 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 - Improved symlink command diff --git a/PKG-INFO b/PKG-INFO index 6ade579..e872a7e 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -51,7 +51,7 @@ Use the specified python in current shell:: Runs a named python file against specified and/or all pythons:: 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 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 -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:: pythonbrew version @@ -125,12 +137,20 @@ update off 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 Show version. -See more details below:: - +See more details below: pythonbrew help LICENCE diff --git a/README.rst b/README.rst index 6ade579..e872a7e 100644 --- a/README.rst +++ b/README.rst @@ -51,7 +51,7 @@ Use the specified python in current shell:: Runs a named python file against specified and/or all pythons:: 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 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 -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:: pythonbrew version @@ -125,12 +137,20 @@ update off 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 Show version. -See more details below:: - +See more details below: pythonbrew help LICENCE diff --git a/pythonbrew/commands/buildout.py b/pythonbrew/commands/buildout.py new file mode 100644 index 0000000..81ef50a --- /dev/null +++ b/pythonbrew/commands/buildout.py @@ -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() diff --git a/pythonbrew/commands/list.py b/pythonbrew/commands/list.py index 1c9f76d..d9fb902 100644 --- a/pythonbrew/commands/list.py +++ b/pythonbrew/commands/list.py @@ -3,7 +3,8 @@ import re from pythonbrew.basecommand import Command from pythonbrew.define import PYTHON_VERSION_URL, LATEST_VERSIONS_OF_PYTHON,\ 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 class ListCommand(Command): @@ -36,15 +37,14 @@ class ListCommand(Command): def installed(self, options, args): logger.info('# installed pythons') - cur = get_current_python_path() + cur = get_using_python_pkgname() 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) - cur = None else: logger.info('%s' % d) - if cur: - logger.info('%s (*)' % cur) + if not cur: + logger.info('%s (*)' % get_using_python_path()) def available_install(self, options, args): logger.info('# available install pythons') diff --git a/pythonbrew/commands/switch.py b/pythonbrew/commands/switch.py index 2fcfc29..d25e5c5 100644 --- a/pythonbrew/commands/switch.py +++ b/pythonbrew/commands/switch.py @@ -2,7 +2,7 @@ import os import sys from pythonbrew.basecommand import Command 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 class SwitchCommand(Command): @@ -16,11 +16,10 @@ class SwitchCommand(Command): sys.exit(1) pkg = Package(args[0]) pkgname = pkg.name - pkgdir = os.path.join(PATH_PYTHONS, pkgname) - if not os.path.isdir(pkgdir): + if not is_installed(pkgname): logger.info("`%s` is not installed." % pkgname) 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)) diff --git a/pythonbrew/commands/uninstall.py b/pythonbrew/commands/uninstall.py index 19f506d..d04e53c 100644 --- a/pythonbrew/commands/uninstall.py +++ b/pythonbrew/commands/uninstall.py @@ -1,7 +1,8 @@ import os from pythonbrew.basecommand import Command -from pythonbrew.define import PATH_PYTHONS, PATH_BIN -from pythonbrew.util import off, rm_r, Package, get_current_python_path, unlink +from pythonbrew.define import PATH_PYTHONS, PATH_BIN, PATH_VENVS +from pythonbrew.util import off, rm_r, Package, get_using_python_pkgname, unlink,\ + is_installed from pythonbrew.log import logger class UninstallCommand(Command): @@ -16,10 +17,11 @@ class UninstallCommand(Command): pkg = Package(arg) pkgname = pkg.name 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) continue - if get_current_python_path() == os.path.join(pkgpath,'bin','python'): + if get_using_python_pkgname() == pkgname: off() for d in os.listdir(PATH_BIN): # remove symlink @@ -30,6 +32,7 @@ class UninstallCommand(Command): if os.path.isfile(tgtpath) and os.path.samefile(path, tgtpath): unlink(path) rm_r(pkgpath) + rm_r(venvpath) else: self.parser.print_help() diff --git a/pythonbrew/commands/venv.py b/pythonbrew/commands/venv.py new file mode 100644 index 0000000..8ac4e4f --- /dev/null +++ b/pythonbrew/commands/venv.py @@ -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 \'.') + 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 \'.') + 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 ' )") + 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() diff --git a/pythonbrew/define.py b/pythonbrew/define.py index 593d2a7..bf4dee5 100644 --- a/pythonbrew/define.py +++ b/pythonbrew/define.py @@ -6,7 +6,7 @@ except: import configparser as ConfigParser # pythonbrew version -VERSION = "0.8" +VERSION = "0.9" # pythonbrew root path 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_BIN = os.path.join(ROOT,"bin") PATH_LOG = os.path.join(ROOT,"log") +PATH_VENVS = os.path.join(ROOT, "venvs") PATH_SCRIPTS = os.path.join(ROOT,"scripts") PATH_SCRIPTS_PYTHONBREW = os.path.join(PATH_SCRIPTS,"pythonbrew") 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_TEMP = os.path.join(PATH_ETC,'temp') PATH_ETC_CONFIG = os.path.join(PATH_ETC,'config.cfg') +PATH_ETC_VENV = os.path.join(PATH_ETC, 'venv.run') # read config.cfg config = ConfigParser.SafeConfigParser() @@ -53,6 +55,9 @@ def _get_or_default(section, option, default=''): # setuptools download DISTRIBUTE_SETUP_DLSITE = _get_or_default('distribute', 'url') +# buildout bootstrap download +BOOTSTRAP_DLSITE = _get_or_default('bootstrap', 'url') + # pythonbrew download PYTHONBREW_UPDATE_URL_MASTER = _get_or_default('pythonbrew', 'master') PYTHONBREW_UPDATE_URL_DEVELOP = _get_or_default('pythonbrew', 'develop') diff --git a/pythonbrew/etc/bashrc b/pythonbrew/etc/bashrc index 6639033..82b73c4 100644 --- a/pythonbrew/etc/bashrc +++ b/pythonbrew/etc/bashrc @@ -61,6 +61,17 @@ __pythonbrew_update() [[ $? == 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() { command_name="" @@ -84,6 +95,7 @@ pythonbrew() switch) __pythonbrew_switch "$@" ;; off) __pythonbrew_off "$@" ;; update) __pythonbrew_update "$@" ;; + venv) __pythonbrew_venv "$@" ;; *) command pythonbrew "$@" ;; esac builtin hash -r diff --git a/pythonbrew/etc/config.cfg b/pythonbrew/etc/config.cfg index dbdc698..1a16836 100644 --- a/pythonbrew/etc/config.cfg +++ b/pythonbrew/etc/config.cfg @@ -1,6 +1,9 @@ [distribute] url = http://python-distribute.org/distribute_setup.py +[bootstrap] +url = http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py + [pythonbrew] master = https://github.com/utahta/pythonbrew/tarball/master develop = https://github.com/utahta/pythonbrew/tarball/develop diff --git a/pythonbrew/installer/pythonbrewinstaller.py b/pythonbrew/installer/pythonbrewinstaller.py index bc17bc3..14c23bc 100644 --- a/pythonbrew/installer/pythonbrewinstaller.py +++ b/pythonbrew/installer/pythonbrewinstaller.py @@ -7,7 +7,7 @@ from pythonbrew.define import PATH_BUILD, PATH_BIN, PATH_DISTS, PATH_PYTHONS,\ PATH_ETC, PATH_SCRIPTS, PATH_SCRIPTS_PYTHONBREW,\ PATH_SCRIPTS_PYTHONBREW_COMMANDS, PATH_BIN_PYTHONBREW,\ ROOT, PATH_LOG, PATH_PATCHES, PATH_ETC_CONFIG,\ - PATH_SCRIPTS_PYTHONBREW_INSTALLER + PATH_SCRIPTS_PYTHONBREW_INSTALLER, PATH_VENVS import stat class PythonbrewInstaller(object): @@ -22,6 +22,7 @@ class PythonbrewInstaller(object): makedirs(PATH_ETC) makedirs(PATH_BIN) makedirs(PATH_LOG) + makedirs(PATH_VENVS) # create script directories rm_r(PATH_SCRIPTS) diff --git a/pythonbrew/util.py b/pythonbrew/util.py index 457e936..a29ae85 100644 --- a/pythonbrew/util.py +++ b/pythonbrew/util.py @@ -9,7 +9,8 @@ import platform import urllib import subprocess 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.log import logger @@ -93,12 +94,8 @@ def is_python32(version): return version >= '3.2' and version < '3.3' def makedirs(path): - try: + if not os.path.exists(path): os.makedirs(path) - except OSError: - e = sys.exc_info()[1] - if errno.EEXIST != e.errno: - raise def symlink(src, dst): try: @@ -212,12 +209,29 @@ def extract_downloadfile(content_type, download_file, target_dir): return False return True -def get_current_python_path(): - """return: python path or '' - """ +def get_using_python_path(): p = subprocess.Popen('command -v python', stdout=subprocess.PIPE, shell=True) return to_str(p.communicate()[0].strip()) +def get_using_python_pkgname(): + """return: Python- 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): fp = open(PATH_ETC_CURRENT, 'w') fp.write('PATH_PYTHONBREW="%s"\n' % (path)) @@ -254,6 +268,16 @@ def is_str(val): return isinstance(val, str) 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): def __init__(self, log=None, cwd=None, verbose=False, debug=False): self._log = log @@ -285,13 +309,16 @@ class Subprocess(object): 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: + 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() - line = to_str(p.stdout.readline()) - if self._verbose: - logger.info(line.strip()) - if fp: - fp.write(line) - fp.flush() if fp: fp.close() return p.returncode diff --git a/stable-version.txt b/stable-version.txt index ce609ca..d893d08 100644 --- a/stable-version.txt +++ b/stable-version.txt @@ -1 +1 @@ -0.8 \ No newline at end of file +0.9 \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py index e6eeae9..2e311ed 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,17 +2,16 @@ import os import shutil PYTHONBREW_ROOT = '/tmp/pythonbrew.test' -TESTPY_FILE = '/tmp/pythonbrew_test.py' 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) - if os.path.isfile(TESTPY_FILE): - os.remove(TESTPY_FILE) def setup(): os.environ['PYTHONBREW_ROOT'] = PYTHONBREW_ROOT cleanall() + from pythonbrew.installer import install_pythonbrew + install_pythonbrew() def teardown(): cleanall() diff --git a/tests/test_00_install_pythonbrew.py b/tests/test_00_install_pythonbrew.py deleted file mode 100644 index 30d0471..0000000 --- a/tests/test_00_install_pythonbrew.py +++ /dev/null @@ -1,3 +0,0 @@ -def test_install_pythonbrew(): - from pythonbrew.installer import install_pythonbrew - install_pythonbrew() \ No newline at end of file diff --git a/tests/test_01_update.py b/tests/test_00_update.py similarity index 100% rename from tests/test_01_update.py rename to tests/test_00_update.py diff --git a/tests/test_02_help.py b/tests/test_01_help.py similarity index 100% rename from tests/test_02_help.py rename to tests/test_01_help.py diff --git a/tests/test_03_version.py b/tests/test_02_version.py similarity index 100% rename from tests/test_03_version.py rename to tests/test_02_version.py diff --git a/tests/test_04_install.py b/tests/test_03_install.py similarity index 100% rename from tests/test_04_install.py rename to tests/test_03_install.py diff --git a/tests/test_05_switch.py b/tests/test_04_switch.py similarity index 100% rename from tests/test_05_switch.py rename to tests/test_04_switch.py diff --git a/tests/test_06_use.py b/tests/test_05_use.py similarity index 100% rename from tests/test_06_use.py rename to tests/test_05_use.py diff --git a/tests/test_07_off.py b/tests/test_06_off.py similarity index 100% rename from tests/test_07_off.py rename to tests/test_06_off.py diff --git a/tests/test_08_list.py b/tests/test_07_list.py similarity index 100% rename from tests/test_08_list.py rename to tests/test_07_list.py diff --git a/tests/test_09_py.py b/tests/test_08_py.py similarity index 76% rename from tests/test_09_py.py rename to tests/test_08_py.py index 77a0705..07031e6 100644 --- a/tests/test_09_py.py +++ b/tests/test_08_py.py @@ -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): pythons = [] diff --git a/tests/test_09_buildout.py b/tests/test_09_buildout.py new file mode 100644 index 0000000..221757a --- /dev/null +++ b/tests/test_09_buildout.py @@ -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(), []) + \ No newline at end of file diff --git a/tests/test_10_venv.py b/tests/test_10_venv.py new file mode 100644 index 0000000..eb5f352 --- /dev/null +++ b/tests/test_10_venv.py @@ -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']) diff --git a/tests/test_10_uninstall.py b/tests/test_11_uninstall.py similarity index 100% rename from tests/test_10_uninstall.py rename to tests/test_11_uninstall.py diff --git a/tests/test_12_cleanup.py b/tests/test_12_cleanup.py new file mode 100644 index 0000000..3549334 --- /dev/null +++ b/tests/test_12_cleanup.py @@ -0,0 +1,4 @@ +def test_clean(): + from pythonbrew.commands.cleanup import CleanupCommand + c = CleanupCommand() + c.run_command(None, None)