From 935a1a5ff4f3f3b622e5cb70ceaae8dd21e3ab31 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 28 Aug 2021 18:16:19 +0200 Subject: [PATCH] fix: linter issues --- CHANGELOG.md | 8 ++-- LICENSE | 2 +- noxfile.py | 13 +++--- scripts/calculate_symbol_versions.py | 44 +++++++++---------- tests/integration/foo.f90 | 2 +- .../sample_extension/pyproject.toml | 2 +- .../sample_extension/src/sample_extension.pyx | 2 +- tests/integration/test_manylinux.py | 9 ++-- .../testpackage/testpackage/testprogram.c | 2 +- tests/unit/test_elfpatcher.py | 1 - tests/unit/test_elfutils.py | 2 +- tests/unit/test_wheel_abi.py | 8 +++- 12 files changed, 50 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2af4f9b9..a0429096 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,12 +15,12 @@ Released Apr. 3, 2021 ### User-facing changes - [BUGFIX] Patch RPATHs of non-Python extension dependencies ([#136](https://github.com/pypa/auditwheel/issues/136), [#298](https://github.com/pypa/auditwheel/pull/298)) - [BUGFIX] Ensure policies in `policy.json` are compliant with PEP600 ([#287](https://github.com/pypa/auditwheel/pull/287)) - - This removes 2 non existing symbols from manylinux1 i686 policy and removes ncurses librairies from manylinux1 whitelist. + - This removes 2 non existing symbols from manylinux1 i686 policy and removes ncurses librairies from manylinux1 whitelist. - [FEATURE] Use PEP600 policy names ([#288](https://github.com/pypa/auditwheel/pull/288), [#297](https://github.com/pypa/auditwheel/pull/297)) - The platform tag passed to `auditwheel repair` `--plat` argument can use either the PEP600 tag or the legacy tag. The repaired wheel will get both platform tags. - Inform about aliases in `auditwheel repair --help` - [FEATURE] Always repair as a single wheel ([#289](https://github.com/pypa/auditwheel/pull/289)) - - Add argument `--only-plat` to `auditwheel repair` for those who were keeping only the lowest priority tag wheel (i.e. the one requested by `--plat` argument). + - Add argument `--only-plat` to `auditwheel repair` for those who were keeping only the lowest priority tag wheel (i.e. the one requested by `--plat` argument). - [FEATURE] Add manylinux_2_27 policy ([#299](https://github.com/pypa/auditwheel/issues/299), [#300](https://github.com/pypa/auditwheel/pull/300)) - [FEATURE] Add libexpat.so.1 to whitelisted libraries starting with manylinux2010 ([#152](https://github.com/pypa/auditwheel/issues/152), [#301](https://github.com/pypa/auditwheel/pull/301)) @@ -63,7 +63,7 @@ Released Dec. 6, 2020 Released Jul. 1, 2020 ### User-facing changes -- [FEATURE] Ensure that system-copied libraries are writable before running patchelf +- [FEATURE] Ensure that system-copied libraries are writable before running patchelf ([https://github.com/pypa/auditwheel/pull/237](#237)) - [FEATURE] Preserve RPATH in extension modules ([https://github.com/pypa/auditwheel/pull/245](#245)) @@ -86,7 +86,7 @@ Released Apr. 25, 2020 Released Jan. 29, 2020 ### User-facing changes -- [FEATURE] Put libraries in `$WHEELNAME.libs` to avoid vendoring multiple copies +- [FEATURE] Put libraries in `$WHEELNAME.libs` to avoid vendoring multiple copies of the same library ([#90](https://github.com/pypa/auditwheel/pull/90)) ### Housekeeping diff --git a/LICENSE b/LICENSE index cff0d5b3..37e9426f 100644 --- a/LICENSE +++ b/LICENSE @@ -23,7 +23,7 @@ The auditwheel package is covered by the MIT license. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - + 3rd party code and data ======================= diff --git a/noxfile.py b/noxfile.py index 618c7cdf..7675b7d0 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,16 +1,15 @@ import os import sys - from pathlib import Path +from typing import List import nox - RUNNING_CI = "TRAVIS" in os.environ or "GITHUB_ACTIONS" in os.environ @nox.session(reuse_venv=True) -def lint(session: nox.Session) -> str: +def lint(session: nox.Session) -> None: """ Run linters on the codebase. """ @@ -19,7 +18,7 @@ def lint(session: nox.Session) -> str: @nox.session() -def coverage(session: nox.Session) -> str: +def coverage(session: nox.Session) -> None: """ Run coverage using unit tests. """ @@ -30,11 +29,11 @@ def coverage(session: nox.Session) -> str: "pytest", "tests/unit", "--cov=auditwheel", - "--cov-report=term-missing" + "--cov-report=term-missing", ) -def _docker_images(session): +def _docker_images(session: nox.Session) -> List[str]: tmp_dir = Path(session.create_tmp()) script = tmp_dir / "list_images.py" images_file = tmp_dir / "images.lst" @@ -51,7 +50,7 @@ def _docker_images(session): @nox.session(python=["3.6", "3.7", "3.8", "3.9"]) -def tests(session: nox.Session) -> str: +def tests(session: nox.Session) -> None: """ Run tests. """ diff --git a/scripts/calculate_symbol_versions.py b/scripts/calculate_symbol_versions.py index 7020573c..6c2599d0 100644 --- a/scripts/calculate_symbol_versions.py +++ b/scripts/calculate_symbol_versions.py @@ -4,15 +4,16 @@ This should be run inside a manylinux Docker container. """ import argparse +import json import os import platform -import json + from elftools.elf.elffile import ELFFile -if platform.architecture()[0] == '64bit': - LIBRARY_PATHS = ['/lib64', '/usr/lib64'] +if platform.architecture()[0] == "64bit": + LIBRARY_PATHS = ["/lib64", "/usr/lib64"] else: - LIBRARY_PATHS = ['/lib', '/usr/lib'] + LIBRARY_PATHS = ["/lib", "/usr/lib"] parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("policy", help="The policy name") @@ -26,9 +27,9 @@ def load_policies(path): def choose_policy(name, policies): try: - return next(policy for policy in policies if policy['name'] == name) + return next(policy for policy in policies if policy["name"] == name) except StopIteration: - raise RuntimeError("Unknown policy {}".format(name)) + raise RuntimeError(f"Unknown policy {name}") def find_library(library): @@ -37,12 +38,12 @@ def find_library(library): if os.path.exists(path): return path else: - raise RuntimeError("Unknown library {}".format(library)) + raise RuntimeError(f"Unknown library {library}") def versionify(version_string): try: - result = [int(n) for n in version_string.split('.')] + result = [int(n) for n in version_string.split(".")] assert len(result) <= 3 except ValueError: result = [999999, 999999, 999999, version_string] @@ -51,30 +52,29 @@ def versionify(version_string): def calculate_symbol_versions(libraries, symbol_versions, arch): calculated_symbol_versions = {k: set() for k in symbol_versions} - prefixes = ['/lib', '/usr/lib'] - if arch == '64bit': - prefixes = [p + '64' for p in prefixes] + prefixes = ["/lib", "/usr/lib"] + if arch == "64bit": + prefixes = [p + "64" for p in prefixes] for library in libraries: library_path = find_library(library) - with open(library_path, 'rb') as f: + with open(library_path, "rb") as f: e = ELFFile(f) - section = e.get_section_by_name('.gnu.version_d') + section = e.get_section_by_name(".gnu.version_d") if section: for _, verdef_iter in section.iter_versions(): for vernaux in verdef_iter: for symbol_name in symbol_versions: try: - name, version = vernaux.name.split('_', 1) + name, version = vernaux.name.split("_", 1) except ValueError: pass - if name in calculated_symbol_versions \ - and version != 'PRIVATE': + if ( + name in calculated_symbol_versions + and version != "PRIVATE" + ): calculated_symbol_versions[name].add(version) - return { - k: sorted(v, key=versionify) - for k, v in calculated_symbol_versions.items() - } + return {k: sorted(v, key=versionify) for k, v in calculated_symbol_versions.items()} def main(): @@ -85,8 +85,8 @@ def main(): print( json.dumps( calculate_symbol_versions( - policy['lib_whitelist'], - policy['symbol_versions'], + policy["lib_whitelist"], + policy["symbol_versions"], arch, ) ) diff --git a/tests/integration/foo.f90 b/tests/integration/foo.f90 index d3d15cfb..56311bb1 100644 --- a/tests/integration/foo.f90 +++ b/tests/integration/foo.f90 @@ -2,7 +2,7 @@ subroutine selectedrealkind(p, r, res) implicit none - + integer, intent(in) :: p, r !f2py integer :: r=0 integer, intent(out) :: res diff --git a/tests/integration/sample_extension/pyproject.toml b/tests/integration/sample_extension/pyproject.toml index 379dc2c9..9307927e 100644 --- a/tests/integration/sample_extension/pyproject.toml +++ b/tests/integration/sample_extension/pyproject.toml @@ -1,3 +1,3 @@ [build-system] requires = ["setuptools >= 45.0.0", "cython"] -build-backend = "setuptools.build_meta" \ No newline at end of file +build-backend = "setuptools.build_meta" diff --git a/tests/integration/sample_extension/src/sample_extension.pyx b/tests/integration/sample_extension/src/sample_extension.pyx index 793e7b24..78c74d23 100644 --- a/tests/integration/sample_extension/src/sample_extension.pyx +++ b/tests/integration/sample_extension/src/sample_extension.pyx @@ -2,4 +2,4 @@ def test_func(x): return _test_func(x) cdef _test_func(x): - return x + 1 \ No newline at end of file + return x + 1 diff --git a/tests/integration/test_manylinux.py b/tests/integration/test_manylinux.py index 779381f2..a684cf24 100644 --- a/tests/integration/test_manylinux.py +++ b/tests/integration/test_manylinux.py @@ -329,7 +329,8 @@ def test_build_wheel_with_binary_executable( [ "bash", "-c", - "cd /auditwheel_src/tests/integration/testpackage && python -m pip wheel --no-deps -w /io .", + "cd /auditwheel_src/tests/integration/testpackage && " + "python -m pip wheel --no-deps -w /io .", ], ) @@ -391,7 +392,8 @@ def test_build_wheel_with_image_dependencies( assert "manylinux" not in orig_wheel repair_command = ( - "LD_LIBRARY_PATH=/auditwheel_src/tests/integration/testdependencies:$LD_LIBRARY_PATH " + "LD_LIBRARY_PATH=" + "/auditwheel_src/tests/integration/testdependencies:$LD_LIBRARY_PATH " "auditwheel -v repair --plat {policy} -w /io /io/{orig_wheel}" ) @@ -522,7 +524,8 @@ def test_build_wheel_depending_on_library_with_rpath( [ "bash", "-c", - "LD_LIBRARY_PATH=/auditwheel_src/tests/integration/testrpath/a:$LD_LIBRARY_PATH " + "LD_LIBRARY_PATH=" + "/auditwheel_src/tests/integration/testrpath/a:$LD_LIBRARY_PATH " + repair_command, ], ) diff --git a/tests/integration/testpackage/testpackage/testprogram.c b/tests/integration/testpackage/testpackage/testprogram.c index dfe12720..04ea917f 100644 --- a/tests/integration/testpackage/testpackage/testprogram.c +++ b/tests/integration/testpackage/testpackage/testprogram.c @@ -24,7 +24,7 @@ int main(int argc, char **argv) fputs("Expected command line argument to be a float\n", stderr); return EXIT_FAILURE; } - + x = gsl_pow_2(x); printf("%g\n", x); return EXIT_SUCCESS; diff --git a/tests/unit/test_elfpatcher.py b/tests/unit/test_elfpatcher.py index 5cb02ac0..ccca54aa 100644 --- a/tests/unit/test_elfpatcher.py +++ b/tests/unit/test_elfpatcher.py @@ -1,4 +1,3 @@ -import os from subprocess import CalledProcessError from unittest.mock import call, patch diff --git a/tests/unit/test_elfutils.py b/tests/unit/test_elfutils.py index a637f056..eb2d1566 100644 --- a/tests/unit/test_elfutils.py +++ b/tests/unit/test_elfutils.py @@ -1,4 +1,4 @@ -from unittest.mock import MagicMock, Mock, patch +from unittest.mock import Mock, patch import pytest from elftools.common.exceptions import ELFError diff --git a/tests/unit/test_wheel_abi.py b/tests/unit/test_wheel_abi.py index ace6ab60..22b61e84 100644 --- a/tests/unit/test_wheel_abi.py +++ b/tests/unit/test_wheel_abi.py @@ -13,12 +13,16 @@ class TestGetWheelElfdata: ( # A single invalid file [os.sep.join(["purelib", "foo"])], - "Invalid binary wheel, found the following shared library/libraries in purelib folder:\n\tfoo\nThe wheel has to be platlib compliant in order to be repaired by auditwheel.", + "Invalid binary wheel, found the following shared library/libraries in" + " purelib folder:\n\tfoo\nThe wheel has to be platlib compliant in " + "order to be repaired by auditwheel.", ), ( # Multiple invalid files [os.sep.join(["purelib", "foo"]), os.sep.join(["purelib", "bar"])], - "Invalid binary wheel, found the following shared library/libraries in purelib folder:\n\tfoo\n\tbar\nThe wheel has to be platlib compliant in order to be repaired by auditwheel.", + "Invalid binary wheel, found the following shared library/libraries in" + " purelib folder:\n\tfoo\n\tbar\nThe wheel has to be platlib compliant" + " in order to be repaired by auditwheel.", ), ], )