Skip to content

Commit

Permalink
Remove six
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
  • Loading branch information
geigerzaehler committed Dec 14, 2023
1 parent f6cbf29 commit 2c0f891
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 28 deletions.
5 changes: 2 additions & 3 deletions beetsplug/alternatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from typing import Iterator, List, Optional, Tuple

import beets
import six
from beets import art, util
from beets.library import Item, parse_query_string
from beets.plugins import BeetsPlugin
Expand Down Expand Up @@ -297,8 +296,8 @@ def destination(self, item: Item) -> bytes:
assert isinstance(path, bytes)
return path

def set_path(self, item, path):
item[self.path_key] = six.text_type(path, "utf8")
def set_path(self, item, path: bytes):
item[self.path_key] = str(path, "utf8")

@staticmethod
def _get_path(item, path_key) -> Optional[bytes]:
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ classifiers = [
[tool.poetry.dependencies]
python = "^3.8.1"
beets = "^1.6.0"
six = "^1.16.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.3.1"
Expand Down
26 changes: 3 additions & 23 deletions test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
import tempfile
from concurrent import futures
from contextlib import contextmanager
from io import StringIO
from typing import Optional
from unittest import TestCase
from zlib import crc32

import beets
import beets.library
import six
from beets import logging, plugins, ui, util
from beets.library import Item
from beets.util import MoveOperation, bytestring_path, displayable_path, syspath
from mediafile import MediaFile
from mock import patch
from six import StringIO

import beetsplug.alternatives as alternatives
import beetsplug.convert as convert
Expand All @@ -30,7 +29,7 @@ def __init__(self):
self.messages = []

def emit(self, record):
self.messages.append(six.text_type(record.msg))
self.messages.append(str(record.msg))


@contextmanager
Expand All @@ -56,8 +55,6 @@ def capture_stdout():
"""
org = sys.stdout
sys.stdout = capture = StringIO()
if six.PY2: # StringIO encoding attr isn't writable in python >= 3
sys.stdout.encoding = "utf-8"
try:
yield sys.stdout
finally:
Expand All @@ -75,29 +72,12 @@ def control_stdin(input=None):
"""
org = sys.stdin
sys.stdin = StringIO(input)
if six.PY2: # StringIO encoding attr isn't writable in python >= 3
sys.stdin.encoding = "utf-8"
try:
yield sys.stdin
finally:
sys.stdin = org


def _convert_args(args):
"""Convert args to bytestrings for Python 2 and convert them to strings
on Python 3.
"""
for i, elem in enumerate(args):
if six.PY2:
if isinstance(elem, six.text_type):
args[i] = elem.encode(util.arg_encoding())
else:
if isinstance(elem, bytes):
args[i] = elem.decode(util.arg_encoding())

return args


class Assertions(TestCase):
def assertFileTag(self, path, tag):
self.assertIsFile(path)
Expand Down Expand Up @@ -278,7 +258,7 @@ def runcli(self, *args):
# TODO mock stdin
with capture_stdout() as out:
try:
ui._raw_main(_convert_args(list(args)), self.lib)
ui._raw_main(list(args), self.lib)
except ui.UserError as u:
# TODO remove this and handle exceptions in tests
print(u.args[0])
Expand Down

0 comments on commit 2c0f891

Please sign in to comment.