Compare commits

...

22 Commits

Author SHA1 Message Date
9b6097373e Another attempt 2022-04-10 22:03:17 -07:00
b954ac6ccc Attempt to hint to cmake what python install to use correctly
Should fix my linux building issue?
2022-04-10 21:51:18 -07:00
593a0c3f46 Fix windows test command and install fat binaries for libomp 2022-04-10 21:08:07 -07:00
3b73bc8bce use Py_ssize_t to make msvc happy 2022-04-10 01:06:25 -07:00
abeb08fc81 Upgrade cibuildwheel to 2.4.0 2022-04-10 00:26:00 -07:00
77637f6abd Run tests in the right directory and skip linux for now 2022-04-10 00:22:13 -07:00
df6d5b1848 Use latest setuptools instead of pinning it 2022-04-10 00:09:44 -07:00
b5aea803d5 Use relative imports in tests 2022-04-10 00:04:08 -07:00
b80a6d2229 Fix arch selection and test command 2022-04-09 23:15:23 -07:00
dac7f07db4 Build for musl linux for platforms supported by Pillow
Specifically x64 for cpython 3.8-3.10
2022-04-09 22:54:06 -07:00
7dfefa3007 Skip musl linux wheel builds
Pillow appears to fail to compile on these without installing a bunch of dependencies, so... sorry alpine users
2022-04-09 22:40:05 -07:00
eaca455a08 syntax error 2022-04-09 22:24:35 -07:00
e5ccdbb4f4 Don't try to download test images 2022-04-09 22:23:00 -07:00
94d88c7e00 Remove nose dependence
Also move test images into the base repo because they're not very big anyways
2022-04-09 22:20:09 -07:00
9421a6d372 Merge branch 'main' into build-modernization 2022-04-09 20:39:43 -07:00
654b6d628a Slightly modernize how project is compiled 2022-04-09 19:43:40 -07:00
421876ab0f Move more metadata to pyproject.toml 2022-04-03 20:41:02 -07:00
29590e0323 Move a good chunk of metadata to pyproject.toml 2022-04-03 16:22:47 -07:00
71379b7ae1 Revert to manylinux2014 2022-04-03 00:05:35 -07:00
d1346ca11d Enable macos cross-compiling in setup.py 2022-04-02 21:39:14 -07:00
e488dbcbff Fix builder version
and here I was thinking this was semver smh
2022-04-01 21:07:57 -07:00
1f7b45aa57 Compile for multiple architectures 2022-04-01 21:06:51 -07:00
32 changed files with 156 additions and 129 deletions

View File

@ -49,7 +49,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
os: [ macos-11, windows-latest, ubuntu-latest ]
steps:
- uses: actions/checkout@v3
@ -61,20 +61,29 @@ jobs:
- name: Install libomp
if: runner.os == 'macOS'
# openMP isnt part of core apple clang for some reason?
run: brew install libomp
# libomp is in homebrew, which works for end users but its not a fat binary
# so we have to install it manually
# compiled dylibs courtesy of https://mac.r-project.org/openmp/ and mirrored on my own server
run: |
wget https://pileof.rocks/openmp-13.0.0-darwin21-Release.tar.gz
sudo tar fvxz openmp-*.tar.gz -C /
- name: Install test images
run: git clone https://git.pileof.rocks/drewcassidy/quicktex-test-images.git tests/images
- name: Install QEMU
# install QEMU if building for arm linux
uses: docker/setup-qemu-action@v1
if: runner.os == 'Linux'
with:
platforms: arm64
- name: Build wheels
uses: joerick/cibuildwheel@v1.11.0
uses: pypa/cibuildwheel@v2.4.0
env:
# these options are all specific to running in the CI. other options are in pyproject.toml
MACOSX_DEPLOYMENT_TARGET: "10.15"
CIBW_BUILD: "cp{37,38,39,310}-*"
CIBW_SKIP: "*-win32 *-manylinux_i686"
CIBW_MANYLINUX_X86_64_IMAGE: "manylinux2014"
CIBW_TEST_EXTRAS: "tests"
CIBW_TEST_COMMAND: nosetests {project}/tests -d
CIBW_ARCHS_MACOS: "x86_64 universal2"
CIBW_ARCHS_LINUX: "x86_64 aarch64"
CIBW_ARCHS_WINDOWS: "auto64"
CIBW_TEST_SKIP: "*-macosx_arm64 *-macosx_universal2:arm64"
- name: Upload Wheels
uses: actions/upload-artifact@v2
@ -83,7 +92,7 @@ jobs:
publish:
name: Publish to PyPI and Github
needs: [build-wheels, build-sdist]
needs: [ build-wheels, build-sdist ]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest

3
.gitignore vendored
View File

@ -12,9 +12,6 @@ docs/_build/
#mypy
out
# Test images
tests/images/
# IDEs
**/.idea

4
.gitmodules vendored
View File

@ -1,4 +0,0 @@
[submodule "extern/pybind11"]
path = extern/pybind11
url = https://github.com/pybind/pybind11.git
branch = stable

View File

@ -1,13 +1,13 @@
cmake_minimum_required(VERSION 3.17)
cmake_minimum_required(VERSION 3.18)
include(CheckIPOSupported)
include(tools/CompilerWarnings.cmake)
project(quicktex)
# Find dependencies
find_package(Python COMPONENTS Interpreter Development)
find_package(Python COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)
find_package(OpenMP)
add_subdirectory(extern/pybind11)
# Collect source files
file(GLOB SOURCE_FILES

View File

@ -1 +0,0 @@
graft extern

1
extern/pybind11 vendored

@ -1 +0,0 @@
Subproject commit 8de7772cc72daca8e947b79b83fea46214931604

View File

@ -1,11 +1,69 @@
[build-system]
requires = [
"setuptools>=42",
"setuptools>=61",
"setuptools_scm>=6.2",
"wheel",
"cmake>=3.18",
"pybind11~=2.6.1",
"ninja; sys_platform != 'win32'",
"cmake>=3.12",
"setuptools_scm[toml]>=3.4"
]
build-backend = "setuptools.build_meta"
[project]
name = "quicktex"
description = "A fast block compression library for python"
readme = "README.md"
license = { file = "LICENSE.md" }
authors = [{ name = "Andrew Cassidy", email = "drewcassidy@me.com" }]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: C++",
]
requires-python = ">=3.7"
dependencies = ["Pillow", "click"]
dynamic = ["version"]
[project.optional-dependencies]
tests = ["parameterized"]
docs = ["sphinx", "myst-parser", "sphinx-rtd-theme"]
stubs = ["pybind11-stubgen"]
[project.urls]
Source = "https://github.com/drewcassidy/quicktex"
Changelog = "https://github.com/drewcassidy/quicktex/blob/main/CHANGELOG.md"
[project.scripts]
quicktex = "quicktex.__main__:main"
[tool.setuptools]
zip-safe = false
packages = { find = { include = ["quicktex*"] } } # only include quicktex and not tests
package-data = { '*' = ['py.typed', '*.pyi'] } # include stubs
package-dir = { '' = '.' } # without this line, C++ source files get included in the bdist
[tool.cibuildwheel]
build = "cp{37,38,39,31*}-*"
skip = ["*cp37-musllinux*", "*musllinux_aarch64*", "cp{38,39,31*}-macosx_x86_64"]
build-frontend = "build"
test-command = "cd {project} && python -m unittest --verbose"
test-extras = ["tests"]
manylinux-x86_64-image = "manylinux2014"
manylinux-aarch64-image = "manylinux2014"
[tool.cibuildwheel.windows]
test-command = "cd /d {project} && python -m unittest --verbose"
[tool.setuptools_scm]

View File

@ -96,9 +96,9 @@ template <typename T> T BufferToTexture(py::buffer buf, int width, int height) {
auto dst_size = output.NBytes();
if (info.format != py::format_descriptor<uint8_t>::format()) throw std::runtime_error("Incompatible format in python buffer: expected a byte array.");
if (info.size < (ssize_t)dst_size) std::runtime_error("Incompatible format in python buffer: Input data is smaller than texture size.");
if (info.size < (Py_ssize_t)dst_size) std::runtime_error("Incompatible format in python buffer: Input data is smaller than texture size.");
if (info.ndim == 1) {
if (info.shape[0] < (ssize_t)dst_size) throw std::runtime_error("Incompatible format in python buffer: 1-D buffer has incorrect length.");
if (info.shape[0] < (Py_ssize_t)dst_size) throw std::runtime_error("Incompatible format in python buffer: 1-D buffer has incorrect length.");
if (info.strides[0] != 1) throw std::runtime_error("Incompatible format in python buffer: 1-D buffer is not contiguous.");
} else {
throw std::runtime_error("Incompatible format in python buffer: Incorrect number of dimensions.");
@ -115,9 +115,9 @@ template <typename T> T BufferToPOD(py::buffer buf) {
auto info = buf.request(false);
if (info.format != py::format_descriptor<uint8_t>::format()) throw std::runtime_error("Incompatible format in python buffer: expected a byte array.");
if (info.size < (ssize_t)sizeof(T)) std::runtime_error("Incompatible format in python buffer: Input data is smaller than texture size.");
if (info.size < (Py_ssize_t)sizeof(T)) std::runtime_error("Incompatible format in python buffer: Input data is smaller than texture size.");
if (info.ndim == 1) {
if (info.shape[0] < (ssize_t)sizeof(T)) throw std::runtime_error("Incompatible format in python buffer: 1-D buffer has incorrect length.");
if (info.shape[0] < (Py_ssize_t)sizeof(T)) throw std::runtime_error("Incompatible format in python buffer: 1-D buffer has incorrect length.");
if (info.strides[0] != 1) throw std::runtime_error("Incompatible format in python buffer: 1-D buffer is not contiguous.");
} else {
throw std::runtime_error("Incompatible format in python buffer: Incorrect number of dimensions.");

View File

@ -1,16 +1,14 @@
import os
import re
import sys
import glob
import subprocess
import pybind11
from setuptools import setup, Extension, find_packages
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
project_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(project_path, 'README.md')) as f:
readme = f.read()
# A CMakeExtension needs a sourcedir instead of a file list.
# The name must be the _single_ output extension from the CMake build.
@ -41,9 +39,13 @@ class CMakeBuild(build_ext):
# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
cmake_args = [
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}".format(extdir),
"-Dpybind11_DIR={}".format(pybind11.get_cmake_dir()),
"-DPython_EXECUTABLE={}".format(sys.executable),
"-DPython_ROOT_DIR={}".format(os.path.dirname(sys.executable)),
"-DQUICKTEX_VERSION_INFO={}".format(version),
"-DCMAKE_BUILD_TYPE={}".format(cfg), # not used on MSVC, but no harm
# clear cached make program binary, see https://github.com/pypa/setuptools/issues/2912
"-U", "CMAKE_MAKE_PROGRAM",
]
build_args = []
@ -84,6 +86,12 @@ class CMakeBuild(build_ext):
]
build_args += ["--config", cfg]
if sys.platform.startswith("darwin"):
# Cross-compile support for macOS - respect ARCHFLAGS if set
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
if archs:
cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]
# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
# across all generators.
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
@ -104,50 +112,10 @@ class CMakeBuild(build_ext):
)
# Find stub files
stubs = [path.replace('quicktex/', '') for path in glob.glob('quicktex/**/*.pyi', recursive=True)]
# The information here can also be placed in setup.cfg - better separation of
# logic and declaration, and simpler if you include description/version in a file.
setup(
name="quicktex",
use_scm_version=True,
author="Andrew Cassidy",
author_email="drewcassidy@me.com",
description="A fast block compression library for python",
url='https://github.com/drewcassidy/quicktex',
long_description=readme,
long_description_content_type='text/markdown',
python_requires=">=3.7",
ext_modules=[CMakeExtension("_quicktex")],
cmdclass={"build_ext": CMakeBuild},
packages=find_packages(where='.', include=['quicktex*']),
package_dir={'': '.'},
package_data={'': ['py.typed'] + stubs},
include_package_data=True,
install_requires=["Pillow", "click"],
extras_require={
"tests": ["nose", "parameterized"],
"docs": ["sphinx", "myst-parser", "sphinx-rtd-theme"],
"stubs": ["pybind11-stubgen"],
},
entry_points={
'console_scripts': ['quicktex = quicktex.__main__:main']
},
zip_safe=False,
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: C++'
],
)

View File

@ -1,9 +1,3 @@
import os.path
# Some checks to run before tests can begin
images_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'images')
assert os.path.isdir(images_path), 'test images repo not present'
assert os.path.isfile(os.path.join(images_path, '__init__.py')), 'images __init__.py not present, is the test image repo present?'
bp_size = os.path.getsize(os.path.join(images_path, 'Boilerplate.png'))
assert bp_size == 955989, 'Boilerplate.png is the wrong size, is the test image repo checked out with LFS enabled?'

Binary file not shown.

After

Width:  |  Height:  |  Size: 934 KiB

BIN
tests/images/Bun.afdesign Normal file

Binary file not shown.

BIN
tests/images/Bun.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 KiB

32
tests/images/__init__.py Normal file
View File

@ -0,0 +1,32 @@
from PIL import Image
from quicktex.s3tc.bc1 import BC1Block
from quicktex.s3tc.bc4 import BC4Block
from quicktex import RawTexture
import os.path
image_path = os.path.dirname(os.path.realpath(__file__))
class BC1Blocks:
class Entry:
def __init__(self, filename, block):
path = os.path.join(image_path, 'bc1', filename)
self.image = Image.open(path).convert('RGBA')
self.texture = RawTexture.frombytes(self.image.tobytes('raw', 'RGBA'), *self.image.size)
self.block = block
greyscale = Entry('greyscale_unpacked.png', BC1Block.frombytes(b'\xFF\xFF\x49\x4A\x78\x78\x78\x78'))
three_color = Entry('3color_unpacked.png', BC1Block.frombytes(b'\xE0\x07\x00\xF8\x29\x29\x29\x29'))
three_color_black = Entry('3color_black_unpacked.png', BC1Block.frombytes(b'\xE0\x07\x00\xF8\x27\x27\x27\x27'))
class BC4Blocks:
class Entry:
def __init__(self, filename, block):
path = os.path.join(image_path, 'bc4', filename)
self.image = Image.open(path).convert('RGBA')
self.texture = RawTexture.frombytes(self.image.tobytes('raw', 'RGBA'), *self.image.size)
self.block = block
six_value = Entry('6value.png', BC4Block(8, 248, [[0, 1, 2, 3]] * 2 + [[4, 5, 6, 7]] * 2))
eight_value = Entry('8value.png', BC4Block(240, 16, [[0, 1, 2, 3]] * 2 + [[4, 5, 6, 7]] * 2))

BIN
tests/images/bc1/3color.dds Normal file

Binary file not shown.

BIN
tests/images/bc1/3color.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 B

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 B

BIN
tests/images/bc4/6value.dds Normal file

Binary file not shown.

BIN
tests/images/bc4/6value.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 B

BIN
tests/images/bc4/8value.dds Normal file

Binary file not shown.

BIN
tests/images/bc4/8value.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B

Binary file not shown.

View File

@ -1,10 +1,7 @@
import unittest
import nose
import os.path
from parameterized import parameterized, parameterized_class
import quicktex
from quicktex.s3tc.bc1 import BC1Block, BC1Texture, BC1Encoder, BC1Decoder
from tests.images import BC1Blocks, image_path
from .images import BC1Blocks
from PIL import Image, ImageChops
in_endpoints = ((253, 254, 255), (65, 70, 67)) # has some small changes that should encode the same
@ -108,9 +105,9 @@ class TestBC1Texture(unittest.TestCase):
self.assertEqual(self.tex[-1, -1], self.tex[self.wb - 1, self.hb - 1], 'incorrect negative subscripting')
with self.assertRaises(IndexError):
thing = self.tex[self.wb, self.hb]
_ = self.tex[self.wb, self.hb]
with self.assertRaises(IndexError):
thing = self.tex[-1 - self.wb, -1 - self.hb]
_ = self.tex[-1 - self.wb, -1 - self.hb]
def test_buffer(self):
"""Test the buffer protocol of BC1Texture"""
@ -158,7 +155,8 @@ class TestBC1Encoder(unittest.TestCase):
out_block = out_tex[0, 0]
if self.color_mode != BC1Encoder.ColorMode.FourColor: # we only care about the selectors if we are in 3 color mode
if self.color_mode != BC1Encoder.ColorMode.FourColor:
# we only care about the selectors if we are in 3 color mode
self.assertTrue(out_block.is_3color, 'returned 4-color block for 3 color test block')
self.assertEqual(out_block, BC1Blocks.three_color.block, 'encoded block is incorrect')
else:
@ -173,7 +171,8 @@ class TestBC1Encoder(unittest.TestCase):
out_block = out_tex[0, 0]
has_black = 3 in [j for row in out_block.selectors for j in row]
if self.color_mode == BC1Encoder.ColorMode.ThreeColorBlack: # we only care about the selectors if we are in 3 color black mode
if self.color_mode == BC1Encoder.ColorMode.ThreeColorBlack:
# we only care about the selectors if we are in 3 color black mode
self.assertTrue(out_block.is_3color, 'returned 4-color block for 3 color test block with black')
self.assertTrue(has_black, 'block does not have black pixels as expected')
self.assertEqual(out_block, BC1Blocks.three_color_black.block, "encoded block is incorrect")
@ -207,7 +206,3 @@ class TestBC1Decoder(unittest.TestCase):
img_diff = ImageChops.difference(out_img, image).convert('L')
img_hist = img_diff.histogram()
self.assertEqual(16, img_hist[0], 'decoded block is incorrect')
if __name__ == '__main__':
nose.main()

View File

@ -1,13 +1,9 @@
import unittest
import nose
from parameterized import parameterized, parameterized_class
from quicktex.s3tc.bc4 import BC4Block, BC4Texture, BC4Encoder, BC4Decoder
from tests.images import BC4Blocks
from .images import BC4Blocks
from PIL import Image, ImageChops
if __name__ == '__main__':
nose.main()
class TestBC4Block(unittest.TestCase):
"""Tests for the BC1Block class"""
@ -119,9 +115,9 @@ class TestBC4Texture(unittest.TestCase):
self.assertEqual(self.tex[-1, -1], self.tex[self.wb - 1, self.hb - 1], 'incorrect negative subscripting')
with self.assertRaises(IndexError):
thing = self.tex[self.wb, self.hb]
_ = self.tex[self.wb, self.hb]
with self.assertRaises(IndexError):
thing = self.tex[-1 - self.wb, -1 - self.hb]
_ = self.tex[-1 - self.wb, -1 - self.hb]
def test_buffer(self):
"""Test the buffer protocol of BC4Texture"""

View File

@ -3,32 +3,21 @@
import unittest
import os.path
import quicktex
import nose
tests_path = os.path.dirname(os.path.realpath(__file__))
def test_images():
"""Test for the images submodule"""
class TestInstall(unittest.TestCase):
def test_version(self):
"""Test if the extension module version matches what setuptools returns"""
try:
from importlib import metadata
except ImportError:
# Python < 3.8, so we cant get the metadata, so just check if it exists
assert quicktex.__version__
print(f'Cannot check version in python < 3.8. __version__ is {quicktex.__version__}')
return
images_path = os.path.join(tests_path, 'images')
version = metadata.version('quicktex')
assert os.path.isdir(images_path), 'test images repo not present. run "git clone https://git.pileof.rocks/drewcassidy/quicktex-test-images.git tests/images" to download them'
assert os.path.isfile(os.path.join(images_path, '__init__.py')), 'images __init__.py not present, is the test image repo present?'
bp_size = os.path.getsize(os.path.join(images_path, 'Boilerplate.png'))
assert bp_size == 955989, 'Boilerplate.png is the wrong size, is the test image repo checked out with LFS enabled?'
def test_version():
"""Test if the extension module version matches what setuptools returns"""
try:
from importlib import metadata
except ImportError:
# Python < 3.8, so we cant get the metadata, so just check if it exists
assert quicktex.__version__
print(f'Cannot check version in python < 3.8. __version__ is {quicktex.__version__}')
return
version = metadata.version('quicktex')
assert version == quicktex.__version__, 'incorrect version string from extension module'
assert version == quicktex.__version__, 'incorrect version string from extension module'

View File

@ -1,7 +1,6 @@
import unittest
import nose
import os.path
from tests.images import image_path
from .images import image_path
from quicktex import RawTexture
from PIL import Image
@ -57,7 +56,3 @@ class TestRawTexture(unittest.TestCase):
"""Test the frombytes factory function"""
bytetex = RawTexture.frombytes(self.boilerplate_bytes, *self.boilerplate.size)
self.assertEqual(self.boilerplate_bytes, bytetex.tobytes(), 'Incorrect bytes after writing to buffer')
if __name__ == '__main__':
nose.main()