diff options
author | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2012-09-14 13:25:22 +0200 |
---|---|---|
committer | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2012-09-14 13:25:22 +0200 |
commit | 4b316ba0b51d4a63cf7ad3523a3121c1b7276f2a (patch) | |
tree | 752b0295350c0f24841ec89f996ea85565c4e923 | |
parent | 5c08aad79af2458ad91e759a1b43c78baaf1a647 (diff) | |
download | pylint-git-4b316ba0b51d4a63cf7ad3523a3121c1b7276f2a.tar.gz |
create a console_scripts entry point to be used by easy_install, buildout and pip. Closes #103949
uniformize run interface and update licensing on the way
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | __init__.py | 34 | ||||
-rwxr-xr-x | bin/pylint | 5 | ||||
-rwxr-xr-x | bin/pylint-gui | 8 | ||||
-rwxr-xr-x | bin/pyreverse | 5 | ||||
-rwxr-xr-x | bin/symilar | 4 | ||||
-rw-r--r-- | checkers/similar.py | 9 | ||||
-rwxr-xr-x | epylint.py | 24 | ||||
-rw-r--r-- | gui.py | 18 | ||||
-rw-r--r-- | pyreverse/main.py | 21 | ||||
-rw-r--r-- | setup.py | 17 | ||||
-rw-r--r-- | test/test_similar.py | 34 |
12 files changed, 123 insertions, 59 deletions
@@ -17,6 +17,9 @@ ChangeLog for PyLint * #103656: fix W0231 false positive for missing call to object.__init__ (patch by lothiraldan@gmail.com) + * #103949: create a console_scripts entry point to be used by + easy_install, buildout and pip + * fix cross-interpreter issue (non compatible access to __builtins__) * stop including tests files in distribution, they causes crash when diff --git a/__init__.py b/__init__.py index 0c4bd134c..dfb4386bc 100644 --- a/__init__.py +++ b/__init__.py @@ -1,3 +1,6 @@ +# Copyright (c) 2003-2012 LOGILAB S.A. (Paris, FRANCE). +# http://www.logilab.fr/ -- mailto:contact@logilab.fr +# # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any later @@ -10,7 +13,32 @@ # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -""" Copyright (c) 2002-2008 LOGILAB S.A. (Paris, FRANCE). -http://www.logilab.fr/ -- mailto:contact@logilab.fr -""" +import sys + +def run_pylint(): + """run pylint""" + from pylint.lint import Run + Run(sys.argv[1:]) + +def run_pylint_gui(): + """run pylint-gui""" + try: + from pylint.gui import Run + Run(sys.argv[1:]) + except ImportError: + sys.exit('tkinter is not available') + +def run_epylint(): + """run pylint""" + from pylint.epylint import Run + Run() + +def run_pyreverse(): + """run pyreverse""" + from pylint.pyreverse.main import Run + Run(sys.argv[1:]) +def run_symilar(): + """run symilar""" + from pylint.checkers.similar import Run + Run(sys.argv[1:]) diff --git a/bin/pylint b/bin/pylint index e20e03135..e3e520f0c 100755 --- a/bin/pylint +++ b/bin/pylint @@ -1,4 +1,3 @@ #!/usr/bin/env python -import sys -from pylint import lint -lint.Run(sys.argv[1:]) +from pylint import run_pylint +run_pylint() diff --git a/bin/pylint-gui b/bin/pylint-gui index 025378fef..02c6c45b0 100755 --- a/bin/pylint-gui +++ b/bin/pylint-gui @@ -1,7 +1,3 @@ #!/usr/bin/env python -import sys -try: - from pylint import gui - gui.Run(sys.argv[1:]) -except ImportError: - sys.exit('tkinter is not available') +from pylint import run_pylint_gui +run_pylint_gui() diff --git a/bin/pyreverse b/bin/pyreverse index 7492c1f04..5d06bb4d2 100755 --- a/bin/pyreverse +++ b/bin/pyreverse @@ -1,4 +1,3 @@ #!/usr/bin/python -import sys -from pylint.pyreverse import main -main.Run(sys.argv[1:]) +from pylint import run_pyreverse +run_pyreverse() diff --git a/bin/symilar b/bin/symilar index 7ca139fe2..ef9446247 100755 --- a/bin/symilar +++ b/bin/symilar @@ -1,3 +1,3 @@ #!/usr/bin/env python -from pylint.checkers import similar -similar.run() +from pylint import run_symilar +run_symilar() diff --git a/checkers/similar.py b/checkers/similar.py index 1e38ed61e..2907e39dc 100644 --- a/checkers/similar.py +++ b/checkers/similar.py @@ -1,5 +1,5 @@ # pylint: disable=W0622 -# Copyright (c) 2004-2006 LOGILAB S.A. (Paris, FRANCE). +# Copyright (c) 2004-2012 LOGILAB S.A. (Paris, FRANCE). # http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This program is free software; you can redistribute it and/or modify it under @@ -16,8 +16,6 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """a similarities / code duplication command line tool and pylint checker """ -from __future__ import generators - import sys from itertools import izip @@ -306,7 +304,7 @@ def usage(status=0): [-i|--ignore-comments] file1...' sys.exit(status) -def run(argv=None): +def Run(argv=None): """standalone command line access point""" if argv is None: argv = sys.argv[1:] @@ -329,6 +327,7 @@ def run(argv=None): for filename in args: sim.append_stream(filename, open(filename)) sim.run() + sys.exit(0) if __name__ == '__main__': - run() + Run() diff --git a/epylint.py b/epylint.py index 780cf79a7..db2ed82f1 100755 --- a/epylint.py +++ b/epylint.py @@ -1,5 +1,19 @@ -#!/usr/bin/env python # -*- coding: utf-8; mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=python:et:sw=4:ts=4:sts=4 +# Copyright (c) 2003-2012 LOGILAB S.A. (Paris, FRANCE). +# http://www.logilab.fr/ -- mailto:contact@logilab.fr +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """Emacs and Flymake compatible Pylint. This script is for integration with emacs and is compatible with flymake mode. @@ -91,9 +105,6 @@ def lint(filename): process.wait() return process.returncode -def Run(): - sys.exit(lint(sys.argv[1])) - def py_run(command_options='', return_std=False, stdout=None, stderr=None, script='epylint'): @@ -146,6 +157,9 @@ def py_run(command_options='', return_std=False, stdout=None, stderr=None, return (p.stdout, p.stderr) +def Run(): + sys.exit(lint(sys.argv[1])) + if __name__ == '__main__': - lint(sys.argv[1]) + Run() @@ -1,3 +1,18 @@ +# Copyright (c) 2003-2012 LOGILAB S.A. (Paris, FRANCE). +# http://www.logilab.fr/ -- mailto:contact@logilab.fr +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """Tkinker gui for pylint""" import os @@ -444,9 +459,10 @@ def Run(args): """launch pylint gui from args""" if args: print 'USAGE: pylint-gui\n launch a simple pylint gui using Tk' - return + sys.exit(1) gui = LintGui() gui.mainloop() + sys.exit(0) if __name__ == '__main__': Run(sys.argv[1:]) diff --git a/pyreverse/main.py b/pyreverse/main.py index da80bd63a..4e4458c46 100644 --- a/pyreverse/main.py +++ b/pyreverse/main.py @@ -1,4 +1,4 @@ -# # Copyright (c) 2000-2010 LOGILAB S.A. (Paris, FRANCE). +# # Copyright (c) 2000-2012 LOGILAB S.A. (Paris, FRANCE). # http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This program is free software; you can redistribute it and/or modify it under @@ -16,7 +16,7 @@ """ %prog [options] <packages> - create UML diagrams for classes and modules in <packages> + create UML diagrams for classes and modules in <packages> """ import sys, os @@ -31,7 +31,7 @@ from pylint.pyreverse.utils import insert_default_options OPTIONS = ( ("filter-mode", dict(short='f', default='PUB_ONLY', dest='mode', type='string', - action='store', metavar='<mode>', + action='store', metavar='<mode>', help="""filter attributes and functions according to <mode>. Correct modes are : 'PUB_ONLY' filter all non public attributes @@ -81,10 +81,10 @@ this disables -f values")), help="create a *.<format> output file if format available.")), ) # FIXME : quiet mode -#( ('quiet', +#( ('quiet', #dict(help='run quietly', action='store_true', short='q')), ) -class PyreverseCommand(ConfigurationMixIn): +class Run(ConfigurationMixIn): """base class providing common behaviour for pyreverse commands""" options = OPTIONS @@ -95,13 +95,13 @@ class PyreverseCommand(ConfigurationMixIn): self.manager = ASTNGManager() self.register_options_provider(self.manager) args = self.load_command_line_configuration() - self.run(args) + sys.exit(self.run(args)) def run(self, args): """checking arguments and run project""" if not args: print self.help() - return + return 1 # insert current working directory to the python path to recognize # dependencies to local modules even if cwd is not in the PYTHONPATH sys.path.insert(0, os.getcwd()) @@ -117,13 +117,8 @@ class PyreverseCommand(ConfigurationMixIn): writer.VCGWriter(self.config).write(diadefs) else: writer.DotWriter(self.config).write(diadefs) + return 0 -class Run: - """pyreverse main class""" - def __init__(self, args): - """run pyreverse""" - PyreverseCommand(args) - if __name__ == '__main__': Run(sys.argv[1:]) @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # pylint: disable=W0404,W0622,W0704,W0613 -# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This file is part of pylint. @@ -139,6 +139,7 @@ class MyInstallLib(install_lib.install_lib): shutil.rmtree(dest, ignore_errors=True) shutil.copytree(directory, dest) + def install(**kwargs): """setup entry point""" if USE_SETUPTOOLS: @@ -156,9 +157,17 @@ def install(**kwargs): else: kwargs['package_dir'] = {modname : '.'} packages = [modname] + get_packages(os.getcwd(), modname) - if USE_SETUPTOOLS and install_requires: - kwargs['install_requires'] = install_requires - kwargs['dependency_links'] = dependency_links + if USE_SETUPTOOLS: + if install_requires: + kwargs['install_requires'] = install_requires + kwargs['dependency_links'] = dependency_links + kwargs['entry_points'] = {'console_scripts': [ + 'pylint = pylint:run_pylint', + 'pylint-gui = pylint:run_pylint_gui', + 'epylint = pylint:run_epylint', + 'pyreverse = pylint:run_pyreverse', + 'symilar = pylint:run_symilar', + ]} kwargs['packages'] = packages return setup(name = distname, version = version, diff --git a/test/test_similar.py b/test/test_similar.py index 68aff835d..91299df73 100644 --- a/test/test_similar.py +++ b/test/test_similar.py @@ -15,8 +15,12 @@ class SimilarTC(TestCase): def test_ignore_comments(self): sys.stdout = StringIO() try: - similar.run(['--ignore-comments', SIMILAR1, SIMILAR2]) + similar.Run(['--ignore-comments', SIMILAR1, SIMILAR2]) + except SystemExit, ex: + self.assertEqual(ex.code, 0) output = sys.stdout.getvalue() + else: + self.fail('not system exit') finally: sys.stdout = sys.__stdout__ self.assertMultiLineEqual(output.strip(), (""" @@ -37,8 +41,12 @@ TOTAL lines=38 duplicates=7 percent=18.42 def test_dont_ignore_comments(self): sys.stdout = StringIO() try: - similar.run([SIMILAR1, SIMILAR2]) + similar.Run([SIMILAR1, SIMILAR2]) + except SystemExit, ex: + self.assertEqual(ex.code, 0) output = sys.stdout.getvalue() + else: + self.fail('not system exit') finally: sys.stdout = sys.__stdout__ self.assertMultiLineEqual(output.strip(), """ @@ -48,24 +56,22 @@ TOTAL lines=38 duplicates=0 percent=0.00 def test_help(self): sys.stdout = StringIO() try: - try: - similar.run(['--help']) - except SystemExit, ex: - self.assertEqual(ex.code, 0) - else: - self.fail() + similar.Run(['--help']) + except SystemExit, ex: + self.assertEqual(ex.code, 0) + else: + self.fail('not system exit') finally: sys.stdout = sys.__stdout__ def test_no_args(self): sys.stdout = StringIO() try: - try: - similar.run([]) - except SystemExit, ex: - self.assertEqual(ex.code, 1) - else: - self.fail() + similar.Run([]) + except SystemExit, ex: + self.assertEqual(ex.code, 1) + else: + self.fail('not system exit') finally: sys.stdout = sys.__stdout__ |