From a510a9ec25f52dfca3727ad603f38c6f8d5690eb Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Wed, 16 Jan 2019 21:14:54 +0100 Subject: [PATCH] Changes for building PyYAML for Fedora Core 27 (#556) --- data/rpm_templates/PyYAML.spec | 20 +++++++++--- l2tdevtools/review_helpers/pylint.py | 46 ++++++++++++++++++++-------- tests/review_helpers/pylint.py | 14 ++++++++- 3 files changed, 62 insertions(+), 18 deletions(-) diff --git a/data/rpm_templates/PyYAML.spec b/data/rpm_templates/PyYAML.spec index 2e481a28..564ab833 100644 --- a/data/rpm_templates/PyYAML.spec +++ b/data/rpm_templates/PyYAML.spec @@ -24,10 +24,22 @@ algorithm is simple enough to be a reference for YAML parser implementors. A simple extension API is also provided. The package is built using libyaml for improved speed. -%package -n python3-%{{name}} +%package -n python2-pyyaml +Obsoletes: PyYAML < %{{version}} +Provides: PyYAML = %{{version}} Summary: YAML parser and emitter for Python -%description -n python3-%{{name}} +%description -n python2-pyyaml +Python-yaml is a complete YAML 1.1 parser and emitter +for Python. It can parse all examples from the specification. The parsing +algorithm is simple enough to be a reference for YAML parser implementors. +A simple extension API is also provided. The package is built using libyaml +for improved speed. + +%package -n python3-pyyaml +Summary: YAML parser and emitter for Python + +%description -n python3-pyyaml Python-yaml is a complete YAML 1.1 parser and emitter for Python. It can parse all examples from the specification. The parsing algorithm is simple enough to be a reference for YAML parser implementors. @@ -51,13 +63,13 @@ rm -rf %{{buildroot}}/usr/share/doc/%{{name}}/ %clean rm -rf %{{buildroot}} -%files -n %{{name}} +%files -n python2-pyyaml %license LICENSE %doc CHANGES README %{{_libdir}}/python2*/site-packages/yaml/ %{{_libdir}}/python2*/site-packages/PyYAML*.egg-info -%files -n python3-%{{name}} +%files -n python3-pyyaml %license LICENSE %doc CHANGES README %{{_libdir}}/python3*/site-packages/yaml/ diff --git a/l2tdevtools/review_helpers/pylint.py b/l2tdevtools/review_helpers/pylint.py index 45d22420..7baf5d5a 100644 --- a/l2tdevtools/review_helpers/pylint.py +++ b/l2tdevtools/review_helpers/pylint.py @@ -20,6 +20,28 @@ class PylintHelper(cli.CLIHelper): _RCFILE_NAME = '.pylintrc' + def _GetVersion(self): + """Retrieves the pylint version. + + Returns: + tuple[int]: pylint version as a tuple of integers or (0, 0, 0) if + not available. + """ + version_tuple = (0, 0, 0) + + exit_code, output, _ = self.RunCommand('pylint --version') + if exit_code == 0: + for line in output.split('\n'): + if line.startswith('pylint '): + _, _, version = line.partition(' ') + # Remove a trailing comma. + version, _, _ = version.partition(',') + + version_tuple = tuple([ + int(digit, 10) for digit in version.split('.')]) + + return version_tuple + def CheckFiles(self, filenames, rcfile): """Checks if the linting of the files is correct using pylint. @@ -30,12 +52,22 @@ def CheckFiles(self, filenames, rcfile): Returns: bool: True if the files were linted without errors. """ + version_tuple = self._GetVersion() + print('Running linter on changed files.') failed_filenames = [] for filename in filenames: print('Checking: {0:s}'.format(filename)) command = 'pylint --rcfile="{0:s}" {1:s}'.format(rcfile, filename) + # For now disable pylint 2.1.1 and later specific checks. + if version_tuple >= (2, 1, 1): + additional_checks = [ + 'assignment-from-none', 'chained-comparison', + 'useless-object-inheritance'] + command = '{0:s} --disable={1:s}'.format( + command, ','.join(additional_checks)) + exit_code = subprocess.call(command, shell=True) if exit_code != 0: failed_filenames.append(filename) @@ -53,19 +85,7 @@ def CheckUpToDateVersion(self): Returns: bool: True if the pylint version is up to date. """ - exit_code, output, _ = self.RunCommand('pylint --version') - if exit_code != 0: - return False - - version_tuple = (0, 0, 0) - for line in output.split('\n'): - if line.startswith('pylint '): - _, _, version = line.partition(' ') - # Remove a trailing comma. - version, _, _ = version.partition(',') - - version_tuple = tuple([int(digit, 10) for digit in version.split('.')]) - + version_tuple = self._GetVersion() return version_tuple >= self._MINIMUM_VERSION_TUPLE def GetRCFile(self, project_path): diff --git a/tests/review_helpers/pylint.py b/tests/review_helpers/pylint.py index 42604e39..46f7f76c 100644 --- a/tests/review_helpers/pylint.py +++ b/tests/review_helpers/pylint.py @@ -14,11 +14,23 @@ class PylintHelperTest(test_lib.BaseTestCase): """Tests the pylint helper""" + # pylint: disable=protected-access + def testInitialize(self): - """Tests that the helper can be initialized.""" + """Tests the __init__ function.""" helper = pylint.PylintHelper() self.assertIsNotNone(helper) + def testGetVersion(self): + """Tests the _GetVersion function.""" + helper = pylint.PylintHelper() + + helper._GetVersion() + + # TODO: add tests for CheckFiles + # TODO: add tests for CheckUpToDateVersion + # TODO: add tests for GetRCFile + if __name__ == '__main__': unittest.main()