style: apply some cleanups from Sourcery.ai (#626)

* style: apply some fixes from Sorcery

* Apply suggestions from code review

Co-authored-by: Yannick Jadoul <yannick.jadoul@belgacom.net>
Co-authored-by: Joe Rickerby <joerick@mac.com>

Co-authored-by: Yannick Jadoul <yannick.jadoul@belgacom.net>
Co-authored-by: Joe Rickerby <joerick@mac.com>
This commit is contained in:
Henry Schreiner
2021-03-24 23:23:27 +01:00
committed by GitHub
co-authored by Yannick Jadoul Joe Rickerby
parent 96aa38b56c
commit 5cbe3e2254
12 changed files with 35 additions and 47 deletions
+1 -2
View File
@@ -91,12 +91,11 @@ class WindowsVersions:
version = versions[-1]
identifier = f"cp{version.major}{version.minor}-{self.arch}"
result = ConfigWinCP(
return ConfigWinCP(
identifier=identifier,
version=str(version),
arch=self.arch_str,
)
return result
class PyPyVersions:
+2 -3
View File
@@ -367,9 +367,8 @@ def detect_warnings(platform: str, build_options: BuildOptions) -> List[str]:
for option_name in ['test_command', 'before_build']:
option_value = getattr(build_options, option_name)
if option_value:
if '{python}' in option_value or '{pip}' in option_value:
warnings.append(option_name + ": '{python}' and '{pip}' are no longer needed, and will be removed in a future release. Simply use 'python' or 'pip' instead.")
if option_value and ('{python}' in option_value or '{pip}' in option_value):
warnings.append(option_name + ": '{python}' and '{pip}' are no longer needed, and will be removed in a future release. Simply use 'python' or 'pip' instead.")
return warnings
+1 -3
View File
@@ -85,9 +85,7 @@ def evaluate_nodes_as_compound_command(nodes: Sequence[bashlex.ast.node], contex
if node.kind == 'command':
result += evaluate_command_node(node, context=context)
elif node.kind == 'operator':
if node.op == ';':
pass
else:
if node.op != ';':
raise ValueError(f'Unsupported bash operator: "{node.op}"')
else:
raise ValueError(f'Unsupported bash node in compound command: "{node.kind}"')
+6 -7
View File
@@ -14,11 +14,10 @@ class InlineArrayDictEncoder(toml.encoder.TomlEncoder): # type: ignore
self.dump_funcs[Version] = lambda v: f'"{v}"'
def dump_sections(self, o: Dict[str, Any], sup: str) -> Any:
if all(isinstance(a, list) for a in o.values()):
val = ""
for k, v in o.items():
inner = ",\n ".join(self.dump_inline_table(d_i).strip() for d_i in v)
val += f"{k} = [\n {inner},\n]\n"
return val, self._dict()
else:
if not all(isinstance(a, list) for a in o.values()):
return super().dump_sections(o, sup)
val = ""
for k, v in o.items():
inner = ",\n ".join(self.dump_inline_table(d_i).strip() for d_i in v)
val += f"{k} = [\n {inner},\n]\n"
return val, self._dict()
+1 -1
View File
@@ -253,5 +253,5 @@ def troubleshoot(package_dir: Path, error: Exception) -> None:
'''), file=sys.stderr)
print(' Files detected:')
print('\n'.join([f' {f}' for f in so_files]))
print('\n'.join(f' {f}' for f in so_files))
print('')
+12 -12
View File
@@ -257,23 +257,23 @@ def setup_python(python_configuration: PythonConfiguration,
# set ARCHFLAGS otherwise CPython sets it to `-arch x86_64`
env.setdefault('ARCHFLAGS', '-arch arm64 -arch x86_64')
if python_configuration.identifier.endswith('arm64') or python_configuration.identifier.endswith('universal2'):
if get_macos_version() < (10, 16) and 'SDKROOT' not in env:
# xcode 12.2 or higher can build arm64 on macos 10.15 or below, but
# needs the correct SDK selected.
sdks = get_macos_sdks()
building_arm64 = python_configuration.identifier.endswith('arm64') or python_configuration.identifier.endswith('universal2')
if building_arm64 and get_macos_version() < (10, 16) and 'SDKROOT' not in env:
# xcode 12.2 or higher can build arm64 on macos 10.15 or below, but
# needs the correct SDK selected.
sdks = get_macos_sdks()
# Different versions of Xcode contain different SDK versions...
# we're happy with anything newer than macOS 11.0
arm64_compatible_sdks = [s for s in sdks if not s.startswith('macosx10.')]
# Different versions of Xcode contain different SDK versions...
# we're happy with anything newer than macOS 11.0
arm64_compatible_sdks = [s for s in sdks if not s.startswith('macosx10.')]
if not arm64_compatible_sdks:
log.warning(unwrap('''
if not arm64_compatible_sdks:
log.warning(unwrap('''
SDK for building arm64-compatible wheels not found. You need Xcode 12.2 or later
to build universal2 or arm64 wheels.
'''))
else:
env.setdefault('SDKROOT', arm64_compatible_sdks[0])
else:
env.setdefault('SDKROOT', arm64_compatible_sdks[0])
log.step('Installing build tools...')
call(['pip', 'install', '--upgrade', 'setuptools', 'wheel', 'delocate', *dependency_constraint_flags], env=env)
+1 -3
View File
@@ -209,9 +209,7 @@ class NonPlatformWheelError(Exception):
def strtobool(val: str) -> bool:
if val.lower() in ('y', 'yes', 't', 'true', 'on', '1'):
return True
return False
return val.lower() in {'y', 'yes', 't', 'true', 'on', '1'}
class CIProvider(Enum):
+1 -1
View File
@@ -44,7 +44,7 @@ def shell(command: str, env: Optional[Dict[str, str]] = None, cwd: Optional[str]
def get_nuget_args(version: str, arch: str) -> List[str]:
python_name = 'python' if version[0] == '3' else 'python2'
if arch == '32':
python_name = python_name + 'x86'
python_name += 'x86'
return [python_name, '-Version', version, '-OutputDirectory', 'C:\\cibw\\python']
+6 -7
View File
@@ -40,11 +40,10 @@ VERSION_REGEX = r'([\w-]+)==([^\s]+)'
def get_versions_from_constraint_file(constraint_file):
constraint_file_text = constraint_file.read_text(encoding='utf8')
versions = {}
for package, version in re.findall(VERSION_REGEX, constraint_file_text):
versions[package] = version
return versions
return {
package: version
for package, version in re.findall(VERSION_REGEX, constraint_file_text)
}
@pytest.mark.parametrize('python_version', ['2.7', '3.5', '3.6', '3.8'])
@@ -91,7 +90,7 @@ def test_pinned_versions(tmp_path, python_version):
build_environment[env_name] = constraint_versions[package]
cibw_environment_option = ' '.join(
[f'{k}={v}' for k, v in build_environment.items()]
f'{k}={v}' for k, v in build_environment.items()
)
# build and test the wheels
@@ -154,7 +153,7 @@ def test_dependency_constraints_file(tmp_path, python_version):
build_environment[env_name] = version
cibw_environment_option = ' '.join(
[f'{k}={v}' for k, v in build_environment.items()]
f'{k}={v}' for k, v in build_environment.items()
)
# build and test the wheels
+1 -1
View File
@@ -94,7 +94,7 @@ def test_binary_output():
data = bytes(output, encoding='utf8', errors='surrogateescape')
for i in range(0, 512):
for i in range(512):
assert data[i] == i % 256
# check that environment variables can carry binary data, except null characters
+1 -1
View File
@@ -134,7 +134,7 @@ def test_repair_command(repair_command, platform_specific, platform, intercepted
])
@pytest.mark.parametrize('platform_specific', [False, True])
def test_environment(environment, platform_specific, platform, intercepted_build_args, monkeypatch):
env_string = ' '.join([f'{k}={v}' for k, v in environment.items()])
env_string = ' '.join(f'{k}={v}' for k, v in environment.items())
if platform_specific:
monkeypatch.setenv('CIBW_ENVIRONMENT_' + platform.upper(), env_string)
monkeypatch.setenv('CIBW_ENVIRONMENT', 'overwritten')
+2 -6
View File
@@ -123,12 +123,10 @@ def test_archs_platform_native(platform, intercepted_build_args, monkeypatch):
main()
build_options = intercepted_build_args.args[0]
if platform == 'linux':
if platform in {'linux', 'macos'}:
assert build_options.architectures == {Architecture.x86_64}
elif platform == 'windows':
assert build_options.architectures == {Architecture.AMD64}
elif platform == 'macos':
assert build_options.architectures == {Architecture.x86_64}
def test_archs_platform_auto64(platform, intercepted_build_args, monkeypatch):
@@ -137,12 +135,10 @@ def test_archs_platform_auto64(platform, intercepted_build_args, monkeypatch):
main()
build_options = intercepted_build_args.args[0]
if platform == 'linux':
if platform in {'linux', 'macos'}:
assert build_options.architectures == {Architecture.x86_64}
elif platform == 'windows':
assert build_options.architectures == {Architecture.AMD64}
elif platform == 'macos':
assert build_options.architectures == {Architecture.x86_64}
def test_archs_platform_auto32(platform, intercepted_build_args, monkeypatch):