Skip to content

Commit

Permalink
Remove usage of six from ramble and vendor deps
Browse files Browse the repository at this point in the history
  • Loading branch information
linsword13 committed May 31, 2024
1 parent 867ebb5 commit b117765
Show file tree
Hide file tree
Showing 97 changed files with 323 additions and 604 deletions.
6 changes: 2 additions & 4 deletions lib/ramble/external/archspec/cpu/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import subprocess
import warnings

import six

from .microarchitecture import generic_microarchitecture, TARGETS
from .schema import TARGETS_JSON

Expand Down Expand Up @@ -83,7 +81,7 @@ def _check_output(args, env):
output = subprocess.Popen( # pylint: disable=consider-using-with
args, stdout=subprocess.PIPE, env=env
).communicate()[0]
return six.text_type(output.decode("utf-8"))
return str(output.decode("utf-8"))


def _machine():
Expand Down Expand Up @@ -267,7 +265,7 @@ def compatibility_check(architecture_family):
this test can be used, e.g. x86_64 or ppc64le etc.
"""
# Turn the argument into something iterable
if isinstance(architecture_family, six.string_types):
if isinstance(architecture_family, str):
architecture_family = (architecture_family,)

def decorator(func):
Expand Down
6 changes: 2 additions & 4 deletions lib/ramble/external/archspec/cpu/microarchitecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import re
import warnings

import six

import archspec
import archspec.cpu.alias
import archspec.cpu.schema
Expand All @@ -27,7 +25,7 @@ def coerce_target_names(func):

@functools.wraps(func)
def _impl(self, other):
if isinstance(other, six.string_types):
if isinstance(other, str):
if other not in TARGETS:
msg = '"{0}" is not a valid target name'
raise ValueError(msg.format(other))
Expand Down Expand Up @@ -150,7 +148,7 @@ def __str__(self):

def __contains__(self, feature):
# Feature must be of a string type, so be defensive about that
if not isinstance(feature, six.string_types):
if not isinstance(feature, str):
msg = "only objects of string types are accepted [got {0}]"
raise TypeError(msg.format(str(type(feature))))

Expand Down
8 changes: 3 additions & 5 deletions lib/ramble/external/ctest_log_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@
import re
import math
import multiprocessing
import io
import time
from contextlib import contextmanager

from six import StringIO
from six import string_types

class prefilter(object):
"""Make regular expressions faster with a simple prefiltering predicate.
Expand Down Expand Up @@ -282,7 +280,7 @@ def __getitem__(self, line_no):

def __str__(self):
"""Returns event lines and context."""
out = StringIO()
out = io.StringIO()
for i in range(self.start, self.end):
if i == self.line_no:
out.write(' >> %-6d%s' % (i, self[i]))
Expand Down Expand Up @@ -423,7 +421,7 @@ def parse(self, stream, context=6, jobs=None):
(tuple): two lists containing ``BuildError`` and
``BuildWarning`` objects.
"""
if isinstance(stream, string_types):
if isinstance(stream, str):
with open(stream) as f:
return self.parse(f, context, jobs)

Expand Down
5 changes: 2 additions & 3 deletions lib/ramble/llnl/util/argparsewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

import argparse
import errno
import io
import re
import sys

from six import StringIO


class Command(object):
"""Parsed representation of a command from argparse.
Expand Down Expand Up @@ -186,7 +185,7 @@ def __init__(self, prog, out=None, aliases=False,
self.rst_levels = rst_levels

def format(self, cmd):
string = StringIO()
string = io.StringIO()
string.write(self.begin_command(cmd.prog))

if cmd.description:
Expand Down
18 changes: 8 additions & 10 deletions lib/ramble/llnl/util/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from contextlib import contextmanager
from sys import platform as _platform

import six

from llnl.util import tty
from llnl.util.compat import Sequence
from llnl.util.lang import dedupe, memoized
Expand Down Expand Up @@ -375,7 +373,7 @@ def chgrp(path, group, follow_symlinks=True):
if is_windows:
raise OSError("Function 'chgrp' is not supported on Windows")

if isinstance(group, six.string_types):
if isinstance(group, str):
gid = grp.getgrnam(group).gr_gid
else:
gid = group
Expand Down Expand Up @@ -870,7 +868,7 @@ def open_if_filename(str_or_file, mode='r'):
If it's a file object, just yields the file object.
"""
if isinstance(str_or_file, six.string_types):
if isinstance(str_or_file, str):
with open(str_or_file, mode) as f:
yield f
else:
Expand Down Expand Up @@ -1392,7 +1390,7 @@ def find(root, files, recursive=True):
Returns:
list: The files that have been found
"""
if isinstance(files, six.string_types):
if isinstance(files, str):
files = [files]

if recursive:
Expand Down Expand Up @@ -1456,7 +1454,7 @@ class FileList(Sequence):
"""

def __init__(self, files):
if isinstance(files, six.string_types):
if isinstance(files, str):
files = [files]

self.files = list(dedupe(files))
Expand Down Expand Up @@ -1554,7 +1552,7 @@ def directories(self):
def directories(self, value):
value = value or []
# Accept a single directory as input
if isinstance(value, six.string_types):
if isinstance(value, str):
value = [value]

self._directories = [path_to_os_path(os.path.normpath(x))[0] for x in value]
Expand Down Expand Up @@ -1690,7 +1688,7 @@ def find_headers(headers, root, recursive=False):
Returns:
HeaderList: The headers that have been found
"""
if isinstance(headers, six.string_types):
if isinstance(headers, str):
headers = [headers]
elif not isinstance(headers, Sequence):
message = '{0} expects a string or sequence of strings as the '
Expand Down Expand Up @@ -1846,7 +1844,7 @@ def find_system_libraries(libraries, shared=True):
Returns:
LibraryList: The libraries that have been found
"""
if isinstance(libraries, six.string_types):
if isinstance(libraries, str):
libraries = [libraries]
elif not isinstance(libraries, Sequence):
message = '{0} expects a string or sequence of strings as the '
Expand Down Expand Up @@ -1900,7 +1898,7 @@ def find_libraries(libraries, root, shared=True, recursive=False):
Returns:
LibraryList: The libraries that have been found
"""
if isinstance(libraries, six.string_types):
if isinstance(libraries, str):
libraries = [libraries]
elif not isinstance(libraries, Sequence):
message = '{0} expects a string or sequence of strings as the '
Expand Down
12 changes: 3 additions & 9 deletions lib/ramble/llnl/util/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
from datetime import datetime, timedelta
from typing import List, Tuple

import six
from six import string_types

from llnl.util.compat import MutableMapping, MutableSequence, zip_longest

# Ignore emacs backups when listing modules
Expand Down Expand Up @@ -202,12 +199,9 @@ def _memoized_function(*args, **kwargs):
return ret
except TypeError as e:
# TypeError is raised when indexing into a dict if the key is unhashable.
raise six.raise_from(
UnhashableArguments(
"args + kwargs '{}' was not hashable for function '{}'"
.format(key, func.__name__),
),
e)
raise UnhashableArguments(
"args + kwargs '{}' was not hashable for function '{}'".format(key, func.__name__),
) from e

return _memoized_function

Expand Down
22 changes: 10 additions & 12 deletions lib/ramble/llnl/util/tty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from __future__ import unicode_literals

import contextlib
import io
import os
import struct
import sys
Expand All @@ -17,9 +18,6 @@
from datetime import datetime
from sys import platform as _platform

import six
from six import StringIO

if _platform != "win32":
import fcntl
import termios
Expand Down Expand Up @@ -201,7 +199,7 @@ def msg(message, *args, **kwargs):
)
)
for arg in args:
print(indent + _output_filter(six.text_type(arg)))
print(indent + _output_filter(str(arg)))


def info(message, *args, **kwargs):
Expand All @@ -222,14 +220,14 @@ def info(message, *args, **kwargs):
format,
st_text,
get_timestamp(),
cescape(_output_filter(six.text_type(message)))
cescape(_output_filter(str(message)))
),
stream=stream
)
for arg in args:
if wrap:
lines = textwrap.wrap(
_output_filter(six.text_type(arg)),
_output_filter(str(arg)),
initial_indent=indent,
subsequent_indent=indent,
break_long_words=break_long_words
Expand All @@ -238,7 +236,7 @@ def info(message, *args, **kwargs):
stream.write(line + '\n')
else:
stream.write(
indent + _output_filter(six.text_type(arg)) + '\n'
indent + _output_filter(str(arg)) + '\n'
)


Expand All @@ -262,7 +260,7 @@ def error(message, *args, **kwargs):

kwargs.setdefault('format', '*r')
kwargs.setdefault('stream', sys.stderr)
info("Error: " + six.text_type(message), *args, **kwargs)
info("Error: " + str(message), *args, **kwargs)


def warn(message, *args, **kwargs):
Expand All @@ -271,7 +269,7 @@ def warn(message, *args, **kwargs):

kwargs.setdefault('format', '*Y')
kwargs.setdefault('stream', sys.stderr)
info("Warning: " + six.text_type(message), *args, **kwargs)
info("Warning: " + str(message), *args, **kwargs)


def die(message, *args, **kwargs):
Expand All @@ -294,7 +292,7 @@ def get_number(prompt, **kwargs):
number = None
while number is None:
msg(prompt, newline=False)
if ans == six.text_type(abort):
if ans == str(abort):
return None

if ans:
Expand Down Expand Up @@ -359,11 +357,11 @@ def hline(label=None, **kwargs):
cols -= 2
cols = min(max_width, cols)

label = six.text_type(label)
label = str(label)
prefix = char * 2 + " "
suffix = " " + (cols - len(prefix) - clen(label)) * char

out = StringIO()
out = io.StringIO()
out.write(prefix)
out.write(label)
out.write(suffix)
Expand Down
7 changes: 3 additions & 4 deletions lib/ramble/llnl/util/tty/colify.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
"""
from __future__ import division, unicode_literals

import io
import os
import sys

from six import StringIO, text_type

from llnl.util.tty import terminal_size
from llnl.util.tty.color import cextra, clen

Expand Down Expand Up @@ -139,7 +138,7 @@ def colify(elts, **options):
% next(options.iterkeys()))

# elts needs to be an array of strings so we can count the elements
elts = [text_type(elt) for elt in elts]
elts = [str(elt) for elt in elts]
if not elts:
return (0, ())

Expand Down Expand Up @@ -237,7 +236,7 @@ def transpose():
def colified(elts, **options):
"""Invokes the ``colify()`` function but returns the result as a string
instead of writing it to an output string."""
sio = StringIO()
sio = io.StringIO()
options['output'] = sio
colify(elts, **options)
return sio.getvalue()
4 changes: 1 addition & 3 deletions lib/ramble/llnl/util/tty/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@
import sys
from contextlib import contextmanager

import six


class ColorParseError(Exception):
"""Raised when a color format fails to parse."""
Expand Down Expand Up @@ -253,7 +251,7 @@ def cescape(string):
Returns:
(str): the string with color codes escaped
"""
string = six.text_type(string)
string = str(string)
string = string.replace('@', '@@')
string = string.replace('}', '}}')
return string
Expand Down
Loading

0 comments on commit b117765

Please sign in to comment.