Skip to content

Commit cb85ff2

Browse files
committed
fix long-standing linting problems
1 parent 1bb5984 commit cb85ff2

File tree

7 files changed

+36
-58
lines changed

7 files changed

+36
-58
lines changed

mesonbuild/build.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,6 @@ def link_whole(self, targets: T.List[BuildTargetTypes], promoted: bool = False)
14731473
msg = f"Can't link non-PIC static library {t.name!r} into shared library {self.name!r}. "
14741474
msg += "Use the 'pic' option to static_library to build with PIC."
14751475
raise InvalidArguments(msg)
1476-
14771476
self.check_can_link_together(t)
14781477
if isinstance(self, StaticLibrary):
14791478
# When we're a static library and we link_whole: to another static
@@ -1495,29 +1494,11 @@ def get_internal_static_libraries(self) -> OrderedSet[BuildTargetTypes]:
14951494
def get_internal_static_libraries_recurse(self, result: OrderedSet[BuildTargetTypes]) -> None:
14961495
for t in self.link_targets:
14971496
if t.is_internal() and t not in result:
1498-
self.check_can_extract_objects(t, origin, promoted=True)
14991497
result.add(t)
1500-
t.get_internal_static_libraries_recurse(result, origin)
1498+
t.get_internal_static_libraries_recurse(result)
15011499
for t in self.link_whole_targets:
15021500
if t.is_internal():
1503-
t.get_internal_static_libraries_recurse(result, origin)
1504-
1505-
def check_can_extract_objects(self, t: T.Union[Target, CustomTargetIndex], origin: StaticLibrary, promoted: bool = False) -> None:
1506-
if isinstance(t, (CustomTarget, CustomTargetIndex)) or t.uses_rust():
1507-
# To extract objects from a custom target we would have to extract
1508-
# the archive, WIP implementation can be found in
1509-
# https://github.com/mesonbuild/meson/pull/9218.
1510-
# For Rust C ABI we could in theory have access to objects, but there
1511-
# are several meson issues that need to be fixed:
1512-
# https://github.com/mesonbuild/meson/issues/10722
1513-
# https://github.com/mesonbuild/meson/issues/10723
1514-
# https://github.com/mesonbuild/meson/issues/10724
1515-
m = (f'Cannot link_whole a custom or Rust target {t.name!r} into a static library {origin.name!r}. '
1516-
'Instead, pass individual object files with the "objects:" keyword argument if possible.')
1517-
if promoted:
1518-
m += (f' Meson had to promote link to link_whole because {origin.name!r} is installed but not {t.name!r},'
1519-
f' and thus has to include objects from {t.name!r} to be usable.')
1520-
raise InvalidArguments(m)
1501+
t.get_internal_static_libraries_recurse(result)
15211502

15221503
def _bundle_static_library(self, t: T.Union[BuildTargetTypes], promoted: bool = False) -> None:
15231504
if self.uses_rust():

mesonbuild/dependencies/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
ExternalLibrary, DependencyException, DependencyMethods,
88
BuiltinDependency, SystemDependency, get_leaf_external_dependencies)
99
from .detect import find_external_dependency, get_dep_identifier, packages, _packages_accept_language
10-
from .blas_lapack import openblas_factory
1110

1211

1312
__all__ = [

mesonbuild/dependencies/blas_lapack.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
from ..mesonlib import MachineChoice
2727
from ..options import OptionKey
2828

29-
from .base import DependencyMethods, SystemDependency
29+
from .base import DependencyMethods, SystemDependency, DependencyException
3030
from .cmake import CMakeDependency
3131
from .detect import packages
3232
from .factory import DependencyFactory, factory_methods
3333
from .pkgconfig import PkgConfigDependency
3434

3535
if T.TYPE_CHECKING:
3636
from ..environment import Environment
37+
from . factory import DependencyGenerator
3738

3839
"""
3940
TODO: how to select BLAS interface layer (LP64, ILP64)?
@@ -303,7 +304,7 @@
303304
"""
304305

305306

306-
def check_blas_machine_file(self, name: str, props: dict) -> T.Tuple[bool, T.List[str]]:
307+
def check_blas_machine_file(name: str, props: dict) -> T.Tuple[bool, T.List[str]]:
307308
# TBD: do we need to support multiple extra dirs?
308309
incdir = props.get(f'{name}_includedir')
309310
assert incdir is None or isinstance(incdir, str)
@@ -364,11 +365,11 @@ def check_symbols(self, compile_args, suffix=None, check_cblas=True,
364365
prototypes = "".join(f"void {symbol}{suffix}();\n" for symbol in symbols)
365366
calls = " ".join(f"{symbol}{suffix}();\n" for symbol in symbols)
366367
code = (f"{prototypes}"
367-
"int main(int argc, const char *argv[])\n"
368-
"{\n"
368+
"int main(int argc, const char *argv[])\n"
369+
"{\n"
369370
f" {calls}"
370-
" return 0;\n"
371-
"}"
371+
" return 0;\n"
372+
"}"
372373
)
373374
code = '''#ifdef __cplusplus
374375
extern "C" {
@@ -720,7 +721,6 @@ def detect_lapack_machine_file(self, props: dict) -> None:
720721
self.detect([libdir], [incdir])
721722

722723

723-
724724
class AccelerateSystemDependency(BLASLAPACKMixin, SystemDependency):
725725
"""
726726
Accelerate is always installed on macOS, and not available on other OSes.
@@ -781,7 +781,6 @@ def detect(self, kwargs: T.Dict[str, T.Any]) -> None:
781781

782782
# We won't check symbols here, because Accelerate is built in a consistent fashion
783783
# with known symbol mangling, unlike OpenBLAS or Netlib BLAS/LAPACK.
784-
return None
785784

786785
def get_symbol_suffix(self) -> str:
787786
return '$NEWLAPACK' if self.interface == 'lp64' else '$NEWLAPACK$ILP64'
@@ -804,7 +803,7 @@ def parse_mkl_options(self, kwargs: T.Dict[str, T.Any]) -> None:
804803
if not threading_module:
805804
self.threading = 'iomp'
806805
elif len(threading_module) > 1:
807-
raise mesonlib.MesonException(f'Multiple threading arguments: {threading_modules}')
806+
raise mesonlib.MesonException(f'Multiple threading arguments: {threading_module}')
808807
else:
809808
# We have a single threading option specified - validate and process it
810809
opt = threading_module[0]
@@ -818,7 +817,7 @@ def parse_mkl_options(self, kwargs: T.Dict[str, T.Any]) -> None:
818817
if not sdl_module:
819818
self.use_sdl = 'auto'
820819
elif len(sdl_module) > 1:
821-
raise mesonlib.MesonException(f'Multiple sdl arguments: {threading_modules}')
820+
raise mesonlib.MesonException(f'Multiple sdl arguments: {threading_module}')
822821
else:
823822
# We have a single sdl option specified - validate and process it
824823
opt = sdl_module[0]
@@ -845,8 +844,6 @@ def parse_mkl_options(self, kwargs: T.Dict[str, T.Any]) -> None:
845844
raise mesonlib.MesonException(f'Linking SDL implies using LP64 and Intel OpenMP, found '
846845
f'conflicting options: {self.interface}, {self.threading}')
847846

848-
return None
849-
850847

851848
class MKLPkgConfigDependency(BLASLAPACKMixin, MKLMixin, PkgConfigDependency):
852849
"""
@@ -896,7 +893,6 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
896893

897894
if self.use_sdl:
898895
self.detect_sdl()
899-
return None
900896

901897
def detect_sdl(self) -> None:
902898
# Use MKLROOT in addition to standard libdir(s)
@@ -926,7 +922,7 @@ def detect_sdl(self) -> None:
926922
self.is_found = True
927923
self.compile_args += incdir_args
928924
self.link_args += link_arg
929-
if not sys.platform == 'win32':
925+
if sys.platform != 'win32':
930926
self.link_args += ['-lpthread', '-lm', '-ldl']
931927

932928
# Determine MKL version

mesonbuild/linkers/linkers.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,9 +1396,6 @@ def rsp_file_syntax(self) -> RSPFileSyntax:
13961396
def get_pie_args(self) -> T.List[str]:
13971397
return []
13981398

1399-
def get_pie_args(self) -> T.List[str]:
1400-
return []
1401-
14021399

14031400
class MSVCDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker):
14041401

mesonbuild/modules/features/feature.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import re
44
from typing import (
55
Dict, Set, Tuple, List, Callable, Optional,
6-
Union, Any, Iterable, cast, TYPE_CHECKING
6+
Union, Any, Iterable, TYPE_CHECKING
77
)
88
from dataclasses import dataclass, field
99
from ...mesonlib import File, MesonException
@@ -18,7 +18,6 @@
1818
from typing import TypedDict
1919
from typing_extensions import NotRequired
2020
from ...interpreterbase import TYPE_var, TYPE_kwargs
21-
from ...compilers import Compiler
2221
from .. import ModuleState
2322

2423
@dataclass(unsafe_hash=True, order=True)
@@ -80,7 +79,7 @@ def __init__(self, func_name: str, opt_name: str, default: Any = None):
8079
)
8180

8281
@staticmethod
83-
def convert(func_name:str, opt_name: str, values: 'IMPLIED_ATTR',
82+
def convert(func_name: str, opt_name: str, values: 'IMPLIED_ATTR',
8483
) -> Union[None, List[ConflictAttr]]:
8584
if values is None:
8685
return None
@@ -131,6 +130,7 @@ def convert(func_name:str, opt_name: str, values: 'IMPLIED_ATTR',
131130
Union[str, Dict[str, str]]
132131
]
133132
]
133+
134134
class FeatureKwArgs(TypedDict):
135135
#implies: Optional[List['FeatureObject']]
136136
implies: NotRequired[List[Any]]
@@ -163,7 +163,8 @@ def __init__(self, state: 'ModuleState',
163163
super().__init__()
164164

165165
@typed_pos_args('features.new', str, int)
166-
@typed_kwargs('features.new',
166+
@typed_kwargs(
167+
'features.new',
167168
KwargInfo(
168169
'implies',
169170
(FeatureObject, ContainerTypeInfo(list, FeatureObject)),
@@ -209,7 +210,8 @@ def init_attrs(state: 'ModuleState',
209210
def update_method(self, state: 'ModuleState', args: List['TYPE_var'],
210211
kwargs: 'TYPE_kwargs') -> 'FeatureObject':
211212
@noPosargs
212-
@typed_kwargs('features.FeatureObject.update',
213+
@typed_kwargs(
214+
'features.FeatureObject.update',
213215
KwargInfo('name', (NoneType, str)),
214216
KwargInfo('interest', (NoneType, int)),
215217
KwargInfo(
@@ -306,7 +308,7 @@ def sort_cb(k: Union[FeatureObject, Iterable[FeatureObject]]) -> int:
306308
# FIXME: that's not a safe way to increase the rank for
307309
# multi features this why this function isn't considerd
308310
# accurate.
309-
rank += len(prevalent_features) -1
311+
rank += len(prevalent_features) - 1
310312
return rank
311313
return sorted(features, reverse=reverse, key=sort_cb)
312314

mesonbuild/modules/features/module.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from typing import TypedDict
2121
from ...interpreterbase import TYPE_var, TYPE_kwargs
2222
from .. import ModuleState
23-
from .feature import FeatureKwArgs
2423

2524
class TestKwArgs(TypedDict):
2625
compiler: Optional[Compiler]
@@ -109,6 +108,7 @@ def add_target(self, features: Union[FeatureObject, List[FeatureObject]],
109108

110109
class Module(NewExtensionModule):
111110
INFO = ModuleInfo('features', '0.1.0')
111+
112112
def __init__(self) -> None:
113113
super().__init__()
114114
self.methods.update({
@@ -142,7 +142,8 @@ def _set_cache(self, state: 'ModuleState', key: str,
142142
self._cache_dict(state)[key] = val
143143

144144
@typed_pos_args('features.test', varargs=FeatureObject, min_varargs=1)
145-
@typed_kwargs('features.test',
145+
@typed_kwargs(
146+
'features.test',
146147
KwargInfo('compiler', (NoneType, Compiler)),
147148
KwargInfo('anyfet', bool, default = False),
148149
KwargInfo('cached', bool, default = True),
@@ -255,7 +256,7 @@ def test_any(self, state: 'ModuleState', features: Set[FeatureObject],
255256
features_any = set()
256257
for fet in all_features:
257258
_, test_any_result = self.cached_test(
258-
state, features={fet,},
259+
state, features={fet, },
259260
compiler=compiler,
260261
cached=cached,
261262
anyfet=False,
@@ -293,7 +294,7 @@ def test(self, state: 'ModuleState', features: Set[FeatureObject],
293294
# Set the highest interested feature
294295
prevalent_features = sorted(features)[-1:]
295296

296-
prevalent_names = [fet.name for fet in prevalent_features]
297+
prevalent_names = [fet.name for fet in prevalent_features]
297298
# prepare the result dict
298299
test_result: 'TestResultKwArgs' = {
299300
'target_name': '__'.join(prevalent_names),
@@ -307,6 +308,7 @@ def test(self, state: 'ModuleState', features: Set[FeatureObject],
307308
'is_disabled': False,
308309
'fail_reason': '',
309310
}
311+
310312
def fail_result(fail_reason: str, is_disabled: bool = False
311313
) -> 'TestResultKwArgs':
312314
test_result.update({
@@ -337,7 +339,7 @@ def fail_result(fail_reason: str, is_disabled: bool = False
337339
predecessor_features = implied_features.difference(_caller)
338340
for fet in sorted(predecessor_features):
339341
_, pred_result = self.cached_test(
340-
state, features={fet,},
342+
state, features={fet, },
341343
compiler=compiler,
342344
cached=cached,
343345
anyfet=False,
@@ -431,7 +433,8 @@ def fail_result(fail_reason: str, is_disabled: bool = False
431433
build.GeneratedList, build.StructuredSources, build.ExtractedObjects,
432434
build.BuildTarget
433435
))
434-
@typed_kwargs('features.multi_targets',
436+
@typed_kwargs(
437+
'features.multi_targets',
435438
KwargInfo(
436439
'dispatch', (
437440
ContainerTypeInfo(list, (FeatureObject, list)),
@@ -451,8 +454,8 @@ def fail_result(fail_reason: str, is_disabled: bool = False
451454
allow_unknown=True
452455
)
453456
def multi_targets_method(self, state: 'ModuleState',
454-
args: Tuple[str], kwargs: 'TYPE_kwargs'
455-
) -> TargetsObject:
457+
args: Tuple[str], kwargs: 'TYPE_kwargs'
458+
) -> TargetsObject:
456459
config_name = args[0]
457460
sources = args[1] # type: ignore
458461
dispatch: List[Union[FeatureObject, List[FeatureObject]]] = (
@@ -467,7 +470,7 @@ def multi_targets_method(self, state: 'ModuleState',
467470
if not compiler:
468471
compiler = get_compiler(state)
469472

470-
baseline_features : Set[FeatureObject] = set()
473+
baseline_features: Set[FeatureObject] = set()
471474
has_baseline = baseline is not None
472475
if has_baseline:
473476
baseline_features = FeatureObject.get_implicit_combine_multi(baseline)
@@ -488,7 +491,7 @@ def multi_targets_method(self, state: 'ModuleState',
488491
]] = []
489492
for d in dispatch:
490493
if isinstance(d, FeatureObject):
491-
target = {d,}
494+
target = {d, }
492495
is_base_part = d in baseline_features
493496
else:
494497
target = set(d)
@@ -647,7 +650,7 @@ def gen_config(self, state: 'ModuleState', config_name: str,
647650
c_detect = '1'
648651
dispatch_calls.append(
649652
f'{prefix}_MTARGETS_EXPAND('
650-
f'EXEC_CB({c_detect}, {test["target_name"]}, __VA_ARGS__)'
653+
f'EXEC_CB({c_detect}, {test["target_name"]}, __VA_ARGS__)'
651654
')'
652655
)
653656

@@ -683,7 +686,8 @@ def gen_config(self, state: 'ModuleState', config_name: str,
683686
return config_path
684687

685688
@typed_pos_args('features.sort', varargs=FeatureObject, min_varargs=1)
686-
@typed_kwargs('features.sort',
689+
@typed_kwargs(
690+
'features.sort',
687691
KwargInfo('reverse', bool, default = False),
688692
)
689693
def sort_method(self, state: 'ModuleState',

mesonbuild/modules/features/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def test_code(state: 'ModuleState', compiler: 'Compiler',
3333

3434
def generate_hash(*args: Any) -> str:
3535
hasher = hashlib.sha1()
36-
test: List[bytes] = []
3736
for a in args:
3837
hasher.update(bytes(str(a), encoding='utf-8'))
3938
return hasher.hexdigest()

0 commit comments

Comments
 (0)