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:
co-authored by
Yannick Jadoul
Joe Rickerby
parent
96aa38b56c
commit
5cbe3e2254
@@ -91,12 +91,11 @@ class WindowsVersions:
|
|||||||
|
|
||||||
version = versions[-1]
|
version = versions[-1]
|
||||||
identifier = f"cp{version.major}{version.minor}-{self.arch}"
|
identifier = f"cp{version.major}{version.minor}-{self.arch}"
|
||||||
result = ConfigWinCP(
|
return ConfigWinCP(
|
||||||
identifier=identifier,
|
identifier=identifier,
|
||||||
version=str(version),
|
version=str(version),
|
||||||
arch=self.arch_str,
|
arch=self.arch_str,
|
||||||
)
|
)
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
class PyPyVersions:
|
class PyPyVersions:
|
||||||
|
|||||||
@@ -367,8 +367,7 @@ def detect_warnings(platform: str, build_options: BuildOptions) -> List[str]:
|
|||||||
for option_name in ['test_command', 'before_build']:
|
for option_name in ['test_command', 'before_build']:
|
||||||
option_value = getattr(build_options, option_name)
|
option_value = getattr(build_options, option_name)
|
||||||
|
|
||||||
if option_value:
|
if option_value and ('{python}' in option_value or '{pip}' in 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.")
|
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
|
return warnings
|
||||||
|
|||||||
@@ -85,9 +85,7 @@ def evaluate_nodes_as_compound_command(nodes: Sequence[bashlex.ast.node], contex
|
|||||||
if node.kind == 'command':
|
if node.kind == 'command':
|
||||||
result += evaluate_command_node(node, context=context)
|
result += evaluate_command_node(node, context=context)
|
||||||
elif node.kind == 'operator':
|
elif node.kind == 'operator':
|
||||||
if node.op == ';':
|
if node.op != ';':
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise ValueError(f'Unsupported bash operator: "{node.op}"')
|
raise ValueError(f'Unsupported bash operator: "{node.op}"')
|
||||||
else:
|
else:
|
||||||
raise ValueError(f'Unsupported bash node in compound command: "{node.kind}"')
|
raise ValueError(f'Unsupported bash node in compound command: "{node.kind}"')
|
||||||
|
|||||||
@@ -14,11 +14,10 @@ class InlineArrayDictEncoder(toml.encoder.TomlEncoder): # type: ignore
|
|||||||
self.dump_funcs[Version] = lambda v: f'"{v}"'
|
self.dump_funcs[Version] = lambda v: f'"{v}"'
|
||||||
|
|
||||||
def dump_sections(self, o: Dict[str, Any], sup: str) -> Any:
|
def dump_sections(self, o: Dict[str, Any], sup: str) -> Any:
|
||||||
if all(isinstance(a, list) for a in o.values()):
|
if not all(isinstance(a, list) for a in o.values()):
|
||||||
|
return super().dump_sections(o, sup)
|
||||||
val = ""
|
val = ""
|
||||||
for k, v in o.items():
|
for k, v in o.items():
|
||||||
inner = ",\n ".join(self.dump_inline_table(d_i).strip() for d_i in v)
|
inner = ",\n ".join(self.dump_inline_table(d_i).strip() for d_i in v)
|
||||||
val += f"{k} = [\n {inner},\n]\n"
|
val += f"{k} = [\n {inner},\n]\n"
|
||||||
return val, self._dict()
|
return val, self._dict()
|
||||||
else:
|
|
||||||
return super().dump_sections(o, sup)
|
|
||||||
|
|||||||
@@ -253,5 +253,5 @@ def troubleshoot(package_dir: Path, error: Exception) -> None:
|
|||||||
'''), file=sys.stderr)
|
'''), file=sys.stderr)
|
||||||
|
|
||||||
print(' Files detected:')
|
print(' Files detected:')
|
||||||
print('\n'.join([f' {f}' for f in so_files]))
|
print('\n'.join(f' {f}' for f in so_files))
|
||||||
print('')
|
print('')
|
||||||
|
|||||||
@@ -257,8 +257,8 @@ def setup_python(python_configuration: PythonConfiguration,
|
|||||||
# set ARCHFLAGS otherwise CPython sets it to `-arch x86_64`
|
# set ARCHFLAGS otherwise CPython sets it to `-arch x86_64`
|
||||||
env.setdefault('ARCHFLAGS', '-arch arm64 -arch x86_64')
|
env.setdefault('ARCHFLAGS', '-arch arm64 -arch x86_64')
|
||||||
|
|
||||||
if python_configuration.identifier.endswith('arm64') or python_configuration.identifier.endswith('universal2'):
|
building_arm64 = python_configuration.identifier.endswith('arm64') or python_configuration.identifier.endswith('universal2')
|
||||||
if get_macos_version() < (10, 16) and 'SDKROOT' not in env:
|
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
|
# xcode 12.2 or higher can build arm64 on macos 10.15 or below, but
|
||||||
# needs the correct SDK selected.
|
# needs the correct SDK selected.
|
||||||
sdks = get_macos_sdks()
|
sdks = get_macos_sdks()
|
||||||
|
|||||||
@@ -209,9 +209,7 @@ class NonPlatformWheelError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
def strtobool(val: str) -> bool:
|
def strtobool(val: str) -> bool:
|
||||||
if val.lower() in ('y', 'yes', 't', 'true', 'on', '1'):
|
return val.lower() in {'y', 'yes', 't', 'true', 'on', '1'}
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class CIProvider(Enum):
|
class CIProvider(Enum):
|
||||||
|
|||||||
@@ -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]:
|
def get_nuget_args(version: str, arch: str) -> List[str]:
|
||||||
python_name = 'python' if version[0] == '3' else 'python2'
|
python_name = 'python' if version[0] == '3' else 'python2'
|
||||||
if arch == '32':
|
if arch == '32':
|
||||||
python_name = python_name + 'x86'
|
python_name += 'x86'
|
||||||
return [python_name, '-Version', version, '-OutputDirectory', 'C:\\cibw\\python']
|
return [python_name, '-Version', version, '-OutputDirectory', 'C:\\cibw\\python']
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,11 +40,10 @@ VERSION_REGEX = r'([\w-]+)==([^\s]+)'
|
|||||||
def get_versions_from_constraint_file(constraint_file):
|
def get_versions_from_constraint_file(constraint_file):
|
||||||
constraint_file_text = constraint_file.read_text(encoding='utf8')
|
constraint_file_text = constraint_file.read_text(encoding='utf8')
|
||||||
|
|
||||||
versions = {}
|
return {
|
||||||
for package, version in re.findall(VERSION_REGEX, constraint_file_text):
|
package: version
|
||||||
versions[package] = version
|
for package, version in re.findall(VERSION_REGEX, constraint_file_text)
|
||||||
|
}
|
||||||
return versions
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('python_version', ['2.7', '3.5', '3.6', '3.8'])
|
@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]
|
build_environment[env_name] = constraint_versions[package]
|
||||||
|
|
||||||
cibw_environment_option = ' '.join(
|
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
|
# build and test the wheels
|
||||||
@@ -154,7 +153,7 @@ def test_dependency_constraints_file(tmp_path, python_version):
|
|||||||
build_environment[env_name] = version
|
build_environment[env_name] = version
|
||||||
|
|
||||||
cibw_environment_option = ' '.join(
|
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
|
# build and test the wheels
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ def test_binary_output():
|
|||||||
|
|
||||||
data = bytes(output, encoding='utf8', errors='surrogateescape')
|
data = bytes(output, encoding='utf8', errors='surrogateescape')
|
||||||
|
|
||||||
for i in range(0, 512):
|
for i in range(512):
|
||||||
assert data[i] == i % 256
|
assert data[i] == i % 256
|
||||||
|
|
||||||
# check that environment variables can carry binary data, except null characters
|
# check that environment variables can carry binary data, except null characters
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ def test_repair_command(repair_command, platform_specific, platform, intercepted
|
|||||||
])
|
])
|
||||||
@pytest.mark.parametrize('platform_specific', [False, True])
|
@pytest.mark.parametrize('platform_specific', [False, True])
|
||||||
def test_environment(environment, platform_specific, platform, intercepted_build_args, monkeypatch):
|
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:
|
if platform_specific:
|
||||||
monkeypatch.setenv('CIBW_ENVIRONMENT_' + platform.upper(), env_string)
|
monkeypatch.setenv('CIBW_ENVIRONMENT_' + platform.upper(), env_string)
|
||||||
monkeypatch.setenv('CIBW_ENVIRONMENT', 'overwritten')
|
monkeypatch.setenv('CIBW_ENVIRONMENT', 'overwritten')
|
||||||
|
|||||||
@@ -123,12 +123,10 @@ def test_archs_platform_native(platform, intercepted_build_args, monkeypatch):
|
|||||||
main()
|
main()
|
||||||
build_options = intercepted_build_args.args[0]
|
build_options = intercepted_build_args.args[0]
|
||||||
|
|
||||||
if platform == 'linux':
|
if platform in {'linux', 'macos'}:
|
||||||
assert build_options.architectures == {Architecture.x86_64}
|
assert build_options.architectures == {Architecture.x86_64}
|
||||||
elif platform == 'windows':
|
elif platform == 'windows':
|
||||||
assert build_options.architectures == {Architecture.AMD64}
|
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):
|
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()
|
main()
|
||||||
build_options = intercepted_build_args.args[0]
|
build_options = intercepted_build_args.args[0]
|
||||||
|
|
||||||
if platform == 'linux':
|
if platform in {'linux', 'macos'}:
|
||||||
assert build_options.architectures == {Architecture.x86_64}
|
assert build_options.architectures == {Architecture.x86_64}
|
||||||
elif platform == 'windows':
|
elif platform == 'windows':
|
||||||
assert build_options.architectures == {Architecture.AMD64}
|
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):
|
def test_archs_platform_auto32(platform, intercepted_build_args, monkeypatch):
|
||||||
|
|||||||
Reference in New Issue
Block a user