forked from mirrors/gecko-dev
Bug 1877347 - Replace distutils.util.strtobool with a custom strtobool within mach r=firefox-build-system-reviewers,glandium
The migration advice (https://peps.python.org/pep-0632/#migration-advice) suggests reimplementing the functionality as per the docs (https://docs.python.org/3.9/distutils/apiref.html#distutils.util.strtobool) which is exactly what I've done here. Differential Revision: https://phabricator.services.mozilla.com/D199950
This commit is contained in:
parent
87cf2400d6
commit
66001aead0
5 changed files with 35 additions and 17 deletions
|
|
@ -115,3 +115,18 @@ def to_optional_str(path: Optional[Path]):
|
|||
return str(path)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def strtobool(value: str):
|
||||
# Reimplementation of distutils.util.strtobool
|
||||
# https://docs.python.org/3.9/distutils/apiref.html#distutils.util.strtobool
|
||||
true_vals = ("y", "yes", "t", "true", "on", "1")
|
||||
false_vals = ("n", "no", "f", "false", "off", "0")
|
||||
|
||||
value = value.lower()
|
||||
if value in true_vals:
|
||||
return 1
|
||||
if value in false_vals:
|
||||
return 0
|
||||
|
||||
raise ValueError(f'Expected one of: {", ".join(true_vals + false_vals)}')
|
||||
|
|
|
|||
|
|
@ -409,7 +409,7 @@ def get_clang_tools(command_context, clang_tools_path):
|
|||
|
||||
def prompt_bool(prompt, limit=5):
|
||||
"""Prompts the user with prompt and requires a boolean value."""
|
||||
from distutils.util import strtobool
|
||||
from mach.util import strtobool
|
||||
|
||||
for _ in range(limit):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ def build_repo_relative_path(abs_path, repo_path):
|
|||
|
||||
def prompt_bool(prompt, limit=5):
|
||||
"""Prompts the user with prompt and requires a boolean value."""
|
||||
from distutils.util import strtobool
|
||||
from mach.util import strtobool
|
||||
|
||||
for _ in range(limit):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import shutil
|
|||
import tempfile
|
||||
import time
|
||||
from contextlib import AsyncExitStack
|
||||
from distutils.util import strtobool
|
||||
from pathlib import Path
|
||||
|
||||
import aiohttp
|
||||
|
|
@ -51,6 +50,22 @@ BCJ_OPTIONS = {
|
|||
}
|
||||
|
||||
|
||||
def strtobool(value: str):
|
||||
# Copied from `mach.util` since this script runs outside of a mach environment
|
||||
# Reimplementation of distutils.util.strtobool
|
||||
# https://docs.python.org/3.9/distutils/apiref.html#distutils.util.strtobool
|
||||
true_vals = ("y", "yes", "t", "true", "on", "1")
|
||||
false_vals = ("n", "no", "f", "false", "off", "0")
|
||||
|
||||
value = value.lower()
|
||||
if value in true_vals:
|
||||
return 1
|
||||
if value in false_vals:
|
||||
return 0
|
||||
|
||||
raise ValueError(f'Expected one of: {", ".join(true_vals + false_vals)}')
|
||||
|
||||
|
||||
def verify_signature(mar, cert):
|
||||
log.info("Checking %s signature", mar)
|
||||
with open(mar, "rb") as mar_fh:
|
||||
|
|
|
|||
|
|
@ -17,23 +17,11 @@ from functools import partial
|
|||
import gecko_taskgraph.main
|
||||
from gecko_taskgraph.main import commands as taskgraph_commands
|
||||
from mach.decorators import Command, CommandArgument, SubCommand
|
||||
from mach.util import strtobool
|
||||
|
||||
logger = logging.getLogger("taskcluster")
|
||||
|
||||
|
||||
def strtobool(value):
|
||||
"""Convert string to boolean.
|
||||
|
||||
Wraps "distutils.util.strtobool", deferring the import of the package
|
||||
in case it's not installed. Otherwise, we have a "chicken and egg problem" where
|
||||
|mach bootstrap| would install the required package to enable "distutils.util", but
|
||||
it can't because mach fails to interpret this file.
|
||||
"""
|
||||
from distutils.util import strtobool
|
||||
|
||||
return bool(strtobool(value))
|
||||
|
||||
|
||||
def get_taskgraph_command_parser(name):
|
||||
"""Given a command name, obtain its argument parser.
|
||||
|
||||
|
|
@ -59,7 +47,7 @@ def get_taskgraph_decision_parser():
|
|||
(
|
||||
["--optimize-target-tasks"],
|
||||
{
|
||||
"type": lambda flag: strtobool(flag),
|
||||
"type": lambda flag: bool(strtobool(flag)),
|
||||
"nargs": "?",
|
||||
"const": "true",
|
||||
"help": "If specified, this indicates whether the target "
|
||||
|
|
|
|||
Loading…
Reference in a new issue