Skip to content

Commit ec5d76e

Browse files
authored
Merge pull request #3 from ramonaoptics/test_windows
Try to fixup windows failures
2 parents 1b94abb + ed44e88 commit ec5d76e

File tree

6 files changed

+58
-30
lines changed

6 files changed

+58
-30
lines changed

.github/workflows/tests.yml

+25-20
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ jobs:
1717
include:
1818
- os: "ubuntu-latest"
1919
installer-url: "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh"
20+
python-version: "3.13"
21+
- os: "ubuntu-latest"
22+
installer-url: "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh"
23+
python-version: "3.10"
2024
- os: "macos-latest"
2125
installer-url: "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-x86_64.sh"
22-
- os: "windows-latest"
23-
installer-url: "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Windows-x86_64.exe"
26+
python-version: "3.9"
27+
# - os: "windows-latest"
28+
# installer-url: "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Windows-x86_64.exe"
29+
# python-version: "3.12"
2430
max-parallel: 8
2531
fail-fast: false
2632

@@ -41,32 +47,31 @@ jobs:
4147
auto-update-conda: true
4248
installer-url: ${{ matrix.installer-url }}
4349
python-version: ${{ matrix.python-version }}
44-
- name: Conda info
50+
51+
- name: Install and Test Package (Unix)
52+
if: matrix.os != 'windows-latest'
4553
shell: bash -el {0}
4654
run: |
47-
conda config --remove channels defaults
48-
conda config --add channels mark.harfouche
4955
conda info
50-
- name: Conda list
51-
shell: pwsh
52-
run: |
5356
conda list
54-
55-
- name: Install dependencies
56-
shell: bash -el {0}
57-
run: |
5857
conda install compilers pybind11 numpy openjph setuptools pytest --yes
59-
60-
- name: Install package
61-
shell: bash -el {0}
62-
run: |
6358
export OJPH_GIT_DESCRIBE=${{ steps.ghd.outputs.describe }}
64-
python -m pip install -e . -vvv
59+
python -m pip install -e . -vvv --no-deps --no-build-isolation
60+
python --version
61+
pip check
62+
python -c "import ojph; print(ojph.__version__)"
63+
pytest
6564
66-
- name: Run tests
67-
shell: bash -el {0}
65+
- name: Install and Test Package (Windows)
66+
if: matrix.os == 'windows-latest'
67+
shell: pwsh
6868
run: |
69-
export OJPH_GIT_DESCRIBE=${{ steps.ghd.outputs.describe }}
69+
conda info
70+
conda list
71+
conda install --yes compilers pybind11 numpy openjph setuptools pytest git
72+
set "OJPH_GIT_DESCRIBE=${{ steps.ghd.outputs.describe }}"
73+
setx OJPH_GIT_DESCRIBE ${{ steps.ghd.outputs.describe }}
74+
python -m pip install -e . -vvv --no-deps --no-build-isolation
7075
python --version
7176
pip check
7277
python -c "import ojph; print(ojph.__version__)"

ojph/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from ._version import __version__
1+
from ._version import __version__ # noqa
22

33
from ._imwrite import imwrite
44
from ._imread import imread
55

6-
__all__ = ["imwrite", "imread"]
6+
__all__ = ["imwrite", "imread"]

ojph/_imread.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import numpy as np
32
import ctypes
43
from .ojph_bindings import J2CInfile, Codestream
@@ -19,13 +18,19 @@ def imread(uri, *, index=None, plugin=None, extension=None, format_hint=None, **
1918

2019

2120
class OJPHImageFile:
22-
def __init__(self, filename):
21+
def __init__(self, filename, *, mode='r'):
22+
if mode != 'r':
23+
raise ValueError(f"We only support mode = 'r' for now. Got {mode}.")
2324
self._codestream = None
2425
self._ojph_file = None
2526
self._filename = filename
2627

27-
self._ojph_file = J2CInfile()
28-
self._ojph_file.open(str(filename))
28+
ojph_file = J2CInfile()
29+
ojph_file.open(str(filename))
30+
# An exception can occur and if we call close in our destructor because
31+
# we think the file has been opened successfully then it breaks things
32+
# the C++ destructor will check if the filehandle is not None
33+
self._ojph_file = ojph_file
2934
self._codestream = Codestream()
3035
self._codestream.read_headers(self._ojph_file)
3136

@@ -52,6 +57,14 @@ def __init__(self, filename):
5257
else:
5358
raise ValueError("Unsupported bit depth")
5459

60+
@property
61+
def shape(self):
62+
return self._shape
63+
64+
@property
65+
def dtype(self):
66+
return self._dtype
67+
5568
def _open_file(self):
5669
self._ojph_file = J2CInfile()
5770
self._ojph_file.open(self._filename)
@@ -99,4 +112,4 @@ def _close_codestream_and_file(self):
99112
self._ojph_file = None
100113

101114
def __del__(self):
102-
self._close_codestream_and_file()
115+
self._close_codestream_and_file()

ojph/_imwrite.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def imwrite(filename, image):
3838
bit_depth = image.dtype.itemsize * 8
3939
# Is there a better way to detect signed dtypes???
4040
is_signed = image.dtype.kind != 'u'
41-
siz.set_num_components(num_components);
41+
siz.set_num_components(num_components)
4242
for i in range(num_components):
4343
# is it necessary to do this in a loop?
4444
siz.set_component(
@@ -75,7 +75,7 @@ def imwrite(filename, image):
7575
line_array[...] = image[i, :]
7676
else:
7777
line_array[...] = image[i, :, c]
78-
c_before = c
78+
# c_before = c
7979
line = codestream.exchange(line, c)
8080

8181
codestream.flush()

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def get_version_and_cmdclass(pkg_path):
6464
'License :: OSI Approved :: BSD License',
6565
'Operating System :: OS Independent',
6666
'Programming Language :: Python :: 3 :: Only',
67+
'Programming Language :: Python :: 3.9',
6768
'Programming Language :: Python :: 3.10',
6869
'Programming Language :: Python :: 3.11',
6970
'Programming Language :: Python :: 3.12',
@@ -72,7 +73,7 @@ def get_version_and_cmdclass(pkg_path):
7273
'Topic :: Software Development :: Libraries :: Python Modules',
7374
],
7475
packages=find_packages(exclude=["tests*"]),
75-
python_requires='>=3.10',
76+
python_requires='>=3.9',
7677
install_requires=[
7778
'numpy>=1.24.0',
7879
],

tests/test_imread_failures.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ojph import imread
2+
import pytest
3+
4+
5+
def test_imread_file_does_not_exist(tmp_path):
6+
# A double free can cause a segmentation fault. So make sure just an error
7+
# is raised and not a full interpreter shutdown.
8+
with pytest.raises(RuntimeError):
9+
imread(tmp_path / 'does_not_exist.j2c')

0 commit comments

Comments
 (0)