diff --git a/.gitignore b/.gitignore index 2a9cb21..00039fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,53 @@ -.tox -coverage +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ diff --git a/.travis.yml b/.travis.yml index 5e562a0..c668537 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,9 @@ language: python python: - - 2.5 - - 2.6 - 2.7 + - 3.4 # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors install: - pip install . --use-mirrors # command to run tests, e.g. python setup.py test -script: py.test . - +script: python setup.py test diff --git a/README.rst b/README.rst index 1ab0a88..589dcab 100644 --- a/README.rst +++ b/README.rst @@ -2,6 +2,25 @@ VIM Pdb integration =================== +Latest + + +Use ``pip3 install git+https://github.com/byronyi/vimpdb`` to install the +package. + +Use ``python setup.py test`` to test the package if you would like to +participate in the development. (Requires package ``pytest``) + +This package is awesome but not active since 2011. Let's port it into py3k! + +Remember: put the following config into your ``~/.vimpdbrc``! +:: + [vimpdb] + vim_client_script = mvim + vim_server_script = mvim + server_name = VIM + port = 6666 + Abstract ======== diff --git a/manual_test.py b/manual_test.py index d9436aa..d3a2475 100644 --- a/manual_test.py +++ b/manual_test.py @@ -1,5 +1,8 @@ +from __future__ import print_function + + def output(arg): - print "MANUAL: arg=", arg + print("MANUAL: arg={}".format(arg)) def main(): diff --git a/setup.py b/setup.py index 9fdeb4b..a55316e 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,26 @@ from setuptools import setup, find_packages +import sys +from setuptools.command.test import test as TestCommand + + +class PyTest(TestCommand): + user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")] + + def initialize_options(self): + TestCommand.initialize_options(self) + self.pytest_args = ['.'] + + def finalize_options(self): + TestCommand.finalize_options(self) + self.test_args = [] + self.test_suite = True + + def run_tests(self): + #import here, cause outside the eggs aren't loaded + import pytest + errno = pytest.main(self.pytest_args) + sys.exit(errno) + version = '0.4.6dev' @@ -25,13 +47,21 @@ author_email='gotcha@bubblenet.be', url='http://github.com/gotcha/vimpdb', license='MIT', - packages=find_packages('src'), - package_dir={'': 'src'}, include_package_data=True, + packages=find_packages(), zip_safe=False, install_requires=[ 'vim_bridge', + 'six' + ], + tests_require=[ + 'mock', + 'pytest' ], + package_data = { + 'vimpdb': ['vimpdb.vim'] + }, + cmdclass = {'test': PyTest}, entry_points=""" # -*- Entry points: -*- """, diff --git a/src/vimpdb/tests/scripts/compatiblevim.py b/src/vimpdb/tests/scripts/compatiblevim.py deleted file mode 100644 index 4fd38c8..0000000 --- a/src/vimpdb/tests/scripts/compatiblevim.py +++ /dev/null @@ -1 +0,0 @@ -print "+clientserver +python" diff --git a/src/vimpdb/tests/scripts/nopython.py b/src/vimpdb/tests/scripts/nopython.py deleted file mode 100644 index 195eaba..0000000 --- a/src/vimpdb/tests/scripts/nopython.py +++ /dev/null @@ -1 +0,0 @@ -print "+clientserver -python" diff --git a/src/vimpdb/tests/scripts/noserver.py b/src/vimpdb/tests/scripts/noserver.py deleted file mode 100644 index 5f40c37..0000000 --- a/src/vimpdb/tests/scripts/noserver.py +++ /dev/null @@ -1 +0,0 @@ -print "-clientserver +python" diff --git a/src/vimpdb/tests/scripts/rightserverlist.py b/src/vimpdb/tests/scripts/rightserverlist.py deleted file mode 100644 index 1fb3be1..0000000 --- a/src/vimpdb/tests/scripts/rightserverlist.py +++ /dev/null @@ -1 +0,0 @@ -print "VIM" diff --git a/src/vimpdb/tests/scripts/wrongserverlist.py b/src/vimpdb/tests/scripts/wrongserverlist.py deleted file mode 100644 index 1c7fc09..0000000 --- a/src/vimpdb/tests/scripts/wrongserverlist.py +++ /dev/null @@ -1 +0,0 @@ -print "WRONG" diff --git a/src/vimpdb/tests/__init__.py b/tests/__init__.py similarity index 100% rename from src/vimpdb/tests/__init__.py rename to tests/__init__.py diff --git a/src/vimpdb/tests/scripts/communicator.py b/tests/scripts/communicator.py similarity index 66% rename from src/vimpdb/tests/scripts/communicator.py rename to tests/scripts/communicator.py index fb9abcf..c8a6a7d 100644 --- a/src/vimpdb/tests/scripts/communicator.py +++ b/tests/scripts/communicator.py @@ -1,5 +1,9 @@ +from __future__ import print_function + import optparse import sys + + parser = optparse.OptionParser() parser.add_option('--servername', dest="server_name") parser.add_option('--remote-expr', dest="expr") @@ -9,6 +13,6 @@ parser.parse_args(sys.argv) if hasattr(parser.values, 'expr'): - print parser.values.expr, parser.values.server_name + print(parser.values.expr, parser.values.server_name) if hasattr(parser.values, 'command'): - print parser.values.command, parser.values.server_name + print(parser.values.command, parser.values.server_name) diff --git a/tests/scripts/compatiblevim.py b/tests/scripts/compatiblevim.py new file mode 100644 index 0000000..056422e --- /dev/null +++ b/tests/scripts/compatiblevim.py @@ -0,0 +1,4 @@ +from __future__ import print_function + + +print("+clientserver +python") diff --git a/src/vimpdb/tests/scripts/emptyserverlist.py b/tests/scripts/emptyserverlist.py similarity index 100% rename from src/vimpdb/tests/scripts/emptyserverlist.py rename to tests/scripts/emptyserverlist.py diff --git a/src/vimpdb/tests/scripts/incompatiblevim.py b/tests/scripts/incompatiblevim.py similarity index 100% rename from src/vimpdb/tests/scripts/incompatiblevim.py rename to tests/scripts/incompatiblevim.py diff --git a/tests/scripts/nopython.py b/tests/scripts/nopython.py new file mode 100644 index 0000000..04cdfc2 --- /dev/null +++ b/tests/scripts/nopython.py @@ -0,0 +1,4 @@ +from __future__ import print_function + + +print("+clientserver -python") diff --git a/tests/scripts/noserver.py b/tests/scripts/noserver.py new file mode 100644 index 0000000..b204d5c --- /dev/null +++ b/tests/scripts/noserver.py @@ -0,0 +1,4 @@ +from __future__ import print_function + + +print("-clientserver +python") diff --git a/src/vimpdb/tests/scripts/returncode.py b/tests/scripts/returncode.py similarity index 100% rename from src/vimpdb/tests/scripts/returncode.py rename to tests/scripts/returncode.py diff --git a/tests/scripts/rightserverlist.py b/tests/scripts/rightserverlist.py new file mode 100644 index 0000000..8d04081 --- /dev/null +++ b/tests/scripts/rightserverlist.py @@ -0,0 +1,4 @@ +from __future__ import print_function + + +print("VIM") diff --git a/tests/scripts/wrongserverlist.py b/tests/scripts/wrongserverlist.py new file mode 100644 index 0000000..c9ee86e --- /dev/null +++ b/tests/scripts/wrongserverlist.py @@ -0,0 +1,4 @@ +from __future__ import print_function + + +print("WRONG") diff --git a/src/vimpdb/tests/test_config.py b/tests/test_config.py similarity index 100% rename from src/vimpdb/tests/test_config.py rename to tests/test_config.py diff --git a/src/vimpdb/tests/test_debugger.py b/tests/test_debugger.py similarity index 95% rename from src/vimpdb/tests/test_debugger.py rename to tests/test_debugger.py index 8c0805d..d97bb68 100644 --- a/src/vimpdb/tests/test_debugger.py +++ b/tests/test_debugger.py @@ -49,7 +49,12 @@ def test_hook(mocked_trace_dispatch): from vimpdb.debugger import hook from vimpdb.debugger import SwitcherToVimpdb - class Klass: + # A work around for Python bug: + # http://bugs.python.org/issue672115 + class Base(object): + pass + + class Klass(Base): def trace_dispatch(self): pass @@ -74,7 +79,6 @@ class Klass: def do_vim(self): pass - hook(Klass) assert not mocked_setupMethod.called diff --git a/src/vimpdb/tests/test_proxy.py b/tests/test_proxy.py similarity index 100% rename from src/vimpdb/tests/test_proxy.py rename to tests/test_proxy.py diff --git a/src/vimpdb/__init__.py b/vimpdb/__init__.py similarity index 100% rename from src/vimpdb/__init__.py rename to vimpdb/__init__.py diff --git a/src/vimpdb/bbbconfig.py b/vimpdb/bbbconfig.py similarity index 90% rename from src/vimpdb/bbbconfig.py rename to vimpdb/bbbconfig.py index 7160212..4b889ad 100644 --- a/src/vimpdb/bbbconfig.py +++ b/vimpdb/bbbconfig.py @@ -1,17 +1,17 @@ import os -import ConfigParser +from six.moves import configparser from vimpdb import errors def read_from_file_4_0(filename, klass): - parser = ConfigParser.RawConfigParser() + parser = configparser.RawConfigParser() parser.read(filename) if not parser.has_section('vimpdb'): raise errors.BadRCFile('[vimpdb] section is missing in "%s"' % - filename) + filename) error_msg = ("'%s' option is missing from section [vimpdb] in " - + "'" + filename + "'.") + + "'" + filename + "'.") if parser.has_option('vimpdb', 'script'): vim_client_script = parser.get('vimpdb', 'script') else: diff --git a/src/vimpdb/config.py b/vimpdb/config.py similarity index 93% rename from src/vimpdb/config.py rename to vimpdb/config.py index cdcf67d..3cd8d2a 100755 --- a/src/vimpdb/config.py +++ b/vimpdb/config.py @@ -3,7 +3,7 @@ import os.path import logging import time -import ConfigParser +from six.moves import configparser import subprocess from vimpdb import bbbconfig @@ -85,7 +85,7 @@ def get_configuration(filename=RCNAME): mustWrite = False try: config = read_from_file(filename, Config) - except errors.BadRCFile, e: + except errors.BadRCFile as e: try: config_4_0 = bbbconfig.read_from_file_4_0(filename, Config) except errors.BadRCFile: @@ -107,7 +107,7 @@ def getRawConfiguration(filename=RCNAME): def read_from_file(filename, klass): - parser = ConfigParser.RawConfigParser() + parser = configparser.RawConfigParser() parser.read(filename) if not parser.has_section('vimpdb'): raise errors.BadRCFile('[vimpdb] section is missing in "%s"' % @@ -135,7 +135,7 @@ def read_option(parser, name, error_msg): def write_to_file(filename, config): - parser = ConfigParser.RawConfigParser() + parser = configparser.RawConfigParser() parser.add_section('vimpdb') parser.set('vimpdb', 'vim_client_script', config.scripts[CLIENT]) parser.set('vimpdb', 'vim_server_script', config.scripts[SERVER]) @@ -150,14 +150,14 @@ def getCommandOutputPosix(parts): try: p = subprocess.Popen(parts, stdout=subprocess.PIPE) return_code = p.wait() - except OSError, e: + except OSError as e: message = 'When trying to run "%s" : %s' % (" ".join(parts), e.args[1]) raise OSError(e.args[0], message) if return_code: raise errors.ReturnCodeError(return_code, " ".join(parts)) child_stdout = p.stdout output = child_stdout.read() - return output.strip() + return output.decode().strip() NO_SERVER_SUPPORT = ("'%s' launches a VIM instance without " @@ -191,15 +191,15 @@ def checkConfiguration(self): def _checkConfiguration(self): try: self.check_clientserver_support(CLIENT) - except ValueError, e: - print e.args[0] + except ValueError as e: + print(e.args[0]) self.query_script(CLIENT) return False try: self.check_python_support() #XXX catch WindowsError - except OSError, e: - print e.args[1] + except OSError as e: + print(e.args[1]) server_script = self.scripts[SERVER] if server_script == DEFAULT_SERVER_SCRIPT: print ("with the default VIM server script (%s)." @@ -209,20 +209,20 @@ def _checkConfiguration(self): "(%s)." % server_script) self.query_script(SERVER) return False - except ValueError, e: - print e.args[0] + except ValueError as e: + print(e.args[0]) self.query_script(SERVER) return False try: self.check_server_clientserver_support() - except ValueError, e: - print e.args[0] + except ValueError as e: + print(e.args[0]) self.query_script(SERVER) return False try: self.check_serverlist() - except ValueError, e: - print e.args[0] + except ValueError as e: + print(e.args[0]) self.query_servername() return False return True @@ -240,11 +240,11 @@ def get_serverlist(self): command = self.build_command(CLIENT, '--serverlist') try: return self.commandParser(command) - except errors.ReturnCodeError, e: + except errors.ReturnCodeError as e: return_code = e.args[0] command = e.args[1] raise ValueError(RETURN_CODE % (command, return_code)) - except OSError, e: + except OSError as e: raise ValueError(str(e)) def serverAvailable(self): @@ -260,11 +260,11 @@ def check_serverlist(self): if not self.serverAvailable(): try: self.launch_vim_server() - except errors.ReturnCodeError, e: + except errors.ReturnCodeError as e: return_code = e.args[0] command = e.args[1] raise ValueError(RETURN_CODE % (command, return_code)) - except OSError, e: + except OSError as e: raise ValueError(str(e)) timeout = 0.0 INCREMENT = 0.1 @@ -284,11 +284,11 @@ def get_vim_version(self, script_type): try: command = self.build_command(script_type, '--version') return self.commandParser(command) - except errors.ReturnCodeError, e: + except errors.ReturnCodeError as e: return_code = e.args[0] command = e.args[1] raise ValueError(RETURN_CODE % (command, return_code)) - except OSError, e: + except OSError as e: raise ValueError(str(e)) def check_clientserver_support(self, script_type): @@ -331,7 +331,7 @@ def query_servername(self): def getCommandOutputWindows(parts): try: - return getCommandOutputPosix(parts) + return getCommandOutputPosix(parts).decode('utf-8') except WindowsError: raise errors.ReturnCodeError(1, " ".join(parts)) diff --git a/src/vimpdb/controller.py b/vimpdb/controller.py similarity index 100% rename from src/vimpdb/controller.py rename to vimpdb/controller.py diff --git a/src/vimpdb/debugger.py b/vimpdb/debugger.py similarity index 95% rename from src/vimpdb/debugger.py rename to vimpdb/debugger.py index db372cf..01d74e3 100755 --- a/src/vimpdb/debugger.py +++ b/vimpdb/debugger.py @@ -1,7 +1,9 @@ +from __future__ import print_function + import pdb from pdb import Pdb import sys -import StringIO +from six.moves import StringIO import pprint from vimpdb import proxy from vimpdb import config @@ -108,7 +110,7 @@ def cmdloop(self): stop = None self.preloop() while not stop: - line = self.from_vim.waitFor(self) + line = self.from_vim.waitFor(self).decode() line = self.precmd(line) stop = self.onecmd(line) stop = self.postcmd(stop, line) @@ -129,9 +131,9 @@ def showFileAtLine(self): self.to_vim.displayLocals(watches) def formatLocals(self): - stream = StringIO.StringIO() + stream = StringIO() locals = self.curframe.f_locals - keys = locals.keys() + keys = list(locals.keys()) keys.sort() for key in keys: stream.write('%s = \n' % key) @@ -145,7 +147,7 @@ def formatLocals(self): # stdout captures to send back to Vim def capture_sys_stdout(self): self.stdout = sys.stdout - sys.stdout = StringIO.StringIO() + sys.stdout = StringIO() self.capturing = True def stop_capture_sys_stdout(self): @@ -157,7 +159,7 @@ def stop_capture_sys_stdout(self): # stdout captures to send back to Vim def capture_self_stdout(self): self.initial_stdout = self.stdout - self.stdout = StringIO.StringIO() + self.stdout = StringIO() self.capturing = True def stop_capture_self_stdout(self): @@ -216,7 +218,7 @@ def default(self, line): def make_instance(): configuration = config.get_configuration() communicator = proxy.Communicator(configuration.vim_client_script, - configuration.server_name) + configuration.server_name) to_vim = proxy.ProxyToVim(communicator) from_vim = proxy.ProxyFromVim(configuration.port) return VimPdb(to_vim, from_vim) @@ -284,7 +286,7 @@ def hook(klass): if not hasattr(klass, 'do_vim'): setupMethod(klass, trace_dispatch) - klass.__bases__ += (SwitcherToVimpdb, ) + klass.__bases__ = (SwitcherToVimpdb, ) + klass.__bases__ def get_hooked_pdb(): diff --git a/src/vimpdb/errors.py b/vimpdb/errors.py similarity index 100% rename from src/vimpdb/errors.py rename to vimpdb/errors.py diff --git a/src/vimpdb/proxy.py b/vimpdb/proxy.py similarity index 94% rename from src/vimpdb/proxy.py rename to vimpdb/proxy.py index 342a64b..e9ec9b2 100755 --- a/src/vimpdb/proxy.py +++ b/vimpdb/proxy.py @@ -29,20 +29,21 @@ def prepare_subprocess(self, *args): def _remote_expr(self, expr): parts = self.prepare_subprocess('--servername', - self.server_name, "--remote-expr", expr) + self.server_name, "--remote-expr", expr) p = subprocess.Popen(parts, stdout=subprocess.PIPE) return_code = p.wait() if return_code: raise errors.RemoteUnavailable() child_stdout = p.stdout output = child_stdout.read() - return output.strip() + return output.decode().strip() def _send(self, command): # add ':' to hide last keys sent in VIM command-line command = ''.join((command, ':')) parts = self.prepare_subprocess('--servername', - self.server_name, "--remote-send", command) + self.server_name, + "--remote-send", command) return_code = subprocess.call(parts) if return_code: raise errors.RemoteUnavailable() @@ -106,7 +107,7 @@ def _showFileAtLine(self, filename, lineno): filename = filename.replace('\\', '/') self.setupRemote() self._send(':call PDB_show_file_at_line("%s", "%d")' - % (filename, lineno)) + % (filename, lineno)) def _expr(self, expr): config.logger.debug("expr: %s" % expr) diff --git a/src/vimpdb/vimpdb.vim b/vimpdb/vimpdb.vim similarity index 100% rename from src/vimpdb/vimpdb.vim rename to vimpdb/vimpdb.vim