commit: 7d70b3ebb3a4614e13a7e15a96c6f57100b52cec Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> AuthorDate: Mon Jan 4 04:44:05 2016 +0000 Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> CommitDate: Sat Jan 30 07:50:20 2016 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=7d70b3eb
repoman: Create a new MultiCheck class plugin Move ebuilds/ checks.py and errors.py to the scan/ebuild plugin. Remove the checks_init from main(), initialize it in the MultiCheck class where it is needed. pym/repoman/checks/ebuilds/__init__.py | 0 pym/repoman/main.py | 2 - pym/repoman/modules/scan/ebuild/__init__.py | 9 +++++ .../ebuilds => modules/scan/ebuild}/checks.py | 2 +- .../ebuilds => modules/scan/ebuild}/errors.py | 0 pym/repoman/modules/scan/ebuild/multicheck.py | 43 ++++++++++++++++++++++ pym/repoman/scanner.py | 21 +---------- 7 files changed, 54 insertions(+), 23 deletions(-) diff --git a/pym/repoman/checks/ebuilds/__init__.py b/pym/repoman/checks/ebuilds/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/pym/repoman/main.py b/pym/repoman/main.py index 8784685..890e034 100755 --- a/pym/repoman/main.py +++ b/pym/repoman/main.py @@ -26,7 +26,6 @@ from portage.util import formatter from repoman.actions import Actions from repoman.argparser import parse_args -from repoman.checks.ebuilds.checks import checks_init from repoman.qa_data import ( format_qa_output, format_qa_output_column, qahelp, qawarnings, qacats) @@ -65,7 +64,6 @@ def repoman_main(argv): if options.experimental_inherit == 'y': # This is experimental, so it's non-fatal. qawarnings.add("inherit.missing") - checks_init(experimental_inherit=True) # Set this to False when an extraordinary issue (generally # something other than a QA issue) makes it impossible to diff --git a/pym/repoman/modules/scan/ebuild/__init__.py b/pym/repoman/modules/scan/ebuild/__init__.py index a22e736..e712e4b 100644 --- a/pym/repoman/modules/scan/ebuild/__init__.py +++ b/pym/repoman/modules/scan/ebuild/__init__.py @@ -28,6 +28,15 @@ module_spec = { 'func_desc': { }, }, + 'multicheck-module': { + 'name': "multicheck", + 'sourcefile': "multicheck", + 'class': "MultiCheck", + 'description': doc, + 'functions': ['check'], + 'func_kwargs': { + }, + }, } } diff --git a/pym/repoman/checks/ebuilds/checks.py b/pym/repoman/modules/scan/ebuild/checks.py similarity index 99% rename from pym/repoman/checks/ebuilds/checks.py rename to pym/repoman/modules/scan/ebuild/checks.py index 5420e51..be59b05 100644 --- a/pym/repoman/checks/ebuilds/checks.py +++ b/pym/repoman/modules/scan/ebuild/checks.py @@ -21,7 +21,7 @@ from portage.eapi import ( eapi_has_src_prepare_and_src_configure, eapi_has_dosed_dohard, eapi_exports_AA, eapi_has_pkg_pretend) -import repoman.checks.ebuilds.errors as errors +from . import errors class LineCheck(object): diff --git a/pym/repoman/checks/ebuilds/errors.py b/pym/repoman/modules/scan/ebuild/errors.py similarity index 100% rename from pym/repoman/checks/ebuilds/errors.py rename to pym/repoman/modules/scan/ebuild/errors.py diff --git a/pym/repoman/modules/scan/ebuild/multicheck.py b/pym/repoman/modules/scan/ebuild/multicheck.py new file mode 100644 index 0000000..989d695 --- /dev/null +++ b/pym/repoman/modules/scan/ebuild/multicheck.py @@ -0,0 +1,43 @@ + +import io + +from portage import _encodings, _unicode_encode + +from .checks import run_checks, checks_init + + +class MultiCheck(object): + '''Class to run multiple different checks on an ebuild''' + + def __init__(self, **kwargs): + self.qatracker = kwargs.get('qatracker') + self.options = kwargs.get('options') + checks_init(self.options.experimental_inherit == 'y') + + def check(self, **kwargs): + ebuild = kwargs.get('ebuild') + pkg = kwargs.get('pkg') + try: + # All ebuilds should have utf_8 encoding. + f = io.open( + _unicode_encode(ebuild.full_path, encoding=_encodings['fs'], + errors='strict'), + mode='r', encoding=_encodings['repo.content']) + try: + for check_name, e in run_checks(f, pkg): + self.qatracker.add_error( + check_name, ebuild.relative_path + ': %s' % e) + finally: + f.close() + except UnicodeDecodeError: + # A file.UTF8 failure will have already been recorded. + pass + return {'continue': False} + + @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 dbbbb15..9fe5f26 100644 --- a/pym/repoman/scanner.py +++ b/pym/repoman/scanner.py @@ -3,7 +3,6 @@ from __future__ import print_function, unicode_literals import copy -import io import logging from itertools import chain from pprint import pformat @@ -13,11 +12,8 @@ from _emerge.Package import Package import portage from portage import normalize_path from portage import os -from portage import _encodings -from portage import _unicode_encode from portage.dep import Atom from portage.output import green -from repoman.checks.ebuilds.checks import run_checks from repoman.modules.commit import repochecks from repoman.profile import check_profiles, dev_profile_keywords, setup_profile from repoman.repos import repo_metadata @@ -294,7 +290,7 @@ class Scanner(object): ('arches', 'ArchChecks'), ('depend', 'DependChecks'), ('use_flags', 'USEFlagChecks'), ('ruby', 'RubyEclassChecks'), ('license', 'LicenseChecks'), ('restrict', 'RestrictChecks'), - ('mtime', 'MtimeChecks'), + ('mtime', 'MtimeChecks'), ('multicheck', 'MultiCheck'), ]: if mod[0]: mod_class = MODULE_CONTROLLER.get_class(mod[0]) @@ -323,21 +319,6 @@ class Scanner(object): continue # Syntax Checks - try: - # All ebuilds should have utf_8 encoding. - f = io.open( - _unicode_encode( - dynamic_data['ebuild'].full_path, encoding=_encodings['fs'], errors='strict'), - mode='r', encoding=_encodings['repo.content']) - try: - for check_name, e in run_checks(f, dynamic_data['pkg']): - self.qatracker.add_error( - check_name, dynamic_data['ebuild'].relative_path + ': %s' % e) - finally: - f.close() - except UnicodeDecodeError: - # A file.UTF8 failure will have already been recorded above. - pass if self.options.force: # The dep_check() calls are the most expensive QA test. If --force