Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PY2/PY3 checks #1477

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -16,7 +16,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 @@ -1429,7 +1428,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
15 changes: 2 additions & 13 deletions labelme/label_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import PIL.Image

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


Expand Down Expand Up @@ -55,9 +48,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 +81,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