-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"]]: | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return ConfigMacOS( | ||
| identifier=identifier, | ||
| version=f"{new_version.major}.{new_version.minor}", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| print("\nHere we go!\n") | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| raise ValueError(msg) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| class EnvironmentAssignment(Protocol): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"]: | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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")): | ||
|
Comment on lines
-370
to
+378
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| print( | ||
| textwrap.dedent( | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| python_version = python_identifier[2:] | ||
|
|
||
| if python_interpreter == "cp": | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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: | ||
|
Comment on lines
-229
to
+234
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| 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( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
|
|
||
|
|
||
| def setup_py_python_requires(content: str) -> Optional[str]: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"]) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| 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 | ||
| ) | ||
|
Comment on lines
-343
to
+346
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| 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'): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if not path.exists(): | ||
| download(url, path) | ||
| return path | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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]}" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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'): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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"): | ||
|
Comment on lines
-93
to
+94
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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'): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if not installation_path.exists(): | ||
| pypy_zip = tmp / zip_filename | ||
| download(url, pypy_zip) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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")) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| 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")) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| assert set(actual_wheels) == set(expected_wheels) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| @pytest.mark.parametrize("python_version", ["3.6", "3.8", "3.9"]) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| 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 | ||
| ) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| return wheels | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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"])'], | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
check_reporefactored with the following changes:switch)use-fstring-for-concatenation)