commit:     d2bdf2bbd826318819b53b56504ec38fe2f4ac2c
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sun Jan  3 20:38:11 2016 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sun Jan 10 22:59:34 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=d2bdf2bb

repoman: New DependChecks plugin

Migrate code from _scan_ebuilds to the plugin system

 pym/repoman/modules/scan/depend/__init__.py |  23 +++++
 pym/repoman/modules/scan/depend/depend.py   | 132 ++++++++++++++++++++++++++++
 pym/repoman/scanner.py                      | 119 ++-----------------------
 3 files changed, 162 insertions(+), 112 deletions(-)

diff --git a/pym/repoman/modules/scan/depend/__init__.py 
b/pym/repoman/modules/scan/depend/__init__.py
new file mode 100644
index 0000000..73d3f8f
--- /dev/null
+++ b/pym/repoman/modules/scan/depend/__init__.py
@@ -0,0 +1,23 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Depend plug-in module for repoman.
+Performs Dependency checks on ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+       'name': 'depend',
+       'description': doc,
+       'provides':{
+               'depend-module': {
+                       'name': "depend",
+                       'class': "DependChecks",
+                       'description': doc,
+                       'functions': ['check'],
+                       'func_desc': {
+                       },
+               },
+       }
+}
+

diff --git a/pym/repoman/modules/scan/depend/depend.py 
b/pym/repoman/modules/scan/depend/depend.py
new file mode 100644
index 0000000..8a0ff48
--- /dev/null
+++ b/pym/repoman/modules/scan/depend/depend.py
@@ -0,0 +1,132 @@
+
+from _emerge.Package import Package
+
+from repoman.check_missingslot import check_missingslot
+# import our initialized portage instance
+from repoman._portage import portage
+from repoman.qa_data import suspect_virtual, suspect_rdepend
+
+
+class DependChecks(object):
+
+       def __init__(self, **kwargs):
+               self.qatracker = kwargs.get('qatracker')
+               self.portdb = kwargs.get('portdb')
+
+       def check(self, **kwargs):
+               ebuild = kwargs.get('ebuild')
+               pkg = kwargs.get('pkg')
+
+               unknown_pkgs = set()
+
+               inherited_java_eclass = "java-pkg-2" in ebuild.inherited or \
+                       "java-pkg-opt-2" in ebuild.inherited,
+               inherited_wxwidgets_eclass = "wxwidgets" in ebuild.inherited
+               # operator_tokens = set(["||", "(", ")"])
+               type_list, badsyntax = [], []
+               for mytype in Package._dep_keys + ("LICENSE", "PROPERTIES", 
"PROVIDE"):
+                       mydepstr = ebuild.metadata[mytype]
+
+                       buildtime = mytype in Package._buildtime_keys
+                       runtime = mytype in Package._runtime_keys
+                       token_class = None
+                       if mytype.endswith("DEPEND"):
+                               token_class = portage.dep.Atom
+
+                       try:
+                               atoms = portage.dep.use_reduce(
+                                       mydepstr, matchall=1, flat=True,
+                                       is_valid_flag=pkg.iuse.is_valid_flag, 
token_class=token_class)
+                       except portage.exception.InvalidDependString as e:
+                               atoms = None
+                               badsyntax.append(str(e))
+
+                       if atoms and mytype.endswith("DEPEND"):
+                               if runtime and \
+                                       "test?" in mydepstr.split():
+                                       self.qatracker.add_error(
+                                               mytype + '.suspect',
+                                               "%s: 'test?' USE conditional in 
%s" %
+                                               (ebuild.relative_path, mytype))
+
+                               for atom in atoms:
+                                       if atom == "||":
+                                               continue
+
+                                       is_blocker = atom.blocker
+
+                                       # Skip dependency.unknown for blockers, 
so that we
+                                       # don't encourage people to remove 
necessary blockers,
+                                       # as discussed in bug 382407. We use 
atom.without_use
+                                       # due to bug 525376.
+                                       if not is_blocker and \
+                                               not 
self.portdb.xmatch("match-all", atom.without_use) and \
+                                               not 
atom.cp.startswith("virtual/"):
+                                               unknown_pkgs.add((mytype, 
atom.unevaluated_atom))
+
+                                       if kwargs.get('catdir') != "virtual":
+                                               if not is_blocker and \
+                                                       atom.cp in 
suspect_virtual:
+                                                       
self.qatracker.add_error(
+                                                               
'virtual.suspect', ebuild.relative_path +
+                                                               ": %s: consider 
using '%s' instead of '%s'" %
+                                                               (mytype, 
suspect_virtual[atom.cp], atom))
+                                               if not is_blocker and \
+                                                       
atom.cp.startswith("perl-core/"):
+                                                       
self.qatracker.add_error('dependency.perlcore',
+                                                               
ebuild.relative_path +
+                                                               ": %s: please 
use '%s' instead of '%s'" %
+                                                               (mytype,
+                                                               
atom.replace("perl-core/","virtual/perl-"),
+                                                               atom))
+
+                                       if buildtime and \
+                                               not is_blocker and \
+                                               not inherited_java_eclass and \
+                                               atom.cp == "virtual/jdk":
+                                               self.qatracker.add_error(
+                                                       'java.eclassesnotused', 
ebuild.relative_path)
+                                       elif buildtime and \
+                                               not is_blocker and \
+                                               not inherited_wxwidgets_eclass 
and \
+                                               atom.cp == "x11-libs/wxGTK":
+                                               self.qatracker.add_error(
+                                                       
'wxwidgets.eclassnotused',
+                                                       "%s: %ss on 
x11-libs/wxGTK without inheriting"
+                                                       " wxwidgets.eclass" % 
(ebuild.relative_path, mytype))
+                                       elif runtime:
+                                               if not is_blocker and \
+                                                       atom.cp in 
suspect_rdepend:
+                                                       
self.qatracker.add_error(
+                                                               mytype + 
'.suspect',
+                                                               
ebuild.relative_path + ": '%s'" % atom)
+
+                                       if atom.operator == "~" and \
+                                               
portage.versions.catpkgsplit(atom.cpv)[3] != "r0":
+                                               qacat = 'dependency.badtilde'
+                                               self.qatracker.add_error(
+                                                       qacat, "%s: %s uses the 
~ operator"
+                                                       " with a non-zero 
revision: '%s'" %
+                                                       (ebuild.relative_path, 
mytype, atom))
+
+                                       check_missingslot(atom, mytype, 
ebuild.eapi, self.portdb, self.qatracker,
+                                               ebuild.relative_path, 
ebuild.metadata)
+
+                       type_list.extend([mytype] * (len(badsyntax) - 
len(type_list)))
+
+               for m, b in zip(type_list, badsyntax):
+                       if m.endswith("DEPEND"):
+                               qacat = "dependency.syntax"
+                       else:
+                               qacat = m + ".syntax"
+                       self.qatracker.add_error(
+                               qacat, "%s: %s: %s" % (ebuild.relative_path, m, 
b))
+               return {'continue': False, 'unknown_pkgs': unknown_pkgs, 
'type_list': type_list}
+
+       @property
+       def runInPkgs(self):
+               return (False, [])
+
+       @property
+       def runInEbuilds(self):
+               return (True, [self.check])

diff --git a/pym/repoman/scanner.py b/pym/repoman/scanner.py
index 7b07a95..7f770c3 100644
--- a/pym/repoman/scanner.py
+++ b/pym/repoman/scanner.py
@@ -19,13 +19,11 @@ from portage.dep import Atom
 from portage.output import green
 from repoman.checks.ebuilds.checks import run_checks
 from repoman.checks.ebuilds.eclasses.ruby import RubyEclassChecks
-from repoman.check_missingslot import check_missingslot
 from repoman.checks.ebuilds.use_flags import USEFlagChecks
 from repoman.checks.ebuilds.variables.license import LicenseChecks
 from repoman.checks.ebuilds.variables.restrict import RestrictChecks
 from repoman.modules.commit import repochecks
 from repoman.profile import check_profiles, dev_profile_keywords, setup_profile
-from repoman.qa_data import missingvars, suspect_virtual, suspect_rdepend
 from repoman.repos import repo_metadata
 from repoman.modules.scan.scan import scan
 from repoman.modules.vcs.vcs import vcs_files_to_cps
@@ -301,7 +299,7 @@ class Scanner(object):
                                ('eapi', 'EAPIChecks'), ('ebuild_metadata', 
'EbuildMetadata'),
                                ('thirdpartymirrors', 'ThirdPartyMirrors'),
                                ('description', 'DescriptionChecks'), (None, 
'KeywordChecks'),
-                               ('arches', 'ArchChecks'),
+                               ('arches', 'ArchChecks'), ('depend', 
'DependChecks'),
                                ]:
                                if mod[0]:
                                        mod_class = 
MODULE_CONTROLLER.get_class(mod[0])
@@ -358,112 +356,9 @@ class Scanner(object):
                        badprovsyntax = False
                        # catpkg = catdir + "/" + y_ebuild
 
-                       inherited_java_eclass = "java-pkg-2" in 
dynamic_data['ebuild'].inherited or \
-                               "java-pkg-opt-2" in 
dynamic_data['ebuild'].inherited,
-                       inherited_wxwidgets_eclass = "wxwidgets" in 
dynamic_data['ebuild'].inherited
-                       # operator_tokens = set(["||", "(", ")"])
-                       type_list, badsyntax = [], []
-                       for mytype in Package._dep_keys + ("LICENSE", 
"PROPERTIES", "PROVIDE"):
-                               mydepstr = 
dynamic_data['ebuild'].metadata[mytype]
-
-                               buildtime = mytype in Package._buildtime_keys
-                               runtime = mytype in Package._runtime_keys
-                               token_class = None
-                               if mytype.endswith("DEPEND"):
-                                       token_class = portage.dep.Atom
-
-                               try:
-                                       atoms = portage.dep.use_reduce(
-                                               mydepstr, matchall=1, flat=True,
-                                               
is_valid_flag=dynamic_data['pkg'].iuse.is_valid_flag, token_class=token_class)
-                               except portage.exception.InvalidDependString as 
e:
-                                       atoms = None
-                                       badsyntax.append(str(e))
-
-                               if atoms and mytype.endswith("DEPEND"):
-                                       if runtime and \
-                                               "test?" in mydepstr.split():
-                                               self.qatracker.add_error(
-                                                       mytype + '.suspect',
-                                                       "%s: 'test?' USE 
conditional in %s" %
-                                                       
(dynamic_data['ebuild'].relative_path, mytype))
-
-                                       for atom in atoms:
-                                               if atom == "||":
-                                                       continue
-
-                                               is_blocker = atom.blocker
-
-                                               # Skip dependency.unknown for 
blockers, so that we
-                                               # don't encourage people to 
remove necessary blockers,
-                                               # as discussed in bug 382407. 
We use atom.without_use
-                                               # due to bug 525376.
-                                               if not is_blocker and \
-                                                       not 
self.portdb.xmatch("match-all", atom.without_use) and \
-                                                       not 
atom.cp.startswith("virtual/"):
-                                                       
unknown_pkgs.add((mytype, atom.unevaluated_atom))
-
-                                               if dynamic_data['catdir'] != 
"virtual":
-                                                       if not is_blocker and \
-                                                               atom.cp in 
suspect_virtual:
-                                                               
self.qatracker.add_error(
-                                                                       
'virtual.suspect', dynamic_data['ebuild'].relative_path +
-                                                                       ": %s: 
consider using '%s' instead of '%s'" %
-                                                                       
(mytype, suspect_virtual[atom.cp], atom))
-                                                       if not is_blocker and \
-                                                               
atom.cp.startswith("perl-core/"):
-                                                               
self.qatracker.add_error('dependency.perlcore',
-                                                                       
dynamic_data['ebuild'].relative_path +
-                                                                       ": %s: 
please use '%s' instead of '%s'" %
-                                                                       (mytype,
-                                                                       
atom.replace("perl-core/","virtual/perl-"),
-                                                                       atom))
-
-                                               if buildtime and \
-                                                       not is_blocker and \
-                                                       not 
inherited_java_eclass and \
-                                                       atom.cp == 
"virtual/jdk":
-                                                       
self.qatracker.add_error(
-                                                               
'java.eclassesnotused', dynamic_data['ebuild'].relative_path)
-                                               elif buildtime and \
-                                                       not is_blocker and \
-                                                       not 
inherited_wxwidgets_eclass and \
-                                                       atom.cp == 
"x11-libs/wxGTK":
-                                                       
self.qatracker.add_error(
-                                                               
'wxwidgets.eclassnotused',
-                                                               "%s: %ss on 
x11-libs/wxGTK without inheriting"
-                                                               " 
wxwidgets.eclass" % (dynamic_data['ebuild'].relative_path, mytype))
-                                               elif runtime:
-                                                       if not is_blocker and \
-                                                               atom.cp in 
suspect_rdepend:
-                                                               
self.qatracker.add_error(
-                                                                       mytype 
+ '.suspect',
-                                                                       
dynamic_data['ebuild'].relative_path + ": '%s'" % atom)
-
-                                               if atom.operator == "~" and \
-                                                       
portage.versions.catpkgsplit(atom.cpv)[3] != "r0":
-                                                       qacat = 
'dependency.badtilde'
-                                                       
self.qatracker.add_error(
-                                                               qacat, "%s: %s 
uses the ~ operator"
-                                                               " with a 
non-zero revision: '%s'" %
-                                                               
(dynamic_data['ebuild'].relative_path, mytype, atom))
-
-                                               check_missingslot(atom, mytype, 
dynamic_data['ebuild'].eapi, self.portdb, self.qatracker,
-                                                       
dynamic_data['ebuild'].relative_path, dynamic_data['ebuild'].metadata)
-
-                               type_list.extend([mytype] * (len(badsyntax) - 
len(type_list)))
-
-                       for m, b in zip(type_list, badsyntax):
-                               if m.endswith("DEPEND"):
-                                       qacat = "dependency.syntax"
-                               else:
-                                       qacat = m + ".syntax"
-                               self.qatracker.add_error(
-                                       qacat, "%s: %s: %s" % 
(dynamic_data['ebuild'].relative_path, m, b))
-
-                       badlicsyntax = len([z for z in type_list if z == 
"LICENSE"])
-                       badprovsyntax = len([z for z in type_list if z == 
"PROVIDE"])
-                       baddepsyntax = len(type_list) != badlicsyntax + 
badprovsyntax
+                       badlicsyntax = len([z for z in 
dynamic_data['type_list'] if z == "LICENSE"])
+                       badprovsyntax = len([z for z in 
dynamic_data['type_list'] if z == "PROVIDE"])
+                       baddepsyntax = len(dynamic_data['type_list']) != 
badlicsyntax + badprovsyntax
                        badlicsyntax = badlicsyntax > 0
                        badprovsyntax = badprovsyntax > 0
 
@@ -626,7 +521,7 @@ class Scanner(object):
                                                                        # 
aren't counted for *DEPEND.bad, so we
                                                                        # 
ignore them here.
                                                                        if not 
atom.blocker:
-                                                                               
unknown_pkgs.discard(
+                                                                               
dynamic_data['unknown_pkgs'].discard(
                                                                                
        (mytype, atom.unevaluated_atom))
 
                                                                if not 
prof.sub_path:
@@ -671,9 +566,9 @@ class Scanner(object):
                                                                        % 
(dynamic_data['ebuild'].relative_path, mytype, keyword,
                                                                                
prof, pformat(atoms, indent=6)))
 
-                       if not baddepsyntax and unknown_pkgs:
+                       if not baddepsyntax and dynamic_data['unknown_pkgs']:
                                type_map = {}
-                               for mytype, atom in unknown_pkgs:
+                               for mytype, atom in 
dynamic_data['unknown_pkgs']:
                                        type_map.setdefault(mytype, 
set()).add(atom)
                                for mytype, atoms in type_map.items():
                                        self.qatracker.add_error(

Reply via email to