From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 020C7139696 for ; Thu, 16 Feb 2017 21:24:45 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1BFC721C039; Thu, 16 Feb 2017 21:24:44 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id DFF8321C039 for ; Thu, 16 Feb 2017 21:24:43 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id BCECB341026 for ; Thu, 16 Feb 2017 21:24:42 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 5B6674A3D for ; Thu, 16 Feb 2017 21:24:41 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1487280098.e97d33dc96730d91c2070f2dc9aab8477dd0445a.vapier@gentoo> Subject: [gentoo-commits] proj/pax-utils:master commit in: / X-VCS-Repository: proj/pax-utils X-VCS-Files: .pylintrc lddtree.py pylint X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: e97d33dc96730d91c2070f2dc9aab8477dd0445a X-VCS-Branch: master Date: Thu, 16 Feb 2017 21:24:41 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 5e94d62c-84c0-4018-8c6c-b44e2934d434 X-Archives-Hash: cf436b01b505a95c16622eed51841232 commit: e97d33dc96730d91c2070f2dc9aab8477dd0445a Author: Mike Frysinger gentoo org> AuthorDate: Thu Feb 16 21:21:38 2017 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Thu Feb 16 21:21:38 2017 +0000 URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=e97d33dc pylint: add a helper to keep python code clean Fix up some lddtree logic at the same time so it's warning free. .pylintrc | 34 ++++++++++++++++++++++++++++++++++ lddtree.py | 16 +++++++++++----- pylint | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 5 deletions(-) diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..b58abfa --- /dev/null +++ b/.pylintrc @@ -0,0 +1,34 @@ +[MESSAGES CONTROL] +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifier separated by comma (,) or put this option +# multiple times (only on the command line, not in the configuration file where +# it should appear only once). +disable= + too-many-lines, + too-many-branches, + too-many-statements, + too-few-public-methods, + too-many-instance-attributes, + too-many-public-methods, + too-many-locals, + too-many-arguments, + locally-enabled, + locally-disabled, + fixme, + invalid-name, + +[REPORTS] +reports=no + +[FORMAT] +max-line-length=80 +indent-string=' ' + +[SIMILARITIES] +min-similarity-lines=20 + +[VARIABLES] +dummy-variables-rgx=_ + +[DESIGN] +max-parents=10 diff --git a/lddtree.py b/lddtree.py index 8480248..d1ec9e9 100755 --- a/lddtree.py +++ b/lddtree.py @@ -1,4 +1,5 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- # Copyright 2012-2014 Gentoo Foundation # Copyright 2012-2014 Mike Frysinger # Copyright 2012-2014 The Chromium OS Authors @@ -73,7 +74,7 @@ def dbg(debug, *args, **kwargs): def bstr(buf): """Decode the byte string into a string""" if isinstance(buf, str): - return buf + return buf return buf.decode('utf-8') @@ -351,6 +352,8 @@ def FindLib(elf, lib, ldpaths, root='/', debug=False): return (None, None) +# We abuse the _all_libs state. We probably shouldn't, but we do currently. +# pylint: disable=dangerous-default-value def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[]}, display=None, debug=False, _first=True, _all_libs={}): """Parse the ELF dependency tree of the specified file @@ -491,6 +494,7 @@ def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[ del elf return ret +# pylint: enable=dangerous-default-value class _NormalizePathAction(argparse.Action): @@ -608,7 +612,7 @@ def _ActionCopy(options, elf): # Similarly, we should provide an option for automatically copying over # the libnsl.so and libnss_*.so libraries, as well as an open ended list # for known libs that get loaded (e.g. curl will dlopen(libresolv)). - libpaths = set() + uniq_libpaths = set() for lib in elf['libs']: libdata = elf['libs'][lib] path = libdata['realpath'] @@ -616,17 +620,18 @@ def _ActionCopy(options, elf): warn('could not locate library: %s' % lib) continue if not options.libdir: - libpaths.add(_StripRoot(os.path.dirname(path))) + uniq_libpaths.add(_StripRoot(os.path.dirname(path))) _copy(path, libdata['path'], outdir=options.libdir) if not options.libdir: - libpaths = list(libpaths) + libpaths = list(uniq_libpaths) if elf['runpath']: libpaths = elf['runpath'] + libpaths else: libpaths = elf['rpath'] + libpaths else: - libpaths.add(options.libdir) + uniq_libpaths.add(options.libdir) + libpaths = list(uniq_libpaths) # We don't bother to copy this as ParseElf adds the interp to the 'libs', # so it was already copied in the libs loop above. @@ -637,6 +642,7 @@ def _ActionCopy(options, elf): def main(argv): + """The main entry point!""" parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) diff --git a/pylint b/pylint new file mode 100755 index 0000000..0098e06 --- /dev/null +++ b/pylint @@ -0,0 +1,49 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright 1999-2017 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +"""Run pylint with the right settings.""" + +from __future__ import print_function + +import os +import sys + + +def find_all_modules(source_root): + """Locate all python modules in the tree for scanning""" + ret = [] + + for root, _dirs, files in os.walk(source_root, topdown=False): + # Add all of the .py modules in the tree. + ret += [os.path.join(root, x) for x in files if x.endswith('.py')] + + # Add the main scripts that don't end in .py. + ret += [os.path.join(source_root, x) for x in ('pylint',)] + + return ret + + +def main(argv): + """The main entry point""" + source_root = os.path.dirname(os.path.realpath(__file__)) + + if not argv: + argv = find_all_modules(source_root) + + pympath = source_root + pythonpath = os.environ.get('PYTHONPATH') + if pythonpath is None: + pythonpath = pympath + else: + pythonpath = pympath + ':' + pythonpath + os.environ['PYTHONPATH'] = pythonpath + + pylintrc = os.path.join(source_root, '.pylintrc') + cmd = ['pylint', '--rcfile', pylintrc] + os.execvp(cmd[0], cmd + argv) + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:]))