diff --git a/bin/inspect_all_known_projects.py b/bin/inspect_all_known_projects.py index 542e42b80..f252710c7 100755 --- a/bin/inspect_all_known_projects.py +++ b/bin/inspect_all_known_projects.py @@ -27,19 +27,19 @@ def parse(contents: str) -> str | None: def check_repo(name: str, contents: str) -> str: s = f" {name}: " - if name == "setup.py": + if name == "setup.cfg": + s += "✅" if "python_requires" in contents else "❌" + elif name == "setup.py": if "python_requires" not in contents: s += "❌" res = parse(contents) if res is None: s += "⚠️ " elif res: - s += "✅ " + res + s += f"✅ {res}" elif "python_requires" in contents: s += "☑️" - elif name == "setup.cfg": - s += "✅" if "python_requires" in contents else "❌" else: s += "✅" if "requires-python" in contents else "❌" diff --git a/bin/update_pythons.py b/bin/update_pythons.py index e4939f799..2abafcfb4 100755 --- a/bin/update_pythons.py +++ b/bin/update_pythons.py @@ -223,8 +223,7 @@ def update_version_macos( response.raise_for_status() file_info = response.json() - urls = [rf["url"] for rf in file_info if file_ident in rf["url"]] - if urls: + if urls := [rf["url"] for rf in file_info if file_ident in rf["url"]]: return ConfigMacOS( identifier=identifier, version=f"{new_version.major}.{new_version.minor}", diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index 306e73ab4..7b26bf4a1 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -237,11 +237,10 @@ def print_preamble(platform: str, options: Options, identifiers: List[str]) -> N print(f"Cache folder: {CIBW_CACHE_PATH}") - warnings = detect_warnings(options=options, identifiers=identifiers) - if warnings: + if warnings := detect_warnings(options=options, identifiers=identifiers): print("\nWarnings:") for warning in warnings: - print(" " + warning) + print(f" {warning}") print("\nHere we go!\n") diff --git a/cibuildwheel/architecture.py b/cibuildwheel/architecture.py index 437ff5e83..9e14891e4 100644 --- a/cibuildwheel/architecture.py +++ b/cibuildwheel/architecture.py @@ -112,9 +112,9 @@ def allowed_architectures_check( msg += " If you want to set emulation architectures on Linux, use CIBW_ARCHS_LINUX instead." if not architectures <= allowed_architectures: - msg = f"Invalid archs option {architectures}. " + msg + msg = f"Invalid archs option {architectures}. {msg}" raise ValueError(msg) if not architectures: - msg = "Empty archs option set. " + msg + msg = f"Empty archs option set. {msg}" raise ValueError(msg) diff --git a/cibuildwheel/docker_container.py b/cibuildwheel/docker_container.py index bc313a7de..a215e4ffa 100644 --- a/cibuildwheel/docker_container.py +++ b/cibuildwheel/docker_container.py @@ -202,11 +202,7 @@ def call( ) self.bash_stdin.flush() - if capture_output: - output_io: IO[bytes] = io.BytesIO() - else: - output_io = sys.stdout.buffer - + output_io = io.BytesIO() if capture_output else sys.stdout.buffer while True: line = self.bash_stdout.readline() @@ -222,7 +218,7 @@ def call( return_code_str = line[footer_offset : footer_offset + 4] return_code = int(return_code_str) # add the last line to output, without the footer - output_io.write(line[0:footer_offset]) + output_io.write(line[:footer_offset]) break else: output_io.write(line) diff --git a/cibuildwheel/environment.py b/cibuildwheel/environment.py index ba66d6e29..86dfbb53a 100644 --- a/cibuildwheel/environment.py +++ b/cibuildwheel/environment.py @@ -32,13 +32,10 @@ def split_env_items(env_string: str) -> List[str]: return [] command_node = bashlex.parsesingle(env_string) - result = [] - - for word_node in command_node.parts: - part_string = env_string[word_node.pos[0] : word_node.pos[1]] - result.append(part_string) - - return result + return [ + env_string[word_node.pos[0] : word_node.pos[1]] + for word_node in command_node.parts + ] class EnvironmentAssignment(Protocol): diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index 8478bf092..dca9f281e 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -358,7 +358,7 @@ def build(options: Options, tmp_path: Path) -> None: # pylint: disable=unused-a def _matches_prepared_command(error_cmd: List[str], command_template: str) -> bool: - if len(error_cmd) < 3 or error_cmd[0:2] != ["sh", "-c"]: + if len(error_cmd) < 3 or error_cmd[:2] != ["sh", "-c"]: return False command_prefix = command_template.split("{", maxsplit=1)[0].strip() return error_cmd[2].startswith(command_prefix) @@ -367,17 +367,15 @@ def _matches_prepared_command(error_cmd: List[str], command_template: str) -> bo def troubleshoot(options: Options, error: Exception) -> None: if isinstance(error, subprocess.CalledProcessError) and ( - error.cmd[0:4] == ["python", "-m", "pip", "wheel"] - or error.cmd[0:3] == ["python", "-m", "build"] + error.cmd[:4] == ["python", "-m", "pip", "wheel"] + or error.cmd[:3] == ["python", "-m", "build"] or _matches_prepared_command( error.cmd, options.build_options(None).repair_command - ) # TODO allow matching of overrides too? + ) ): # the wheel build step or the repair step failed print("Checking for common errors...") - so_files = list(options.globals.package_dir.glob("**/*.so")) - - if so_files: + if so_files := list(options.globals.package_dir.glob("**/*.so")): print( textwrap.dedent( """ diff --git a/cibuildwheel/logger.py b/cibuildwheel/logger.py index 0a4be14d2..921f625f0 100644 --- a/cibuildwheel/logger.py +++ b/cibuildwheel/logger.py @@ -187,7 +187,7 @@ def build_description_from_identifier(identifier: str) -> str: build_description = "" - python_interpreter = python_identifier[0:2] + python_interpreter = python_identifier[:2] python_version = python_identifier[2:] if python_interpreter == "cp": diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index a58186123..8d8e349b2 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -114,7 +114,7 @@ def install_pypy(tmp: Path, url: str) -> Path: extension = ".tar.bz2" assert pypy_tar_bz2.endswith(extension) installation_path = CIBW_CACHE_PATH / pypy_tar_bz2[: -len(extension)] - with FileLock(str(installation_path) + ".lock"): + with FileLock(f'{str(installation_path)}.lock'): if not installation_path.exists(): downloaded_tar_bz2 = tmp / pypy_tar_bz2 download(url, downloaded_tar_bz2) @@ -226,11 +226,12 @@ def setup_python( # 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.")] + if arm64_compatible_sdks := [ + s for s in sdks if not s.startswith("macosx10.") + ]: + env.setdefault("SDKROOT", arm64_compatible_sdks[0]) - if not arm64_compatible_sdks: + else: log.warning( unwrap( """ @@ -239,9 +240,6 @@ def setup_python( """ ) ) - else: - env.setdefault("SDKROOT", arm64_compatible_sdks[0]) - log.step("Installing build tools...") if build_frontend == "pip": call( diff --git a/cibuildwheel/projectfiles.py b/cibuildwheel/projectfiles.py index 8a6311de7..1398a79cc 100644 --- a/cibuildwheel/projectfiles.py +++ b/cibuildwheel/projectfiles.py @@ -31,13 +31,12 @@ def visit(self, node: ast.AST) -> None: def visit_keyword(self, node: ast.keyword) -> None: self.generic_visit(node) - if node.arg == "python_requires": - # Must not be nested in an if or other structure - # This will be Module -> Expr -> Call -> keyword - if not hasattr(node.parent.parent.parent, "parent") and isinstance( # type: ignore[attr-defined] - node.value, Constant - ): - self.requires_python = get_constant(node.value) + if ( + node.arg == "python_requires" + and not hasattr(node.parent.parent.parent, "parent") + and isinstance(node.value, Constant) # type: ignore[attr-defined] + ): + self.requires_python = get_constant(node.value) def setup_py_python_requires(content: str) -> Optional[str]: diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index 18df677db..ac8078505 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -204,8 +204,7 @@ def read_python_configs(config: PlatformName) -> List[Dict[str, str]]: input_file = resources_dir / "build-platforms.toml" with input_file.open("rb") as f: loaded_file = tomli.load(f) - results: List[Dict[str, str]] = list(loaded_file[config]["python_configurations"]) - return results + return list(loaded_file[config]["python_configurations"]) def selector_matches(patterns: str, string: str) -> bool: @@ -340,10 +339,11 @@ def __repr__(self) -> str: return f"{self.__class__.__name__}({self.base_file_path!r})" def __eq__(self, o: object) -> bool: - if not isinstance(o, DependencyConstraints): - return False - - return self.base_file_path == o.base_file_path + return ( + self.base_file_path == o.base_file_path + if isinstance(o, DependencyConstraints) + else False + ) class NonPlatformWheelError(Exception): @@ -464,7 +464,7 @@ def _ensure_virtualenv() -> Path: version = str(loaded_file["version"]) url = str(loaded_file["url"]) path = CIBW_CACHE_PATH / f"virtualenv-{version}.pyz" - with FileLock(str(path) + ".lock"): + with FileLock(f'{str(path)}.lock'): if not path.exists(): download(url, path) return path diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 86d01fa82..f3c25cf57 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -33,7 +33,7 @@ def get_nuget_args(version: str, arch: str, output_directory: Path) -> List[str]: platform_suffix = {"32": "x86", "64": "", "ARM64": "arm64"} - python_name = "python" + platform_suffix[arch] + python_name = f"python{platform_suffix[arch]}" return [ python_name, "-Version", @@ -81,7 +81,7 @@ def extract_zip(zip_src: Path, dest: Path) -> None: @lru_cache(maxsize=None) def _ensure_nuget() -> Path: nuget = CIBW_CACHE_PATH / "nuget.exe" - with FileLock(str(nuget) + ".lock"): + with FileLock(f'{str(nuget)}.lock'): if not nuget.exists(): download("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe", nuget) return nuget @@ -90,8 +90,8 @@ def _ensure_nuget() -> Path: def install_cpython(version: str, arch: str) -> Path: base_output_dir = CIBW_CACHE_PATH / "nuget-cpython" nuget_args = get_nuget_args(version, arch, base_output_dir) - installation_path = base_output_dir / (nuget_args[0] + "." + version) / "tools" - with FileLock(str(base_output_dir) + f"-{version}-{arch}.lock"): + installation_path = base_output_dir / f'{nuget_args[0]}.{version}' / "tools" + with FileLock(f"{str(base_output_dir)}-{version}-{arch}.lock"): if not installation_path.exists(): nuget = _ensure_nuget() call(nuget, "install", *nuget_args) @@ -105,7 +105,7 @@ def install_pypy(tmp: Path, arch: str, url: str) -> Path: extension = ".zip" assert zip_filename.endswith(extension) installation_path = CIBW_CACHE_PATH / zip_filename[: -len(extension)] - with FileLock(str(installation_path) + ".lock"): + with FileLock(f'{str(installation_path)}.lock'): if not installation_path.exists(): pypy_zip = tmp / zip_filename download(url, pypy_zip) diff --git a/test/test_cpp_standards.py b/test/test_cpp_standards.py index a5385007f..673a4887a 100644 --- a/test/test_cpp_standards.py +++ b/test/test_cpp_standards.py @@ -68,7 +68,7 @@ def test_cpp11(tmp_path): cpp11_project.generate(project_dir) actual_wheels = utils.cibuildwheel_run(project_dir) - expected_wheels = [w for w in utils.expected_wheels("spam", "0.1.0")] + expected_wheels = list(utils.expected_wheels("spam", "0.1.0")) assert set(actual_wheels) == set(expected_wheels) @@ -87,7 +87,7 @@ def test_cpp14(tmp_path): cpp14_project.generate(project_dir) actual_wheels = utils.cibuildwheel_run(project_dir) - expected_wheels = [w for w in utils.expected_wheels("spam", "0.1.0")] + expected_wheels = list(utils.expected_wheels("spam", "0.1.0")) assert set(actual_wheels) == set(expected_wheels) diff --git a/test/test_dependency_versions.py b/test/test_dependency_versions.py index 90854a866..f58c4aa0c 100644 --- a/test/test_dependency_versions.py +++ b/test/test_dependency_versions.py @@ -42,9 +42,7 @@ def get_versions_from_constraint_file(constraint_file): constraint_file_text = constraint_file.read_text(encoding="utf8") - return { - package: version for package, version in re.findall(VERSION_REGEX, constraint_file_text) - } + return dict(re.findall(VERSION_REGEX, constraint_file_text)) @pytest.mark.parametrize("python_version", ["3.6", "3.8", "3.9"]) diff --git a/test/utils.py b/test/utils.py index 0248a7c15..2af2c0f6f 100644 --- a/test/utils.py +++ b/test/utils.py @@ -93,10 +93,7 @@ def _get_arm64_macosx_deployment_target(macosx_deployment_target: str) -> str: MACOSX_DEPLOYMENT_TARGET sets it. """ version_tuple = tuple(map(int, macosx_deployment_target.split("."))) - if version_tuple <= (11, 0): - return "11.0" - else: - return macosx_deployment_target + return "11.0" if version_tuple <= (11, 0) else macosx_deployment_target def expected_wheels( @@ -193,8 +190,10 @@ def expected_wheels( else: raise Exception("unsupported platform") - for platform_tag in platform_tags: - wheels.append(f"{package_name}-{package_version}-{python_abi_tag}-{platform_tag}.whl") + wheels.extend( + f"{package_name}-{package_version}-{python_abi_tag}-{platform_tag}.whl" + for platform_tag in platform_tags + ) return wheels diff --git a/unit_test/docker_container_test.py b/unit_test/docker_container_test.py index 3b250ad36..b790e88ea 100644 --- a/unit_test/docker_container_test.py +++ b/unit_test/docker_container_test.py @@ -139,7 +139,7 @@ def test_binary_output(): # check that environment variables can carry binary data, except null characters # (https://www.gnu.org/software/libc/manual/html_node/Environment-Variables.html) - binary_data = bytes(n for n in range(1, 256)) + binary_data = bytes(range(1, 256)) binary_data_string = str(binary_data, encoding="utf8", errors="surrogateescape") output = container.call( ["python2", "-c", 'import os, sys; sys.stdout.write(os.environ["TEST_VAR"])'], diff --git a/unit_test/main_tests/main_options_test.py b/unit_test/main_tests/main_options_test.py index 0a345cb1f..0cb1cea21 100644 --- a/unit_test/main_tests/main_options_test.py +++ b/unit_test/main_tests/main_options_test.py @@ -95,7 +95,7 @@ def test_manylinux_images( architecture, image, full_image, platform, intercepted_build_args, monkeypatch ): if image is not None: - monkeypatch.setenv("CIBW_MANYLINUX_" + architecture.upper() + "_IMAGE", image) + monkeypatch.setenv(f"CIBW_MANYLINUX_{architecture.upper()}_IMAGE", image) main() @@ -149,7 +149,7 @@ def test_repair_command( def test_environment(environment, platform_specific, platform, intercepted_build_args, monkeypatch): 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(f"CIBW_ENVIRONMENT_{platform.upper()}", env_string) monkeypatch.setenv("CIBW_ENVIRONMENT", "overwritten") else: monkeypatch.setenv("CIBW_ENVIRONMENT", env_string) @@ -170,7 +170,7 @@ def test_test_requires( ): if test_requires is not None: if platform_specific: - monkeypatch.setenv("CIBW_TEST_REQUIRES_" + platform.upper(), test_requires) + monkeypatch.setenv(f"CIBW_TEST_REQUIRES_{platform.upper()}", test_requires) monkeypatch.setenv("CIBW_TEST_REQUIRES", "overwritten") else: monkeypatch.setenv("CIBW_TEST_REQUIRES", test_requires) @@ -187,7 +187,7 @@ def test_test_requires( def test_test_extras(test_extras, platform_specific, platform, intercepted_build_args, monkeypatch): if test_extras is not None: if platform_specific: - monkeypatch.setenv("CIBW_TEST_EXTRAS_" + platform.upper(), test_extras) + monkeypatch.setenv(f"CIBW_TEST_EXTRAS_{platform.upper()}", test_extras) monkeypatch.setenv("CIBW_TEST_EXTRAS", "overwritten") else: monkeypatch.setenv("CIBW_TEST_EXTRAS", test_extras) @@ -196,7 +196,7 @@ def test_test_extras(test_extras, platform_specific, platform, intercepted_build build_options = intercepted_build_args.args[0].build_options(identifier=None) - assert build_options.test_extras == ("[" + test_extras + "]" if test_extras else "") + assert build_options.test_extras == (f"[{test_extras}]" if test_extras else "") @pytest.mark.parametrize("test_command", [None, "test --command"]) @@ -206,7 +206,7 @@ def test_test_command( ): if test_command is not None: if platform_specific: - monkeypatch.setenv("CIBW_TEST_COMMAND_" + platform.upper(), test_command) + monkeypatch.setenv(f"CIBW_TEST_COMMAND_{platform.upper()}", test_command) monkeypatch.setenv("CIBW_TEST_COMMAND", "overwritten") else: monkeypatch.setenv("CIBW_TEST_COMMAND", test_command) @@ -225,7 +225,7 @@ def test_before_build( ): if before_build is not None: if platform_specific: - monkeypatch.setenv("CIBW_BEFORE_BUILD_" + platform.upper(), before_build) + monkeypatch.setenv(f"CIBW_BEFORE_BUILD_{platform.upper()}", before_build) monkeypatch.setenv("CIBW_BEFORE_BUILD", "overwritten") else: monkeypatch.setenv("CIBW_BEFORE_BUILD", before_build) @@ -243,7 +243,11 @@ def test_build_verbosity( ): if build_verbosity is not None: if platform_specific: - monkeypatch.setenv("CIBW_BUILD_VERBOSITY_" + platform.upper(), str(build_verbosity)) + monkeypatch.setenv( + f"CIBW_BUILD_VERBOSITY_{platform.upper()}", + str(build_verbosity), + ) + monkeypatch.setenv("CIBW_BUILD_VERBOSITY", "overwritten") else: monkeypatch.setenv("CIBW_BUILD_VERBOSITY", str(build_verbosity)) @@ -296,7 +300,7 @@ def test_build_selector_deprecated_error( def test_before_all(before_all, platform_specific, platform, intercepted_build_args, monkeypatch): if before_all is not None: if platform_specific: - monkeypatch.setenv("CIBW_BEFORE_ALL_" + platform.upper(), before_all) + monkeypatch.setenv(f"CIBW_BEFORE_ALL_{platform.upper()}", before_all) monkeypatch.setenv("CIBW_BEFORE_ALL", "overwritten") else: monkeypatch.setenv("CIBW_BEFORE_ALL", before_all)