Skip to content
Merged
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
3 changes: 1 addition & 2 deletions pylib/gyp/MSVSSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ def _ValidateExclusionSetting(setting, settings, error_msg, stderr=sys.stderr):
# This may be unrecognized because it's an exclusion list. If the
# setting name has the _excluded suffix, then check the root name.
unrecognized = True
m = re.match(_EXCLUDED_SUFFIX_RE, setting)
if m:
if m := re.match(_EXCLUDED_SUFFIX_RE, setting):
root_setting = m.group(1)
unrecognized = root_setting not in settings

Expand Down
3 changes: 1 addition & 2 deletions pylib/gyp/MSVSVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,7 @@ def SelectVisualStudioVersion(version="auto", allow_fallback=True):
"2019": ("16.0",),
"2022": ("17.0",),
}
override_path = os.environ.get("GYP_MSVS_OVERRIDE_PATH")
if override_path:
if override_path := os.environ.get("GYP_MSVS_OVERRIDE_PATH"):
msvs_version = os.environ.get("GYP_MSVS_VERSION")
if not msvs_version:
raise ValueError(
Expand Down
3 changes: 1 addition & 2 deletions pylib/gyp/generator/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,8 +901,7 @@ def WriteTarget(
if self.type != "none":
self.WriteTargetFlags(spec, configs, link_deps)

settings = spec.get("aosp_build_settings", {})
if settings:
if settings := spec.get("aosp_build_settings", {}):
self.WriteLn("### Set directly by aosp_build_settings.")
for k, v in settings.items():
if isinstance(v, list):
Expand Down
6 changes: 2 additions & 4 deletions pylib/gyp/generator/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,7 @@ def WriteTarget(
# link directories to targets defined after it is called.
# As a result, link_directories must come before the target definition.
# CMake unfortunately has no means of removing entries from LINK_DIRECTORIES.
library_dirs = config.get("library_dirs")
if library_dirs is not None:
if (library_dirs := config.get("library_dirs")) is not None:
output.write("link_directories(")
for library_dir in library_dirs:
output.write(" ")
Expand Down Expand Up @@ -1294,8 +1293,7 @@ def CallGenerateOutputForConfig(arglist):


def GenerateOutput(target_list, target_dicts, data, params):
user_config = params.get("generator_flags", {}).get("config", None)
if user_config:
if user_config := params.get("generator_flags", {}).get("config", None):
GenerateOutputForConfig(target_list, target_dicts, data, params, user_config)
else:
config_names = target_dicts[target_list[0]]["configurations"]
Expand Down
3 changes: 1 addition & 2 deletions pylib/gyp/generator/eclipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,7 @@ def GenerateOutput(target_list, target_dicts, data, params):
if params["options"].generator_output:
raise NotImplementedError("--generator_output not implemented for eclipse")

user_config = params.get("generator_flags", {}).get("config", None)
if user_config:
if user_config := params.get("generator_flags", {}).get("config", None):
GenerateOutputForConfig(target_list, target_dicts, data, params, user_config)
else:
config_names = target_dicts[target_list[0]]["configurations"]
Expand Down
6 changes: 2 additions & 4 deletions pylib/gyp/generator/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,8 +1465,7 @@ def WriteSources(
order_only=True,
)

pchdeps = precompiled_header.GetObjDependencies(compilable, objs)
if pchdeps:
if pchdeps := precompiled_header.GetObjDependencies(compilable, objs):
self.WriteLn("# Dependencies from obj files to their precompiled headers")
for source, obj, gch in pchdeps:
self.WriteLn(f"{obj}: {gch}")
Expand Down Expand Up @@ -1600,8 +1599,7 @@ def ComputeOutputBasename(self, spec):

target_prefix = spec.get("product_prefix", target_prefix)
target = spec.get("product_name", target)
product_ext = spec.get("product_extension")
if product_ext:
if product_ext := spec.get("product_extension"):
target_ext = "." + product_ext

return target_prefix + target + target_ext
Expand Down
12 changes: 4 additions & 8 deletions pylib/gyp/generator/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,8 +1365,7 @@ def _GetOutputTargetExt(spec):
Returns:
A string with the extension, or None
"""
target_extension = spec.get("product_extension")
if target_extension:
if target_extension := spec.get("product_extension"):
return "." + target_extension
return None

Expand Down Expand Up @@ -3169,8 +3168,7 @@ def _GetMSBuildAttributes(spec, config, build_file):
"windows_driver": "Link",
"static_library": "Lib",
}
msbuild_tool = msbuild_tool_map.get(spec["type"])
if msbuild_tool:
if msbuild_tool := msbuild_tool_map.get(spec["type"]):
msbuild_settings = config["finalized_msbuild_settings"]
out_file = msbuild_settings[msbuild_tool].get("OutputFile")
if out_file:
Expand All @@ -3187,8 +3185,7 @@ def _GetMSBuildConfigurationGlobalProperties(spec, configurations, build_file):
# there are actions.
# TODO(jeanluc) Handle the equivalent of setting 'CYGWIN=nontsec'.
new_paths = []
cygwin_dirs = spec.get("msvs_cygwin_dirs", ["."])[0]
if cygwin_dirs:
if cygwin_dirs := spec.get("msvs_cygwin_dirs", ["."])[0]:
cyg_path = "$(MSBuildProjectDirectory)\\%s\\bin\\" % _FixPath(cygwin_dirs)
new_paths.append(cyg_path)
# TODO(jeanluc) Change the convention to have both a cygwin_dir and a
Expand Down Expand Up @@ -3373,7 +3370,6 @@ def _FinalizeMSBuildSettings(spec, configuration):
prebuild = configuration.get("msvs_prebuild")
postbuild = configuration.get("msvs_postbuild")
def_file = _GetModuleDefinition(spec)
precompiled_header = configuration.get("msvs_precompiled_header")

# Add the information to the appropriate tool
# TODO(jeanluc) We could optimize and generate these settings only if
Expand Down Expand Up @@ -3411,7 +3407,7 @@ def _FinalizeMSBuildSettings(spec, configuration):
msbuild_settings, "ClCompile", "DisableSpecificWarnings", disabled_warnings
)
# Turn on precompiled headers if appropriate.
if precompiled_header:
if precompiled_header := configuration.get("msvs_precompiled_header"):
# While MSVC works with just file name eg. "v8_pch.h", ClangCL requires
# the full path eg. "tools/msvs/pch/v8_pch.h" to find the file.
# P.S. Only ClangCL defines msbuild_toolset, for MSVC it is None.
Expand Down
15 changes: 5 additions & 10 deletions pylib/gyp/generator/ninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,15 @@ def ExpandSpecial(self, path, product_dir=None):
dir.
"""

PRODUCT_DIR = "$!PRODUCT_DIR"
if PRODUCT_DIR in path:
if (PRODUCT_DIR := "$!PRODUCT_DIR") in path:
if product_dir:
path = path.replace(PRODUCT_DIR, product_dir)
else:
path = path.replace(PRODUCT_DIR + "/", "")
path = path.replace(PRODUCT_DIR + "\\", "")
path = path.replace(PRODUCT_DIR, ".")

INTERMEDIATE_DIR = "$!INTERMEDIATE_DIR"
if INTERMEDIATE_DIR in path:
if (INTERMEDIATE_DIR := "$!INTERMEDIATE_DIR") in path:
int_dir = self.GypPathToUniqueOutput("gen")
# GypPathToUniqueOutput generates a path relative to the product dir,
# so insert product_dir in front if it is provided.
Expand Down Expand Up @@ -2077,16 +2075,14 @@ def OpenOutput(path, mode="w"):


def CommandWithWrapper(cmd, wrappers, prog):
wrapper = wrappers.get(cmd, "")
if wrapper:
if wrapper := wrappers.get(cmd, ""):
return wrapper + " " + prog
return prog


def GetDefaultConcurrentLinks():
"""Returns a best-guess for a number of concurrent links."""
pool_size = int(os.environ.get("GYP_LINK_CONCURRENCY") or 0)
if pool_size:
if pool_size := int(os.environ.get("GYP_LINK_CONCURRENCY") or 0):
return pool_size

if sys.platform in ("win32", "cygwin"):
Expand Down Expand Up @@ -2307,8 +2303,7 @@ def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name
key_prefix = re.sub(r"\.HOST$", ".host", key_prefix)
wrappers[key_prefix] = os.path.join(build_to_root, value)

mac_toolchain_dir = generator_flags.get("mac_toolchain_dir", None)
if mac_toolchain_dir:
if mac_toolchain_dir := generator_flags.get("mac_toolchain_dir", None):
wrappers["LINK"] = "export DEVELOPER_DIR='%s' &&" % mac_toolchain_dir

if flavor == "win":
Expand Down
3 changes: 1 addition & 2 deletions pylib/gyp/mac_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

def main(args):
executor = MacTool()
exit_code = executor.Dispatch(args)
if exit_code is not None:
if (exit_code := executor.Dispatch(args)) is not None:
sys.exit(exit_code)


Expand Down
16 changes: 5 additions & 11 deletions pylib/gyp/msvs_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,7 @@ def GetExtension(self):
the target type.
"""
ext = self.spec.get("product_extension", None)
if ext:
return ext
return gyp.MSVSUtil.TARGET_TYPE_EXT.get(self.spec["type"], "")
return ext or gyp.MSVSUtil.TARGET_TYPE_EXT.get(self.spec["type"], "")

def GetVSMacroEnv(self, base_to_build=None, config=None):
"""Get a dict of variables mapping internal VS macro names to their gyp
Expand Down Expand Up @@ -625,8 +623,7 @@ def GetDefFile(self, gyp_to_build_path):
def _GetDefFileAsLdflags(self, ldflags, gyp_to_build_path):
""".def files get implicitly converted to a ModuleDefinitionFile for the
linker in the VS generator. Emulate that behaviour here."""
def_file = self.GetDefFile(gyp_to_build_path)
if def_file:
if def_file := self.GetDefFile(gyp_to_build_path):
ldflags.append('/DEF:"%s"' % def_file)

def GetPGDName(self, config, expand_special):
Expand Down Expand Up @@ -674,14 +671,11 @@ def GetLdflags(
)
ld("DelayLoadDLLs", prefix="/DELAYLOAD:")
ld("TreatLinkerWarningAsErrors", prefix="/WX", map={"true": "", "false": ":NO"})
out = self.GetOutputName(config, expand_special)
if out:
if out := self.GetOutputName(config, expand_special):
ldflags.append("/OUT:" + out)
pdb = self.GetPDBName(config, expand_special, output_name + ".pdb")
if pdb:
if pdb := self.GetPDBName(config, expand_special, output_name + ".pdb"):
ldflags.append("/PDB:" + pdb)
pgd = self.GetPGDName(config, expand_special)
if pgd:
if pgd := self.GetPGDName(config, expand_special):
ldflags.append("/PGD:" + pgd)
map_file = self.GetMapFileName(config, expand_special)
ld("GenerateMapFile", map={"true": "/MAP:" + map_file if map_file else "/MAP"})
Expand Down
3 changes: 1 addition & 2 deletions pylib/gyp/win_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@

def main(args):
executor = WinTool()
exit_code = executor.Dispatch(args)
if exit_code is not None:
if (exit_code := executor.Dispatch(args)) is not None:
sys.exit(exit_code)


Expand Down
9 changes: 3 additions & 6 deletions pylib/gyp/xcode_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,8 +1352,7 @@ def _DefaultSdkRoot(self):
if xcode_version < "0500":
return ""
default_sdk_path = self._XcodeSdkPath("")
default_sdk_root = XcodeSettings._sdk_root_cache.get(default_sdk_path)
if default_sdk_root:
if default_sdk_root := XcodeSettings._sdk_root_cache.get(default_sdk_path):
return default_sdk_root
try:
all_sdks = GetStdout(["xcodebuild", "-showsdks"])
Expand Down Expand Up @@ -1789,11 +1788,9 @@ def _GetXcodeEnv(
env["INFOPLIST_PATH"] = xcode_settings.GetBundlePlistPath()
env["WRAPPER_NAME"] = xcode_settings.GetWrapperName()

install_name = xcode_settings.GetInstallName()
if install_name:
if install_name := xcode_settings.GetInstallName():
env["LD_DYLIB_INSTALL_NAME"] = install_name
install_name_base = xcode_settings.GetInstallNameBase()
if install_name_base:
if install_name_base := xcode_settings.GetInstallNameBase():
env["DYLIB_INSTALL_NAME_BASE"] = install_name_base
xcode_version, _ = XcodeVersion()
if xcode_version >= "0500" and not env.get("SDKROOT"):
Expand Down
3 changes: 1 addition & 2 deletions pylib/gyp/xcode_ninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ def _TargetFromSpec(old_spec, params):

target_name = old_spec.get("target_name")
product_name = old_spec.get("product_name", target_name)
product_extension = old_spec.get("product_extension")

ninja_target = {}
ninja_target["target_name"] = target_name
ninja_target["product_name"] = product_name
if product_extension:
if product_extension := old_spec.get("product_extension"):
ninja_target["product_extension"] = product_extension
ninja_target["toolset"] = old_spec.get("toolset")
ninja_target["default_configuration"] = old_spec.get("default_configuration")
Expand Down
12 changes: 4 additions & 8 deletions pylib/gyp/xcodeproj_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ def SourceTreeAndPathFromPath(input_path):
'path' (None, 'path')
"""

source_group_match = _path_leading_variable.match(input_path)
if source_group_match:
if source_group_match := _path_leading_variable.match(input_path):
source_tree = source_group_match.group(1)
output_path = source_group_match.group(3) # This may be None.
else:
Expand Down Expand Up @@ -389,8 +388,7 @@ def Comment(self):
def Hashables(self):
hashables = [self.__class__.__name__]

name = self.Name()
if name is not None:
if (name := self.Name()) is not None:
hashables.append(name)

hashables.extend(self._hashables)
Expand Down Expand Up @@ -1050,8 +1048,7 @@ def Hashables(self):
# including paths with a sourceTree, they'll still inherit their parents'
# hashables, even though the paths aren't relative to their parents. This
# is not expected to be much of a problem in practice.
path = self.PathFromSourceTreeAndPath()
if path is not None:
if (path := self.PathFromSourceTreeAndPath()) is not None:
components = path.split(posixpath.sep)
for component in components:
hashables.append(self.__class__.__name__ + ".path")
Expand Down Expand Up @@ -2111,8 +2108,7 @@ def SetDestination(self, path):
specifically, "$(DIR)/path".
"""

path_tree_match = self.path_tree_re.search(path)
if path_tree_match:
if path_tree_match := self.path_tree_re.search(path):
path_tree = path_tree_match.group(1)
if path_tree in self.path_tree_first_to_subfolder:
subfolder = self.path_tree_first_to_subfolder[path_tree]
Expand Down
3 changes: 1 addition & 2 deletions pylib/packaging/_elffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def __init__(self, f: IO[bytes]) -> None:
ident = self._read("16B")
except struct.error:
raise ELFInvalid("unable to parse identification")
magic = bytes(ident[:4])
if magic != b"\x7fELF":
if (magic := bytes(ident[:4])) != b"\x7fELF":
raise ELFInvalid(f"invalid magic: {magic!r}")

self.capacity = ident[4] # Format for program header (bitness).
Expand Down
3 changes: 1 addition & 2 deletions pylib/packaging/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ def _evaluate_markers(markers: MarkerList, environment: Dict[str, str]) -> bool:

def format_full_version(info: "sys._version_info") -> str:
version = "{0.major}.{0.minor}.{0.micro}".format(info)
kind = info.releaselevel
if kind != "final":
if (kind := info.releaselevel) != "final":
version += kind[0] + str(info.serial)
return version

Expand Down
3 changes: 1 addition & 2 deletions pylib/packaging/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,7 @@ def _process_description_content_type(self, value: str) -> str:
f"{{field}} must be one of {list(content_types)}, not {value!r}"
)

charset = parameters.get("charset", "UTF-8")
if charset != "UTF-8":
if (charset := parameters.get("charset", "UTF-8")) != "UTF-8":
raise self._invalid_metadata(
f"{{field}} can only specify the UTF-8 charset, not {list(charset)}"
)
Expand Down
Loading