Skip to content
This repository was archived by the owner on Mar 10, 2023. It is now read-only.

Commit f6e6ffb

Browse files
committed
Better #1 handling. Auto tests.
1 parent 11e0858 commit f6e6ffb

File tree

4 files changed

+86
-10
lines changed

4 files changed

+86
-10
lines changed

.github/workflows/python-linux.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,35 @@ jobs:
1313
runs-on: ubuntu-20.04
1414
strategy:
1515
matrix:
16-
python-version: ['3.7', '3.8', '3.9']
16+
python-version: ['3.8', '3.9']
1717

1818
steps:
1919
- uses: actions/checkout@v2
20+
2021
- name: Set up Python ${{ matrix.python-version }}
2122
uses: actions/setup-python@v2
2223
with:
2324
python-version: ${{ matrix.python-version }}
25+
2426
- name: Install dependencies
2527
run: |
2628
python -m pip install --upgrade pip
27-
python -m pip install setuptools wheel twine flake8
29+
python -m pip install setuptools wheel twine flake8 pytest Pillow
2830
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
31+
2932
- name: Lint with flake8
3033
run: |
3134
# stop the build if there are Python syntax errors or undefined names
3235
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
3336
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
3437
flake8 . --count --exit-zero --max-complexity=15 --max-line-length=250 --statistics
3538
39+
- name: Install cjxl
40+
run: /bin/bash build_cjxl.sh
41+
42+
- name: Test
43+
run: pytest
44+
3645
- name: Build package
3746
run: python setup.py sdist bdist_wheel
3847

build_cjxl.sh

+16-4
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,32 @@ if [ "$EUID" -ne 0 ]
55
exit
66
fi
77

8-
DEBIAN_FRONTEND=noninteractive
8+
if [ $(grep -c avx2 /proc/cpuinfo) == 0 ]
9+
then echo "AVX2 support required"
10+
exit
11+
fi
12+
13+
set -ex
14+
15+
16+
export DEBIAN_FRONTEND=noninteractive
17+
18+
export RUSTFLAGS="-C target-feature=+avx2,+fma"
19+
export CFLAGS="-mavx2 -mfma -ftree-vectorize -pipe"
20+
21+
export CC=clang-7 CXX=clang++-7
922

1023
apt-get update
1124
apt-get -y install git wget ca-certificates cmake pkg-config libbrotli-dev libgif-dev libjpeg-dev libopenexr-dev libpng-dev libwebp-dev clang-7
12-
export CC=clang-7 CXX=clang++-7
1325

1426
cd /tmp/
1527
rm -rf jpeg-xl
16-
git clone https://gitlab.com/wg1/jpeg-xl.git --recursive
28+
git clone --recursive --depth=1 https://gitlab.com/wg1/jpeg-xl.git
1729
cd jpeg-xl
1830
rm -rf build
1931
mkdir build
2032
cd build
2133
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF ..
22-
cmake --build . -- -j
34+
cmake --build . -- -j$(nproc)
2335

2436
cp tools/cjxl /usr/bin/

makejxl.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
from shutil import which
88
from subprocess import run
99
from typing import Iterable
10-
import shlex
1110

1211
import click
1312

14-
__version__ = '0.1.2'
13+
__version__ = '0.1.4'
1514
SUPPORTED_FORMATS = ['jpeg', 'jpg', 'png', 'apng', 'gif', 'exr', 'ppm', 'pfm', 'pgx']
1615

1716

@@ -63,8 +62,8 @@ def main(directory, recursive=False, speed='kitten'):
6362
for filepath in search_files(str(directory), recursive=recursive):
6463
fp = pathlib.PurePath(filepath)
6564
newpath = fp.parent.joinpath(fp.stem + '.' + 'jxl')
66-
convert_cmd = f'cjxl --quiet -s {speed} --num_threads={jobs} {fp} {newpath}'
67-
conversion_return_code = run(shlex.split(convert_cmd)).returncode
65+
convert_cmd = ['cjxl', '--quiet', '-s', speed, f'--num_threads={jobs}', fp, newpath]
66+
conversion_return_code = run(convert_cmd).returncode
6867
if conversion_return_code == 0:
6968
saved = os.path.getsize(fp) - os.path.getsize(newpath)
7069
total += saved

test_main.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import os
2+
3+
from PIL import Image
4+
import tempfile
5+
from click.testing import CliRunner
6+
7+
from makejxl import main as conv
8+
9+
tempdir = tempfile.mkdtemp() + os.sep
10+
# tempdir = '/mnt/c/temp/2/'
11+
12+
n1 = tempdir + 'testimage1.jpg'
13+
n2 = tempdir + 'testimage with space.jpg'
14+
n3 = tempdir + 'testimage-with-dash.jpg'
15+
n4 = tempdir + 'testimage.with.dots.jpg'
16+
n5 = tempdir + 'файлик на кириллице.jpg'
17+
18+
r1 = tempdir + 'testimage1.jxl'
19+
r2 = tempdir + 'testimage with space.jxl'
20+
r3 = tempdir + 'testimage-with-dash.jxl'
21+
r4 = tempdir + 'testimage.with.dots.jxl'
22+
r5 = tempdir + 'файлик на кириллице.jxl'
23+
24+
# Generate test images
25+
img = Image.new('RGB', (1024, 1024), color='white')
26+
img.save(n1)
27+
img.save(n2)
28+
img.save(n3)
29+
img.save(n4)
30+
img.save(n5)
31+
32+
33+
def test_1():
34+
runner = CliRunner()
35+
result = runner.invoke(conv, tempdir)
36+
assert result.exit_code == 0
37+
38+
39+
def test_2():
40+
assert os.path.exists(r1)
41+
42+
43+
def test_3():
44+
assert os.path.exists(r2)
45+
46+
47+
def test_4():
48+
assert os.path.exists(r3)
49+
50+
51+
def test_5():
52+
assert os.path.exists(r4)
53+
54+
55+
def test_6():
56+
assert os.path.exists(r5)

0 commit comments

Comments
 (0)