Drop Python 2.7 support

This commit is contained in:
Fabien LOISON 2021-06-23 11:17:26 +02:00
parent 3607487fb7
commit d74d9bd5ca
No known key found for this signature in database
GPG Key ID: FF90CA148348048E
8 changed files with 26 additions and 30 deletions

View File

@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
python-version: [2.7, 3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9]
name: "Build and test YOGA"
runs-on: ubuntu-latest

View File

@ -54,6 +54,10 @@ Documentation
Changelog
---------
* **[NEXT]** (changes on ``master`` that have not been released yet):
* Python 2.7 support dropped
* **1.0.0:**
* WEBP (lossy and lossless) images supported as output format

View File

@ -29,7 +29,7 @@ def black_fix(session):
session.run("black", *PYTHON_FILES)
@nox.session(python=["2.7", "3.7", "3.8", "3.9"], reuse_venv=True)
@nox.session(python=["3.7", "3.8", "3.9"], reuse_venv=True)
def test(session):
session.install("pytest")
session.install(".")

View File

@ -1,3 +1,3 @@
[tool.black]
line-length = 79
target-version = ['py27']
target-version = ['py37']

View File

@ -38,9 +38,6 @@ class Test_normalize_options(object):
("jpeg_quality", b"0.42", 0.42),
("jpeg_quality", b".42", 0.42),
("jpeg_quality", b"42", 0.42),
("jpeg_quality", u"0.42", 0.42),
("jpeg_quality", u".42", 0.42),
("jpeg_quality", u"42", 0.42),
# webp_quality
("webp_quality", 0.42, 0.42),
("webp_quality", 42, 0.42),
@ -50,9 +47,6 @@ class Test_normalize_options(object):
("webp_quality", b"0.42", 0.42),
("webp_quality", b".42", 0.42),
("webp_quality", b"42", 0.42),
("webp_quality", u"0.42", 0.42),
("webp_quality", u".42", 0.42),
("webp_quality", u"42", 0.42),
# opacity_threshold
("opacity_threshold", 128, 128),
("opacity_threshold", 0.5, 128),
@ -64,7 +58,6 @@ class Test_normalize_options(object):
("opacity_threshold", 300, 255),
("opacity_threshold", "300", 255),
("opacity_threshold", b"255", 255),
("opacity_threshold", u"255", 255),
# png_slow_optimization
("png_slow_optimization", True, True),
("png_slow_optimization", False, False),
@ -89,7 +82,6 @@ class Test_normalize_options(object):
("100:200", [100, 200]),
("100,200", [100, 200]),
("100;200", [100, 200]),
(u"100x200", [100, 200]),
(b"100x200", [100, 200]),
([100, 200], [100, 200]),
],

View File

@ -8,56 +8,56 @@ from yoga.model import helpers
class Test_model_helpers(object):
def test_normalize_path(self):
assert (
helpers.normalize_path(u"images/texture.png")
helpers.normalize_path("images/texture.png")
== "images/texture.png"
)
assert (
helpers.normalize_path(u"./images/texture.png")
helpers.normalize_path("./images/texture.png")
== "images/texture.png"
)
assert (
helpers.normalize_path(u".\\images\\texture.png")
helpers.normalize_path(".\\images\\texture.png")
== "images/texture.png"
)
assert (
helpers.normalize_path(u"./images\\texture.png")
helpers.normalize_path("./images\\texture.png")
== "images/texture.png"
)
assert (
helpers.normalize_path(u".\\images/texture.png")
helpers.normalize_path(".\\images/texture.png")
== "images/texture.png"
)
assert (
helpers.normalize_path(u"../images/texture.png")
helpers.normalize_path("../images/texture.png")
== "images/texture.png"
)
assert (
helpers.normalize_path(u"..\\images\\texture.png")
helpers.normalize_path("..\\images\\texture.png")
== "images/texture.png"
)
assert (
helpers.normalize_path(u"./images/subfolder/../texture.png")
helpers.normalize_path("./images/subfolder/../texture.png")
== "images/texture.png"
)
assert (
helpers.normalize_path(u"./images/sub1\\sub2/../../texture.png")
helpers.normalize_path("./images/sub1\\sub2/../../texture.png")
== "images/texture.png"
)
assert (
helpers.normalize_path(u"./images/texture.png")
helpers.normalize_path("./images/texture.png")
== "images/texture.png"
)
assert (
helpers.normalize_path(u"/images/texture.png")
helpers.normalize_path("/images/texture.png")
== "images/texture.png"
)
assert (
helpers.normalize_path(u"C:\\images\\texture.png")
helpers.normalize_path("C:\\images\\texture.png")
== "images/texture.png"
)
assert (
helpers.normalize_path(u"somE_valid-caractères of files.png")
helpers.normalize_path("somE_valid-caractères of files.png")
== "some_valid-caracteres of files.png"
)

View File

@ -188,7 +188,7 @@ def optimize(input_file, output_file, options={}, verbose=False, quiet=False):
options = normalize_options(options)
# Image as file-like object
if type(input_file) in (str, type(u"")):
if type(input_file) is str:
image_file = open(input_file, "rb")
elif hasattr(input_file, "read") and hasattr(input_file, "seek"):
image_file = input_file
@ -237,5 +237,5 @@ def optimize(input_file, output_file, options={}, verbose=False, quiet=False):
output_file.write(output_image_bytes)
# Close input file if we opened it
if type(input_file) in (str, type(u"")):
if type(input_file) is str:
image_file.close()

View File

@ -52,7 +52,7 @@ def normalize_options(options=None):
if type(value) == bytes:
value = value.decode()
if type(value) in (str, type(u"")):
if type(value) in (str, bytes):
value = value.lower()
if value.isdigit():
@ -77,7 +77,7 @@ def normalize_options(options=None):
if "jpeg_quality" in options:
value = options["jpeg_quality"]
if type(value) in (str, type(u""), bytes):
if type(value) in (str, bytes):
value = float(value)
if value > 1:
@ -94,7 +94,7 @@ def normalize_options(options=None):
if "webp_quality" in options:
value = options["webp_quality"]
if type(value) in (str, type(u""), bytes):
if type(value) in (str, bytes):
value = float(value)
if value > 1:
@ -111,7 +111,7 @@ def normalize_options(options=None):
if "opacity_threshold" in options:
value = options["opacity_threshold"]
if type(value) in (str, type(u""), bytes):
if type(value) in (str, bytes):
value = float(value)
if value < 1: