Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bin/inspect_all_known_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "❌"
Comment on lines -30 to -42
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function check_repo refactored with the following changes:

else:
s += "✅" if "requires-python" in contents else "❌"

Expand Down
3 changes: 1 addition & 2 deletions bin/update_pythons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CPythonVersions.update_version_macos refactored with the following changes:

return ConfigMacOS(
identifier=identifier,
version=f"{new_version.major}.{new_version.minor}",
Expand Down
5 changes: 2 additions & 3 deletions cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Comment on lines -240 to +243
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function print_preamble refactored with the following changes:


print("\nHere we go!\n")

Expand Down
4 changes: 2 additions & 2 deletions cibuildwheel/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Comment on lines -115 to +119
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function allowed_architectures_check refactored with the following changes:

raise ValueError(msg)
8 changes: 2 additions & 6 deletions cibuildwheel/docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DockerContainer.call refactored with the following changes:

while True:
line = self.bash_stdout.readline()

Expand All @@ -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)
Expand Down
11 changes: 4 additions & 7 deletions cibuildwheel/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Comment on lines -35 to +38
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function split_env_items refactored with the following changes:



class EnvironmentAssignment(Protocol):
Expand Down
12 changes: 5 additions & 7 deletions cibuildwheel/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _matches_prepared_command refactored with the following changes:

return False
command_prefix = command_template.split("{", maxsplit=1)[0].strip()
return error_cmd[2].startswith(command_prefix)
Expand All @@ -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")):
Comment on lines -370 to +378
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function troubleshoot refactored with the following changes:

This removes the following comments ( why? ):

# TODO allow matching of overrides too?

print(
textwrap.dedent(
"""
Expand Down
2 changes: 1 addition & 1 deletion cibuildwheel/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function build_description_from_identifier refactored with the following changes:

python_version = python_identifier[2:]

if python_interpreter == "cp":
Expand Down
14 changes: 6 additions & 8 deletions cibuildwheel/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function install_pypy refactored with the following changes:

if not installation_path.exists():
downloaded_tar_bz2 = tmp / pypy_tar_bz2
download(url, downloaded_tar_bz2)
Expand Down Expand Up @@ -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:
Comment on lines -229 to +234
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function setup_python refactored with the following changes:

This removes the following comments ( why? ):

# Different versions of Xcode contain different SDK versions...
# we're happy with anything newer than macOS 11.0

log.warning(
unwrap(
"""
Expand All @@ -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(
Expand Down
13 changes: 6 additions & 7 deletions cibuildwheel/projectfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines -34 to +39
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Analyzer.visit_keyword refactored with the following changes:

This removes the following comments ( why? ):

# This will be Module -> Expr -> Call -> keyword
# Must not be nested in an if or other structure



def setup_py_python_requires(content: str) -> Optional[str]:
Expand Down
14 changes: 7 additions & 7 deletions cibuildwheel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function read_python_configs refactored with the following changes:



def selector_matches(patterns: str, string: str) -> bool:
Expand Down Expand Up @@ -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
)
Comment on lines -343 to +346
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DependencyConstraints.__eq__ refactored with the following changes:



class NonPlatformWheelError(Exception):
Expand Down Expand Up @@ -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'):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _ensure_virtualenv refactored with the following changes:

if not path.exists():
download(url, path)
return path
Expand Down
10 changes: 5 additions & 5 deletions cibuildwheel/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_nuget_args refactored with the following changes:

return [
python_name,
"-Version",
Expand Down Expand Up @@ -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'):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _ensure_nuget refactored with the following changes:

if not nuget.exists():
download("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe", nuget)
return nuget
Expand All @@ -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"):
Comment on lines -93 to +94
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function install_cpython refactored with the following changes:

if not installation_path.exists():
nuget = _ensure_nuget()
call(nuget, "install", *nuget_args)
Expand All @@ -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'):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function install_pypy refactored with the following changes:

if not installation_path.exists():
pypy_zip = tmp / zip_filename
download(url, pypy_zip)
Expand Down
4 changes: 2 additions & 2 deletions test/test_cpp_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_cpp11 refactored with the following changes:


assert set(actual_wheels) == set(expected_wheels)

Expand All @@ -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"))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_cpp14 refactored with the following changes:


assert set(actual_wheels) == set(expected_wheels)

Expand Down
4 changes: 1 addition & 3 deletions test/test_dependency_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_versions_from_constraint_file refactored with the following changes:



@pytest.mark.parametrize("python_version", ["3.6", "3.8", "3.9"])
Expand Down
11 changes: 5 additions & 6 deletions test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _get_arm64_macosx_deployment_target refactored with the following changes:



def expected_wheels(
Expand Down Expand Up @@ -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
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function expected_wheels refactored with the following changes:


return wheels

Expand Down
2 changes: 1 addition & 1 deletion unit_test/docker_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_binary_output refactored with the following changes:

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"])'],
Expand Down
Loading