From 6740ba1683ba146d51156e0bbf63cbb0f9dc728d Mon Sep 17 00:00:00 2001 From: Arzhan Kinzhalin Date: Wed, 24 Oct 2018 15:46:56 -0700 Subject: [PATCH] Fix linter (flake8) errors. Also: * flake8 configuration is moved from the command-line in the makefile to setup.cfg --- Makefile | 2 +- autospec/autospec.py | 4 +-- autospec/buildreq.py | 2 +- autospec/commitmessage.py | 2 +- autospec/config.py | 3 +- autospec/count.py | 6 ++-- autospec/files.py | 74 +++++++++++++++++++-------------------- autospec/pkg_integrity.py | 6 ++-- autospec/specfiles.py | 8 ++--- autospec/tarball.py | 10 +++--- autospec/test.py | 10 +++--- setup.cfg | 4 +++ 12 files changed, 66 insertions(+), 65 deletions(-) diff --git a/Makefile b/Makefile index 76ef99f..7d60c3e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ check: autospec/*.py - @flake8 --max-line-length=199 --ignore=E722 $^ + @flake8 $^ test_pkg_integrity: PYTHONPATH=${CURDIR}/autospec python3 tests/test_pkg_integrity.py diff --git a/autospec/autospec.py b/autospec/autospec.py index 3361df5..a8037a7 100644 --- a/autospec/autospec.py +++ b/autospec/autospec.py @@ -62,8 +62,8 @@ def add_sources(download_path, archives): # directories which usually reside in directories such as # /run or /tmp. # - if os.path.exists(os.path.normpath(build.download_path + - "/{0}.tmpfiles".format(tarball.name))): + if os.path.exists(os.path.normpath( + build.download_path + "/{0}.tmpfiles".format(tarball.name))): buildpattern.sources["tmpfile"].append( "{}.tmpfiles".format(tarball.name)) if tarball.gcov_file: diff --git a/autospec/buildreq.py b/autospec/buildreq.py index 3fb46d9..a90144d 100644 --- a/autospec/buildreq.py +++ b/autospec/buildreq.py @@ -169,7 +169,7 @@ def is_version(num_str): """ Return True if num_str looks like a version number """ - if re.search('^\d+(\.\d+)*$', num_str): + if re.search(r'^\d+(\.\d+)*$', num_str): return True return False diff --git a/autospec/commitmessage.py b/autospec/commitmessage.py index e7f442a..5c605f8 100644 --- a/autospec/commitmessage.py +++ b/autospec/commitmessage.py @@ -150,7 +150,7 @@ def process_NEWS(newsfile): return commitmessage, cves # now search for CVEs - pat = re.compile("(CVE\-[0-9]+\-[0-9]+)") + pat = re.compile(r"(CVE\-[0-9]+\-[0-9]+)") for news in newslines[start:stop]: match = pat.search(news) if match: diff --git a/autospec/config.py b/autospec/config.py index 8d7a488..260217a 100644 --- a/autospec/config.py +++ b/autospec/config.py @@ -728,8 +728,7 @@ def parse_config_files(path, bump, filemanager, version): patches += read_conf_file(os.path.join(path, "series")) pfiles = [("%s/%s" % (path, x.split(" ")[0])) for x in patches] - cmd = "egrep \"(\+\+\+|\-\-\-).*((Makefile.am)|(configure.ac|configure.in))\" %s" % \ - " ".join(pfiles) + cmd = "egrep \"(\+\+\+|\-\-\-).*((Makefile.am)|(configure.ac|configure.in))\" %s" % " ".join(pfiles) # noqa: W605 if patches and call(cmd, check=False, stdout=subprocess.DEVNULL, diff --git a/autospec/count.py b/autospec/count.py index 92e7bfd..513b264 100644 --- a/autospec/count.py +++ b/autospec/count.py @@ -1249,12 +1249,12 @@ def parse_log(log, pkgname=''): # == 55 tests, 48 stderr failures, 6 stdout failures, 0 stderrB failures, 0 stdoutB failures, 0 post failures == # == 125 tests, 12 stderr failures, 0 stdout failures, 0 stderrB failures, 0 stdoutB failures, 0 post failures == match = re.search(r"\=\= ([0-9]+) tests?\, ([0-9]+) stderr failures?\, ([0-9]+) stdout failures?\, " - "([0-9]+) stderrB failures?\, ([0-9]+) stdoutB failures?\, ([0-9]+) post failures? \=\=", line) + r"([0-9]+) stderrB failures?\, ([0-9]+) stdoutB failures?\, ([0-9]+) post failures? \=\=", line) if match and incheck: total_tests += convert_int(match.group(1)) total_fail += (convert_int(match.group(2)) + convert_int(match.group(3)) + convert_int(match.group(4)) + convert_int(match.group(5)) + convert_int(match.group(6))) - total_pass += (convert_int(match.group(1)) - (convert_int(match.group(2)) + convert_int(match.group(3)) + convert_int(match.group(4)) + convert_int(match.group(5)) + - convert_int(match.group(6)))) + total_pass += \ + (convert_int(match.group(1)) - (convert_int(match.group(2)) + convert_int(match.group(3)) + convert_int(match.group(4)) + convert_int(match.group(5)) + convert_int(match.group(6)))) continue # zsh diff --git a/autospec/files.py b/autospec/files.py index 71c3e14..a5f8df3 100644 --- a/autospec/files.py +++ b/autospec/files.py @@ -134,7 +134,7 @@ class FileManager(object): res = set() removed = False - directive_re = re.compile("(%\w+(\([^\)]*\))?\s+)(.*)") + directive_re = re.compile(r"(%\w+(\([^\)]*\))?\s+)(.*)") for f in files: # skip the files with directives at the beginning, including %doc # and %dir directives. @@ -218,17 +218,17 @@ class FileManager(object): # Patterns for matching files, format is a tuple as follows: # (, , , ) # order matters! - (r"^/usr/share/package-licenses/.+/.+", "license"), + (r"^/usr/share/package-licenses/.{1,}/.{1,}", "license"), (r"^/usr/share/man/man2", "dev"), (r"^/usr/share/man/man3", "dev"), (r"^/usr/share/man/", "man"), (r"^/usr/share/omf", "main", "/usr/share/omf/*"), - (r"^/usr/lib/[a-zA-Z0-9\.\_\-\+]*\.so\.", "lib"), - (r"^/usr/lib64/[a-zA-Z0-9\.\_\-\+]*\.so\.", "lib"), - (r"^/usr/lib32/[a-zA-Z0-9\.\_\-\+]*\.so\.", "lib32"), + (r"^/usr/lib/[a-zA-Z0-9._+-]*\.so\.", "lib"), + (r"^/usr/lib64/[a-zA-Z0-9._+-]*\.so\.", "lib"), + (r"^/usr/lib32/[a-zA-Z0-9._+-]*\.so\.", "lib32"), (r"^/usr/lib64/lib(asm|dw|elf)-[0-9.]+\.so", "lib"), (r"^/usr/lib32/lib(asm|dw|elf)-[0-9.]+\.so", "lib32"), - (r"^/usr/lib64/haswell/[a-zA-Z0-9\.\_\-\+]*\.so\.", "lib"), + (r"^/usr/lib64/haswell/[a-zA-Z0-9._+-]*\.so\.", "lib"), (r"^/usr/lib64/gobject-introspection/", "lib"), (r"^/usr/libexec/", "libexec"), (r"^/usr/bin/", "bin"), @@ -238,17 +238,17 @@ class FileManager(object): (r"^/usr/lib/python3.*/", "python3", "/usr/lib/python3*/*"), (r"^/usr/lib/python2.*/", "legacypython", "/usr/lib/python2*/*"), (r"^/usr/lib64/python.*/", "python", "/usr/lib64/python*/*"), - (r"^/usr/share/gir-[0-9\.]+/[a-zA-Z0-9\.\_\-\+]*\.gir", "data", "/usr/share/gir-1.0/*.gir"), + (r"^/usr/share/gir-[0-9\.]+/[a-zA-Z0-9._+-]*\.gir", "data", "/usr/share/gir-1.0/*.gir"), (r"^/usr/share/cmake/", "data", "/usr/share/cmake/*"), (r"^/usr/share/cmake-3.1/", "data", "/usr/share/cmake-3.1/*"), (r"^/usr/share/cmake-3.7/", "data", "/usr/share/cmake-3.7/*"), (r"^/usr/share/cmake-3.8/", "data", "/usr/share/cmake-3.8/*"), (r"^/usr/share/cmake-3.6/", "data", "/usr/share/cmake-3.6/*"), (r"^/usr/share/girepository-1\.0/.*\.typelib\$", "data", "/usr/share/girepository-1.0/*.typelib"), - (r"^/usr/include/[a-zA-Z0-9\.\_\-\+]*\.hxx", "dev", "/usr/include/*.hxx"), - (r"^/usr/include/[a-zA-Z0-9\.\_\-\+]*\.hpp", "dev", "/usr/include/*.hpp"), - (r"^/usr/include/[a-zA-Z0-9\.\_\-\+]*\.h\+\+", "dev", "/usr/include/*.h\+\+"), - (r"^/usr/include/[a-zA-Z0-9\.\_\-\+]*\.h", "dev", "/usr/include/*.h"), + (r"^/usr/include/[a-zA-Z0-9._+-]*\.hxx", "dev", "/usr/include/*.hxx"), + (r"^/usr/include/[a-zA-Z0-9._+-]*\.hpp", "dev", "/usr/include/*.hpp"), + (r"^/usr/include/[a-zA-Z0-9._+-]*\.h\+\+", "dev", "/usr/include/*.h++"), + (r"^/usr/include/[a-zA-Z0-9._+-]*\.h", "dev", "/usr/include/*.h"), (r"^/usr/include/", "dev"), (r"^/usr/lib64/girepository-1.0/", "data"), (r"^/usr/share/cmake/", "dev"), @@ -261,29 +261,29 @@ class FileManager(object): (r"^/usr/lib/qt5/", "lib"), (r"^/usr/lib64/qt5/", "lib"), (r"^/usr/lib32/qt5/", "lib32"), - (r"^/usr/lib/[a-zA-Z0-9\.\_\-\+]*\.so$", so_dest), - (r"^/usr/lib64/[a-zA-Z0-9\.\_\-\+]*\.so$", so_dest), - (r"^/usr/lib32/[a-zA-Z0-9\.\_\-\+]*\.so$", so_dest + '32'), - (r"^/usr/lib64/haswell/[a-zA-Z0-9\.\_\-\+]*\.so$", so_dest), - (r"^/usr/lib/[a-zA-Z0-9\.\_\-\+]*\.a$", "dev", "/usr/lib/*.a"), - (r"^/usr/lib64/[a-zA-Z0-9\.\_\-\+]*\.a$", "dev", "/usr/lib64/*.a"), - (r"^/usr/lib32/[a-zA-Z0-9\.\_\-\+]*\.a$", "dev32", "/usr/lib32/*.a"), - (r"^/usr/lib/haswell/[a-zA-Z0-9\.\_\-\+]*\.a$", "dev", "/usr/lib/haswell/*.a"), - (r"^/usr/lib64/haswell/[a-zA-Z0-9\.\_\-\+]*\.a$", "dev", "/usr/lib64/haswell/*.a"), - (r"^/usr/lib32/haswell/[a-zA-Z0-9\.\_\-\+]*\.a$", "dev32", "/usr/lib32/haswell/*.a"), - (r"^/usr/lib/pkgconfig/[a-zA-Z0-9\.\_\-\+]*\.pc$", "dev"), - (r"^/usr/lib64/pkgconfig/[a-zA-Z0-9\.\_\-\+]*\.pc$", "dev"), - (r"^/usr/lib32/pkgconfig/[a-zA-Z0-9\.\_\-\+]*\.pc$", "dev32"), - (r"^/usr/lib/[a-zA-Z0-9\.\_\-\+]*\.la$", "dev"), - (r"^/usr/lib64/[a-zA-Z0-9\.\_\-\+]*\.la$", "dev"), - (r"^/usr/lib32/[a-zA-Z0-9\.\_\-\+]*\.la$", "dev32"), - (r"^/usr/lib/[a-zA-Z0-9\.\_\-\+]*\.prl$", "dev"), - (r"^/usr/lib64/[a-zA-Z0-9\.\_\-\+]*\.prl$", "dev"), - (r"^/usr/lib32/[a-zA-Z0-9\.\_\-\+]*\.prl$", "dev32"), - (r"^/usr/share/aclocal/[a-zA-Z0-9\.\_\-\+]*\.ac$", "dev", "/usr/share/aclocal/*.ac"), - (r"^/usr/share/aclocal/[a-zA-Z0-9\.\_\-\+]*\.m4$", "dev", "/usr/share/aclocal/*.m4"), - (r"^/usr/share/aclocal-1.[0-9]+/[a-zA-Z0-9\.\_\-\+]*\.ac$", "dev", "/usr/share/aclocal-1.*/*.ac"), - (r"^/usr/share/aclocal-1.[0-9]+/[a-zA-Z0-9\.\_\-\+]*\.m4$", "dev", "/usr/share/aclocal-1.*/*.m4"), + (r"^/usr/lib/[a-zA-Z0-9._+-]*\.so$", so_dest), + (r"^/usr/lib64/[a-zA-Z0-9._+-]*\.so$", so_dest), + (r"^/usr/lib32/[a-zA-Z0-9._+-]*\.so$", so_dest + '32'), + (r"^/usr/lib64/haswell/[a-zA-Z0-9._+-]*\.so$", so_dest), + (r"^/usr/lib/[a-zA-Z0-9._+-]*\.a$", "dev", "/usr/lib/*.a"), + (r"^/usr/lib64/[a-zA-Z0-9._+-]*\.a$", "dev", "/usr/lib64/*.a"), + (r"^/usr/lib32/[a-zA-Z0-9._+-]*\.a$", "dev32", "/usr/lib32/*.a"), + (r"^/usr/lib/haswell/[a-zA-Z0-9._+-]*\.a$", "dev", "/usr/lib/haswell/*.a"), + (r"^/usr/lib64/haswell/[a-zA-Z0-9._+-]*\.a$", "dev", "/usr/lib64/haswell/*.a"), + (r"^/usr/lib32/haswell/[a-zA-Z0-9._+-]*\.a$", "dev32", "/usr/lib32/haswell/*.a"), + (r"^/usr/lib/pkgconfig/[a-zA-Z0-9._+-]*\.pc$", "dev"), + (r"^/usr/lib64/pkgconfig/[a-zA-Z0-9._+-]*\.pc$", "dev"), + (r"^/usr/lib32/pkgconfig/[a-zA-Z0-9._+-]*\.pc$", "dev32"), + (r"^/usr/lib/[a-zA-Z0-9._+-]*\.la$", "dev"), + (r"^/usr/lib64/[a-zA-Z0-9._+-]*\.la$", "dev"), + (r"^/usr/lib32/[a-zA-Z0-9._+-]*\.la$", "dev32"), + (r"^/usr/lib/[a-zA-Z0-9._+-]*\.prl$", "dev"), + (r"^/usr/lib64/[a-zA-Z0-9._+-]*\.prl$", "dev"), + (r"^/usr/lib32/[a-zA-Z0-9._+-]*\.prl$", "dev32"), + (r"^/usr/share/aclocal/[a-zA-Z0-9._+-]*\.ac$", "dev", "/usr/share/aclocal/*.ac"), + (r"^/usr/share/aclocal/[a-zA-Z0-9._+-]*\.m4$", "dev", "/usr/share/aclocal/*.m4"), + (r"^/usr/share/aclocal-1.[0-9]+/[a-zA-Z0-9._+-]*\.ac$", "dev", "/usr/share/aclocal-1.*/*.ac"), + (r"^/usr/share/aclocal-1.[0-9]+/[a-zA-Z0-9._+-]*\.m4$", "dev", "/usr/share/aclocal-1.*/*.m4"), (r"^/usr/share/doc/" + re.escape(tarball.name) + "/", "doc", "%doc /usr/share/doc/" + re.escape(tarball.name) + "/*"), (r"^/usr/share/doc/", "doc"), (r"^/usr/share/gtk-doc/html", "doc"), @@ -303,9 +303,9 @@ class FileManager(object): (r"^/usr/share/", "data"), # finally move any dynamically loadable plugins (not # perl/python/ruby/etc.. extensions) into lib package - (r"^/usr/lib/.*/[a-zA-Z0-9\.\_\-\+]*\.so", "lib"), - (r"^/usr/lib64/.*/[a-zA-Z0-9\.\_\-\+]*\.so", "lib"), - (r"^/usr/lib32/.*/[a-zA-Z0-9\.\_\-\+]*\.so", "lib32"), + (r"^/usr/lib/.*/[a-zA-Z0-9._+-]*\.so", "lib"), + (r"^/usr/lib64/.*/[a-zA-Z0-9._+-]*\.so", "lib"), + (r"^/usr/lib32/.*/[a-zA-Z0-9._+-]*\.so", "lib32"), # locale data gets picked up via file_is_locale (r"^/usr/share/locale/", "ignore")] diff --git a/autospec/pkg_integrity.py b/autospec/pkg_integrity.py index 2de2b76..849d44b 100644 --- a/autospec/pkg_integrity.py +++ b/autospec/pkg_integrity.py @@ -383,9 +383,9 @@ class PyPiVerifier(MD5Verifier): def parse_name(self): pkg_name = os.path.basename(self.package_path) - name, _ = re.split('-\d+\.', pkg_name, maxsplit=1) + name, _ = re.split(r'-\d+\.', pkg_name, maxsplit=1) release_no = pkg_name.replace(name + '-', '') - extensions = "({})".format("|".join(['\.tar\.gz$', '\.zip$', '\.tgz$', '\.tar\.bz2$'])) + extensions = "({})".format("|".join([r'\.tar\.gz$', r'\.zip$', r'\.tgz$', r'\.tar\.bz2$'])) ext = re.search(extensions, release_no) if ext is not None: release_no = release_no.replace(ext.group(), '') @@ -541,7 +541,7 @@ class GEMShaVerifier(Verifier): if os.path.exists(self.package_path) is False: self.print_result(False, 'GEM was not found {}'.format(self.package_path)) return - name, _ = re.split('-\d+\.', gemname) + name, _ = re.split(r'-\d+\.', gemname) number = gemname.replace(name + '-', '') geminfo = self.get_rubygems_info(name) gemsha = self.get_gemnumber_sha(geminfo, number) diff --git a/autospec/specfiles.py b/autospec/specfiles.py index 2235a67..cd3cc1a 100644 --- a/autospec/specfiles.py +++ b/autospec/specfiles.py @@ -160,10 +160,8 @@ class Specfile(object): Append additional source files - systemd unit files, gcov, and additional source tarballs are the currently supported file types. """ - for count, source in enumerate(sorted(self.sources["unit"] + - self.sources["archive"] + - self.sources["tmpfile"] + - self.sources["gcov"])): + for count, source in enumerate( + sorted(self.sources["unit"] + self.sources["archive"] + self.sources["tmpfile"] + self.sources["gcov"])): self.source_index[source] = count + 1 if self.urlban: source = re.sub(self.urlban, "localhost", source) @@ -1472,7 +1470,7 @@ class Specfile(object): quoted = '' # Capture any directive prefix separately from actual filename # (1 )(3 ) - directive_re = re.compile("(%\w+(\([^\)]*\))?\s+)(.*)") + directive_re = re.compile(r"(%\w+(\([^\)]*\))?\s+)(.*)") parts = directive_re.match(filename) if parts: # Add prefix to the output diff --git a/autospec/tarball.py b/autospec/tarball.py index d5122a3..17f407d 100644 --- a/autospec/tarball.py +++ b/autospec/tarball.py @@ -273,9 +273,9 @@ def download_tarball(target_dir): config_f = configparser.ConfigParser(interpolation=None) config_f.read('options.conf') if "package" in config_f.sections(): - if (config_f["package"].get("name") == name or - config_f["package"].get("url") == url or - config_f["package"].get("archives") == " ".join(archives)): + if (config_f["package"].get("name") == name + or config_f["package"].get("url") == url + or config_f["package"].get("archives") == " ".join(archives)): target = os.getcwd() if "giturl" in config_f["package"]: giturl = config_f["package"].get("giturl") @@ -427,8 +427,8 @@ def name_and_version(name_arg, version_arg, filemanager): # Only take the repo name as the package name if it's more descriptive name = repo elif name != repo: - name = re.sub("release-", '', name) - name = re.sub("\d*$", '', name) + name = re.sub(r"release-", '', name) + name = re.sub(r"\d*$", '', name) rawname = name version = m.group(3).replace(name, '') if "archive" not in pattern: diff --git a/autospec/test.py b/autospec/test.py index 2990724..148dc67 100644 --- a/autospec/test.py +++ b/autospec/test.py @@ -81,11 +81,11 @@ def scan_for_tests(src_dir): "perlcheck": perl_check, "setup.py": setup_check, "cmake": "cd clr-build; " + cmake_check, - "rakefile": "pushd %{buildroot}%{gem_dir}/gems/" + - tarball.tarball_prefix + - "\nrake --trace test TESTOPTS=\"-v\"\npopd", - "rspec": "pushd %{buildroot}%{gem_dir}/gems/" + - tarball.tarball_prefix + "\nrspec -I.:lib spec/\npopd" + "rakefile": "pushd %{buildroot}%{gem_dir}/gems/" + + tarball.tarball_prefix + + "\nrake --trace test TESTOPTS=\"-v\"\npopd", + "rspec": "pushd %{buildroot}%{gem_dir}/gems/" + + tarball.tarball_prefix + "\nrspec -I.:lib spec/\npopd" } if config.config_opts['32bit']: testsuites["makecheck"] += "\ncd ../build32;\n" + make_check + " || :" diff --git a/setup.cfg b/setup.cfg index 760115e..693e638 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,3 +6,7 @@ ignore = E501 [coverage:run] # omit tests and travis site-packages omit = tests/*,*site-packages*,*site.py + +[flake8] +max-line-length = 199 +ignore = E722, W503