mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
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
426e311669
commit
664c1ecf7c
@ -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,10 +13,10 @@ import shutil
|
||||
import tempfile
|
||||
import time
|
||||
from contextlib import AsyncExitStack
|
||||
from distutils.util import strtobool
|
||||
from pathlib import Path
|
||||
|
||||
import aiohttp
|
||||
from mach.util import strtobool
|
||||
from mardor.reader import MarReader
|
||||
from mardor.signing import get_keysize
|
||||
from scriptworker.utils import get_hash, retry_async
|
||||
|
@ -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 New Issue
Block a user