Skip to content

Commit

Permalink
Remove PY2 and PY3
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Feb 16, 2025
1 parent 1481802 commit 526f4db
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 22 deletions.
5 changes: 0 additions & 5 deletions labelme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# flake8: noqa

import logging
import sys

from qtpy import QT_VERSION

Expand All @@ -19,10 +18,6 @@
QT5 = QT_VERSION[0] == "5"
del QT_VERSION

PY2 = sys.version[0] == "2"
PY3 = sys.version[0] == "3"
del sys

from labelme.label_file import LabelFile
from labelme import testing
from labelme import utils
3 changes: 1 addition & 2 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from qtpy import QtWidgets
from qtpy.QtCore import Qt

from labelme import PY2
from labelme import __appname__
from labelme import ai
from labelme.ai import MODELS
Expand Down Expand Up @@ -1420,7 +1419,7 @@ def format_shape(s):
data = s.other_data.copy()
data.update(
dict(
label=s.label.encode("utf-8") if PY2 else s.label,
label=s.label,
points=[(p.x(), p.y()) for p in s.points],
group_id=s.group_id,
description=s.description,
Expand Down
3 changes: 0 additions & 3 deletions labelme/cli/draw_json.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#!/usr/bin/env python

import argparse
import sys

import imgviz
import matplotlib.pyplot as plt

from labelme import utils
from labelme.label_file import LabelFile

PY2 = sys.version_info[0] == 2


def main():
parser = argparse.ArgumentParser()
Expand Down
14 changes: 2 additions & 12 deletions labelme/label_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import PIL.Image
from loguru import logger

from labelme import PY2
from labelme import QT4
from labelme import __version__
from labelme import utils

Expand All @@ -18,11 +16,7 @@
@contextlib.contextmanager
def open(name, mode):
assert mode in ["r", "w"]
if PY2:
mode += "b"
encoding = None
else:
encoding = "utf-8"
encoding = "utf-8"
yield io.open(name, mode, encoding=encoding)
return

Expand Down Expand Up @@ -55,9 +49,7 @@ def load_image_file(filename):

with io.BytesIO() as f:
ext = osp.splitext(filename)[1].lower()
if PY2 and QT4:
format = "PNG"
elif ext in [".jpg", ".jpeg"]:
if ext in [".jpg", ".jpeg"]:
format = "JPEG"
else:
format = "PNG"
Expand Down Expand Up @@ -90,8 +82,6 @@ def load(self, filename):

if data["imageData"] is not None:
imageData = base64.b64decode(data["imageData"])
if PY2 and QT4:
imageData = utils.img_data_to_png_data(imageData)
else:
# relative path from label file to relative path from cwd
imagePath = osp.join(osp.dirname(filename), data["imagePath"])
Expand Down

0 comments on commit 526f4db

Please # to comment.