Skip to content

Commit 01667eb

Browse files
committed
Fix linter issue
1 parent 63a0ded commit 01667eb

19 files changed

+103
-70
lines changed

auditwheel/condatools.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,36 @@
22
conda packages.
33
"""
44
import os
5+
from typing import List, Optional
56

67
from .tmpdirs import InTemporaryDirectory
78
from .tools import tarbz2todir
89

910

1011
class InCondaPkg(InTemporaryDirectory):
11-
def __init__(self, in_conda_pkg):
12+
def __init__(self, in_conda_pkg: str) -> None:
1213
"""Initialize in-conda-package context manager"""
1314
self.in_conda_pkg = os.path.abspath(in_conda_pkg)
1415
super().__init__()
1516

16-
def __enter__(self):
17+
def __enter__(self) -> str:
1718
tarbz2todir(self.in_conda_pkg, self.name)
1819
return super().__enter__()
1920

2021

2122
class InCondaPkgCtx(InCondaPkg):
22-
def __init__(self, in_conda_pkg):
23+
def __init__(self, in_conda_pkg: str) -> None:
2324
super().__init__(in_conda_pkg)
24-
self.path = None
25+
self.path: Optional[str] = None
2526

2627
def __enter__(self):
2728
self.path = super().__enter__()
2829
return self
2930

30-
def iter_files(self):
31+
def iter_files(self) -> List[str]:
32+
if self.path is None:
33+
raise ValueError(
34+
"This function should be called from context manager")
3135
files = os.path.join(self.path, 'info', 'files')
3236
with open(files) as f:
3337
return [line.strip() for line in f.readlines()]

auditwheel/elfutils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from os.path import basename, realpath, relpath
33
from .lddtree import parse_ld_paths
44

5-
from elftools.elf.elffile import ELFFile # type: ignore
6-
from elftools.common.exceptions import ELFError # type: ignore
5+
from elftools.elf.elffile import ELFFile
6+
from elftools.common.exceptions import ELFError
77
from typing import Iterator, Tuple, Optional, Dict, List
88

99

@@ -78,7 +78,8 @@ def elf_references_PyFPE_jbuf(elf: ELFFile) -> bool:
7878
return False
7979

8080

81-
def elf_is_python_extension(fn, elf) -> Tuple[bool, Optional[int]]:
81+
def elf_is_python_extension(fn: str,
82+
elf: ELFFile) -> Tuple[bool, Optional[int]]:
8283
modname = basename(fn).split('.', 1)[0]
8384
module_init_f = {
8485
'init' + modname: 2,

auditwheel/genericpkgctx.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
from typing import Optional, Union
12
from .wheeltools import InWheelCtx
23
from .condatools import InCondaPkgCtx
34

45

5-
def InGenericPkgCtx(in_path, out_path=None):
6+
def InGenericPkgCtx(
7+
in_path: str, out_path: Optional[str] = None
8+
) -> Union[InWheelCtx, InCondaPkgCtx]:
69
"""Factory that returns a InWheelCtx or InCondaPkgCtx
710
context manager depending on the file extension
811
"""

auditwheel/hashfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import hashlib
2+
from typing import BinaryIO
23

34

4-
def hashfile(afile, blocksize=65536):
5+
def hashfile(afile: BinaryIO, blocksize: int = 65536) -> str:
56
"""Hash the contents of an open file handle with SHA256"""
67
hasher = hashlib.sha256()
78
buf = afile.read(blocksize)

auditwheel/lddtree.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import errno
1818
import logging
1919
import functools
20-
from typing import List, Dict, Optional, Any
20+
from typing import List, Dict, Optional, Any, Tuple
2121

22-
from elftools.elf.elffile import ELFFile # type: ignore
22+
from elftools.elf.elffile import ELFFile
2323

2424
log = logging.getLogger(__name__)
2525
__all__ = ['lddtree']
@@ -75,7 +75,7 @@ def dedupe(items: List[str]) -> List[str]:
7575
return [seen.setdefault(x, x) for x in items if x not in seen]
7676

7777

78-
def parse_ld_paths(str_ldpaths, root='', path=None) -> List[str]:
78+
def parse_ld_paths(str_ldpaths: str, path: str, root: str = '') -> List[str]:
7979
"""Parse the colon-delimited list of paths and apply ldso rules to each
8080
8181
Note the special handling as dictated by the ldso:
@@ -204,7 +204,7 @@ def load_ld_paths(root: str = '/', prefix: str = '') -> Dict[str, List[str]]:
204204
return ldpaths
205205

206206

207-
def compatible_elfs(elf1, elf2):
207+
def compatible_elfs(elf1: ELFFile, elf2: ELFFile) -> bool:
208208
"""See if two ELFs are compatible
209209
210210
This compares the aspects of the ELF to see if they're compatible:
@@ -232,7 +232,8 @@ def compatible_elfs(elf1, elf2):
232232
elf1.header['e_machine'] == elf2.header['e_machine'])
233233

234234

235-
def find_lib(elf, lib, ldpaths, root='/'):
235+
def find_lib(elf: ELFFile, lib: str, ldpaths: List[str],
236+
root: str = '/') -> Tuple[Optional[str], Optional[str]]:
236237
"""Try to locate a ``lib`` that is compatible to ``elf`` in the given
237238
``ldpaths``
238239
@@ -370,13 +371,13 @@ def lddtree(path: str,
370371
if t.entry.d_tag == 'DT_RPATH':
371372
rpaths = parse_ld_paths(
372373
t.rpath,
373-
root=root,
374-
path=path)
374+
path=path,
375+
root=root)
375376
elif t.entry.d_tag == 'DT_RUNPATH':
376377
runpaths = parse_ld_paths(
377378
t.runpath,
378-
root=root,
379-
path=path)
379+
path=path,
380+
root=root)
380381
elif t.entry.d_tag == 'DT_NEEDED':
381382
libs.append(t.needed)
382383
if runpaths:
@@ -412,7 +413,7 @@ def lddtree(path: str,
412413
'path': fullpath,
413414
'needed': [],
414415
}
415-
if fullpath:
416+
if realpath and fullpath:
416417
lret = lddtree(realpath,
417418
root,
418419
prefix,

auditwheel/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
import sys
33
import logging
44
import argparse
5-
import pkg_resources # type: ignore
5+
import pkg_resources
6+
from typing import Optional
67

78
from . import main_show
89
from . import main_addtag
910
from . import main_lddtree
1011
from . import main_repair
1112

1213

13-
def main():
14+
def main() -> Optional[int]:
1415
if sys.platform != 'linux':
1516
print('Error: This tool only supports Linux')
1617
return 1
@@ -45,7 +46,7 @@ def main():
4546

4647
if not hasattr(args, 'func'):
4748
p.print_help()
48-
return
49+
return None
4950

5051
rval = args.func(args, p)
5152

auditwheel/main_addtag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def configure_parser(sub_parsers):
2222

2323
def execute(args, p):
2424
import os
25-
from ._vendor.wheel.wheelfile import WHEEL_INFO_RE # type: ignore
25+
from ._vendor.wheel.wheelfile import WHEEL_INFO_RE
2626
from .wheeltools import InWheelCtx, add_platforms, WheelToolsError
2727
from .wheel_abi import analyze_wheel_abi, NonPlatformWheel
2828

auditwheel/main_lddtree.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
32
logger = logging.getLogger(__name__)
43

54

auditwheel/main_show.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def configure_parser(sub_parsers):
1212
p.set_defaults(func=execute)
1313

1414

15-
def printp(text):
15+
def printp(text: str) -> None:
1616
from textwrap import wrap
1717
print()
1818
print('\n'.join(wrap(text)))

auditwheel/patcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _verify_patchelf() -> None:
4646

4747

4848
class Patchelf(ElfPatcher):
49-
def __init__(self):
49+
def __init__(self) -> None:
5050
_verify_patchelf()
5151

5252
def replace_needed(self,

0 commit comments

Comments
 (0)