mach: remove python2 compatibility code (#33410)

* util.py: Remove six

We don't need to support python2 anymore, so we can just use
`str(x)` instead of `six.ensure_str(x)`

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

* config.py: Remove six

We don't need to support python2 anymore, so we can just use
`str(x)` instead of `six.ensure_str(x)`

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

* main.py: Remove six

We don't need to support python2 anymore, so we can just use
`str(x)` instead of `six.ensure_str(x)`

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

* main.py: Fix `--settings` being ignored

Previously `paths` was unused in this function,
and the usage for the settings_file would have no effect.

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

* terminal.py: Remove `six`

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

* registrar.py: Remove `six`

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

* mach/util.py: Remove `six`

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

* mach: Remove python2 from the list of programming languages

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

---------

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
Jonathan Schwender 2024-09-11 20:25:25 +02:00 committed by GitHub
parent ed5dc43f16
commit b42f5eaa17
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 13 additions and 25 deletions

View file

@ -19,10 +19,8 @@ from __future__ import absolute_import, unicode_literals
import collections import collections
import os import os
import sys import sys
import six
from functools import wraps from functools import wraps
from six.moves.configparser import RawConfigParser, NoSectionError from configparser import RawConfigParser, NoSectionError
from six import string_types
class ConfigException(Exception): class ConfigException(Exception):
@ -62,7 +60,7 @@ class ConfigType(object):
class StringType(ConfigType): class StringType(ConfigType):
@staticmethod @staticmethod
def validate(value): def validate(value):
if not isinstance(value, string_types): if not isinstance(value, str):
raise TypeError() raise TypeError()
@staticmethod @staticmethod
@ -109,7 +107,7 @@ class PositiveIntegerType(IntegerType):
class PathType(StringType): class PathType(StringType):
@staticmethod @staticmethod
def validate(value): def validate(value):
if not isinstance(value, string_types): if not isinstance(value, str):
raise TypeError() raise TypeError()
@staticmethod @staticmethod
@ -140,7 +138,7 @@ def reraise_attribute_error(func):
return func(*args, **kwargs) return func(*args, **kwargs)
except KeyError: except KeyError:
exc_class, exc, tb = sys.exc_info() exc_class, exc, tb = sys.exc_info()
six.reraise(AttributeError().__class__, exc, tb) raise(AttributeError().__class__, exc, tb)
return _ return _
@ -337,7 +335,7 @@ class ConfigSettings(collections.abc.Mapping):
extra -- A dict of additional key/value pairs to add to the extra -- A dict of additional key/value pairs to add to the
setting metadata. setting metadata.
""" """
if isinstance(type_cls, string_types): if isinstance(type_cls, str):
type_cls = TYPE_CLASSES[type_cls] type_cls = TYPE_CLASSES[type_cls]
meta = { meta = {

View file

@ -18,8 +18,6 @@ import traceback
import uuid import uuid
from collections.abc import Iterable from collections.abc import Iterable
from six import string_types
from .base import ( from .base import (
CommandContext, CommandContext,
MachError, MachError,
@ -538,7 +536,7 @@ To see more help for a specific command, run:
machrc, .machrc machrc, .machrc
""" """
if isinstance(paths, string_types): if isinstance(paths, str):
paths = [paths] paths = [paths]
valid_names = ('machrc', '.machrc') valid_names = ('machrc', '.machrc')
@ -552,7 +550,7 @@ To see more help for a specific command, run:
if os.path.isfile(path): if os.path.isfile(path):
return path return path
files = map(find_in_dir, self.settings_paths) files = map(find_in_dir, paths)
files = filter(bool, files) files = filter(bool, files)
self.settings.load_files(files) self.settings.load_files(files)

View file

@ -6,8 +6,6 @@ from __future__ import absolute_import, print_function, unicode_literals
import time import time
import six
from .base import MachError from .base import MachError
INVALID_COMMAND_CONTEXT = r''' INVALID_COMMAND_CONTEXT = r'''
@ -111,7 +109,7 @@ class MachRegistrar(object):
end_time = time.time() end_time = time.time()
result = result or 0 result = result or 0
assert isinstance(result, six.integer_types) assert isinstance(result, int)
if context and not debug_command: if context and not debug_command:
postrun = getattr(context, 'post_dispatch_handler', None) postrun = getattr(context, 'post_dispatch_handler', None)

View file

@ -13,8 +13,6 @@ from __future__ import absolute_import, print_function, unicode_literals
import logging import logging
import sys import sys
from six.moves import range
class LoggingHandler(logging.Handler): class LoggingHandler(logging.Handler):
"""Custom logging handler that works with terminal window dressing. """Custom logging handler that works with terminal window dressing.

View file

@ -7,8 +7,6 @@ from __future__ import absolute_import, unicode_literals
import os import os
import sys import sys
from six import text_type
def setenv(key, value): def setenv(key, value):
"""Compatibility shim to ensure the proper string type is used with """Compatibility shim to ensure the proper string type is used with
@ -17,9 +15,9 @@ def setenv(key, value):
encoding = "mbcs" if sys.platform == "win32" else "utf-8" encoding = "mbcs" if sys.platform == "win32" else "utf-8"
if sys.version_info[0] == 2: if sys.version_info[0] == 2:
if isinstance(key, text_type): if isinstance(key, str):
key = key.encode(encoding) key = key.encode(encoding)
if isinstance(value, text_type): if isinstance(value, str):
value = value.encode(encoding) value = value.encode(encoding)
else: else:
if isinstance(key, bytes): if isinstance(key, bytes):

View file

@ -26,8 +26,7 @@ setup(
'Development Status :: 5 - Production/Stable', 'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)', 'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
'Natural Language :: English', 'Natural Language :: English',
'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.5',
], ],
install_requires=[ install_requires=[
'blessings', 'blessings',

View file

@ -19,7 +19,6 @@ import urllib.request
import zipfile import zipfile
from typing import Dict, List, Union from typing import Dict, List, Union
import six
from io import BufferedIOBase, BytesIO from io import BufferedIOBase, BytesIO
from socket import error as socket_error from socket import error as socket_error
@ -188,7 +187,7 @@ def append_paths_to_env(env: Dict[str, str], key: str, paths: Union[str, List[st
existing_value = env.get(key, None) existing_value = env.get(key, None)
if existing_value: if existing_value:
new_value = six.ensure_str(existing_value) + os.pathsep + paths new_value = str(existing_value) + os.pathsep + paths
else: else:
new_value = paths new_value = paths
env[key] = new_value env[key] = new_value
@ -201,7 +200,7 @@ def prepend_paths_to_env(env: Dict[str, str], key: str, paths: Union[str, List[s
existing_value = env.get(key, None) existing_value = env.get(key, None)
new_value = paths new_value = paths
if existing_value: if existing_value:
new_value += os.pathsep + six.ensure_str(existing_value) new_value += os.pathsep + str(existing_value)
env[key] = new_value env[key] = new_value