mirror of https://github.com/wanadev/yoga.git
Drop Python 2.7 support
This commit is contained in:
parent
3607487fb7
commit
d74d9bd5ca
|
@ -8,7 +8,7 @@ jobs:
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [2.7, 3.7, 3.8, 3.9]
|
python-version: [3.7, 3.8, 3.9]
|
||||||
|
|
||||||
name: "Build and test YOGA"
|
name: "Build and test YOGA"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
@ -54,6 +54,10 @@ Documentation
|
||||||
Changelog
|
Changelog
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
* **[NEXT]** (changes on ``master`` that have not been released yet):
|
||||||
|
|
||||||
|
* Python 2.7 support dropped
|
||||||
|
|
||||||
* **1.0.0:**
|
* **1.0.0:**
|
||||||
|
|
||||||
* WEBP (lossy and lossless) images supported as output format
|
* WEBP (lossy and lossless) images supported as output format
|
||||||
|
|
|
@ -29,7 +29,7 @@ def black_fix(session):
|
||||||
session.run("black", *PYTHON_FILES)
|
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):
|
def test(session):
|
||||||
session.install("pytest")
|
session.install("pytest")
|
||||||
session.install(".")
|
session.install(".")
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
[tool.black]
|
[tool.black]
|
||||||
line-length = 79
|
line-length = 79
|
||||||
target-version = ['py27']
|
target-version = ['py37']
|
||||||
|
|
|
@ -38,9 +38,6 @@ class Test_normalize_options(object):
|
||||||
("jpeg_quality", b"0.42", 0.42),
|
("jpeg_quality", b"0.42", 0.42),
|
||||||
("jpeg_quality", b".42", 0.42),
|
("jpeg_quality", b".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
|
||||||
("webp_quality", 0.42, 0.42),
|
("webp_quality", 0.42, 0.42),
|
||||||
("webp_quality", 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"0.42", 0.42),
|
||||||
("webp_quality", b".42", 0.42),
|
("webp_quality", b".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
|
||||||
("opacity_threshold", 128, 128),
|
("opacity_threshold", 128, 128),
|
||||||
("opacity_threshold", 0.5, 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", "300", 255),
|
("opacity_threshold", "300", 255),
|
||||||
("opacity_threshold", b"255", 255),
|
("opacity_threshold", b"255", 255),
|
||||||
("opacity_threshold", u"255", 255),
|
|
||||||
# png_slow_optimization
|
# png_slow_optimization
|
||||||
("png_slow_optimization", True, True),
|
("png_slow_optimization", True, True),
|
||||||
("png_slow_optimization", False, False),
|
("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]),
|
("100,200", [100, 200]),
|
||||||
("100;200", [100, 200]),
|
("100;200", [100, 200]),
|
||||||
(u"100x200", [100, 200]),
|
|
||||||
(b"100x200", [100, 200]),
|
(b"100x200", [100, 200]),
|
||||||
([100, 200], [100, 200]),
|
([100, 200], [100, 200]),
|
||||||
],
|
],
|
||||||
|
|
|
@ -8,56 +8,56 @@ from yoga.model import helpers
|
||||||
class Test_model_helpers(object):
|
class Test_model_helpers(object):
|
||||||
def test_normalize_path(self):
|
def test_normalize_path(self):
|
||||||
assert (
|
assert (
|
||||||
helpers.normalize_path(u"images/texture.png")
|
helpers.normalize_path("images/texture.png")
|
||||||
== "images/texture.png"
|
== "images/texture.png"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
helpers.normalize_path(u"./images/texture.png")
|
helpers.normalize_path("./images/texture.png")
|
||||||
== "images/texture.png"
|
== "images/texture.png"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
helpers.normalize_path(u".\\images\\texture.png")
|
helpers.normalize_path(".\\images\\texture.png")
|
||||||
== "images/texture.png"
|
== "images/texture.png"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
helpers.normalize_path(u"./images\\texture.png")
|
helpers.normalize_path("./images\\texture.png")
|
||||||
== "images/texture.png"
|
== "images/texture.png"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
helpers.normalize_path(u".\\images/texture.png")
|
helpers.normalize_path(".\\images/texture.png")
|
||||||
== "images/texture.png"
|
== "images/texture.png"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
helpers.normalize_path(u"../images/texture.png")
|
helpers.normalize_path("../images/texture.png")
|
||||||
== "images/texture.png"
|
== "images/texture.png"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
helpers.normalize_path(u"..\\images\\texture.png")
|
helpers.normalize_path("..\\images\\texture.png")
|
||||||
== "images/texture.png"
|
== "images/texture.png"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
helpers.normalize_path(u"./images/subfolder/../texture.png")
|
helpers.normalize_path("./images/subfolder/../texture.png")
|
||||||
== "images/texture.png"
|
== "images/texture.png"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
helpers.normalize_path(u"./images/sub1\\sub2/../../texture.png")
|
helpers.normalize_path("./images/sub1\\sub2/../../texture.png")
|
||||||
== "images/texture.png"
|
== "images/texture.png"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
helpers.normalize_path(u"./images/texture.png")
|
helpers.normalize_path("./images/texture.png")
|
||||||
== "images/texture.png"
|
== "images/texture.png"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
helpers.normalize_path(u"/images/texture.png")
|
helpers.normalize_path("/images/texture.png")
|
||||||
== "images/texture.png"
|
== "images/texture.png"
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
helpers.normalize_path(u"C:\\images\\texture.png")
|
helpers.normalize_path("C:\\images\\texture.png")
|
||||||
== "images/texture.png"
|
== "images/texture.png"
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (
|
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"
|
== "some_valid-caracteres of files.png"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ def optimize(input_file, output_file, options={}, verbose=False, quiet=False):
|
||||||
options = normalize_options(options)
|
options = normalize_options(options)
|
||||||
|
|
||||||
# Image as file-like object
|
# 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")
|
image_file = open(input_file, "rb")
|
||||||
elif hasattr(input_file, "read") and hasattr(input_file, "seek"):
|
elif hasattr(input_file, "read") and hasattr(input_file, "seek"):
|
||||||
image_file = input_file
|
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)
|
output_file.write(output_image_bytes)
|
||||||
|
|
||||||
# Close input file if we opened it
|
# Close input file if we opened it
|
||||||
if type(input_file) in (str, type(u"")):
|
if type(input_file) is str:
|
||||||
image_file.close()
|
image_file.close()
|
||||||
|
|
|
@ -52,7 +52,7 @@ def normalize_options(options=None):
|
||||||
if type(value) == bytes:
|
if type(value) == bytes:
|
||||||
value = value.decode()
|
value = value.decode()
|
||||||
|
|
||||||
if type(value) in (str, type(u"")):
|
if type(value) in (str, bytes):
|
||||||
value = value.lower()
|
value = value.lower()
|
||||||
|
|
||||||
if value.isdigit():
|
if value.isdigit():
|
||||||
|
@ -77,7 +77,7 @@ def normalize_options(options=None):
|
||||||
if "jpeg_quality" in options:
|
if "jpeg_quality" in options:
|
||||||
value = options["jpeg_quality"]
|
value = options["jpeg_quality"]
|
||||||
|
|
||||||
if type(value) in (str, type(u""), bytes):
|
if type(value) in (str, bytes):
|
||||||
value = float(value)
|
value = float(value)
|
||||||
|
|
||||||
if value > 1:
|
if value > 1:
|
||||||
|
@ -94,7 +94,7 @@ def normalize_options(options=None):
|
||||||
if "webp_quality" in options:
|
if "webp_quality" in options:
|
||||||
value = options["webp_quality"]
|
value = options["webp_quality"]
|
||||||
|
|
||||||
if type(value) in (str, type(u""), bytes):
|
if type(value) in (str, bytes):
|
||||||
value = float(value)
|
value = float(value)
|
||||||
|
|
||||||
if value > 1:
|
if value > 1:
|
||||||
|
@ -111,7 +111,7 @@ def normalize_options(options=None):
|
||||||
if "opacity_threshold" in options:
|
if "opacity_threshold" in options:
|
||||||
value = options["opacity_threshold"]
|
value = options["opacity_threshold"]
|
||||||
|
|
||||||
if type(value) in (str, type(u""), bytes):
|
if type(value) in (str, bytes):
|
||||||
value = float(value)
|
value = float(value)
|
||||||
|
|
||||||
if value < 1:
|
if value < 1:
|
||||||
|
|
Loading…
Reference in New Issue