Skip to content

Commit

Permalink
Don't include openjpeg source in wheels (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaramallion authored Jan 5, 2024
1 parent e3c8c16 commit 5150b74
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 272 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/pytest-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ jobs:
- name: Run pytest
run: |
pytest --cov openjpeg --ignore=openjpeg/src/openjpeg
pytest --cov openjpeg openjpeg/tests
- name: Install pydicom release and rerun pytest
run: |
pip install pydicom pylibjpeg
pytest --cov openjpeg --ignore=openjpeg/src/openjpeg
pytest --cov openjpeg openjpeg/tests
osx:
runs-on: macos-latest
Expand Down Expand Up @@ -69,12 +69,12 @@ jobs:
- name: Run pytest
run: |
pytest --cov openjpeg --ignore=openjpeg/src/openjpeg
pytest --cov openjpeg openjpeg/tests
- name: Install pydicom release and rerun pytest
run: |
pip install pydicom pylibjpeg
pytest --cov openjpeg --ignore=openjpeg/src/openjpeg
pytest --cov openjpeg openjpeg/tests
ubuntu:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -103,19 +103,19 @@ jobs:
- name: Run pytest
run: |
pytest --cov openjpeg --ignore=openjpeg/src/openjpeg
pytest --cov openjpeg openjpeg/tests
- name: Install pydicom release and rerun pytest
run: |
pip install pydicom pylibjpeg
pytest --cov openjpeg --ignore=openjpeg/src/openjpeg
pytest --cov openjpeg openjpeg/tests
- name: Switch to pydicom dev and rerun pytest (3.10+)
if: ${{ contains('3.10 3.11 3.12', matrix.python-version) }}
run: |
pip uninstall -y pydicom
pip install git+https://github.com/pydicom/pydicom
pytest --cov openjpeg --ignore=openjpeg/src/openjpeg
pytest --cov openjpeg openjpeg/tests
- name: Send coverage results
if: ${{ success() && matrix.coverage == 'coverage' }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Store artifacts
uses: actions/upload-artifact@v4
with:
name: wheels
name: sdist
path: ./dist

build-wheels:
Expand Down Expand Up @@ -184,7 +184,7 @@ jobs:
- name: Store artifacts
uses: actions/upload-artifact@v4
with:
name: wheels
name: wheel-${{ matrix.python }}-${{ matrix.platform_id }}
path: ./dist

test-package:
Expand All @@ -206,8 +206,8 @@ jobs:
- name: Download the wheels
uses: actions/download-artifact@v4
with:
name: wheels
path: dist/
merge-multiple: true

- name: Install from package wheels and test
run: |
Expand Down
7 changes: 4 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "openjpeg/src/openjpeg"]
path = openjpeg/src/openjpeg
url = https://github.com/uclouvain/openjpeg.git

[submodule "lib/openjpeg"]
path = lib/openjpeg
url = https://github.com/uclouvain/openjpeg
11 changes: 0 additions & 11 deletions MANIFEST.in

This file was deleted.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ python -m pip install pylibjpeg-openjpeg
| ISO/IEC Standard | ITU Equivalent | JPEG Format |
| --- | --- | --- |
| [15444-1](https://www.iso.org/standard/78321.html) | [T.800](https://www.itu.int/rec/T-REC-T.800/en) | [JPEG 2000](https://jpeg.org/jpeg2000/) |
| [15444-1](https://www.iso.org/standard/78321.html) | [T.800](https://www.itu.int/rec/T-REC-T.800/en) | [High-Throughput JPEG 2000](https://jpeg.org/jpeg2000/) |

#### Encoding
Encoding of JPEG 2000 images is not currently supported
Expand All @@ -46,6 +47,9 @@ Encoding of JPEG 2000 images is not currently supported
| --- | --- |
| 1.2.840.10008.1.2.4.90 | JPEG 2000 Image Compression (Lossless Only) |
| 1.2.840.10008.1.2.4.91 | JPEG 2000 Image Compression |
| 1.2.840.10008.1.2.4.201 | High-Throughput JPEG 2000 Image Compression (Lossless Only) |
| 1.2.840.10008.1.2.4.202 | High-Throughput JPEG 2000 with RPCL Options Image Compression (Lossless Only) |
| 1.2.840.10008.1.2.4.203 | High-Throughput JPEG 2000 Image Compression |


### Usage
Expand Down
69 changes: 32 additions & 37 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@


PACKAGE_DIR = Path(__file__).parent / "openjpeg"
BUILD_TOOLS = PACKAGE_DIR.parent / "build_tools"
OPENJPEG_SRC = PACKAGE_DIR / "src" / "openjpeg" / "src" / "lib" / "openjp2"
INTERFACE_SRC = PACKAGE_DIR / "src" / "interface"
LIB_DIR = Path(__file__).parent / "lib"
BUILD_TOOLS = Path(__file__).parent / "build_tools"
OPENJPEG_SRC = LIB_DIR / "openjpeg" / "src" / "lib" / "openjp2"
INTERFACE_SRC = LIB_DIR / "interface"
BUILD_DIR = LIB_DIR / "openjpeg" / "build"
BACKUP_DIR = BUILD_TOOLS / "backup"


def build(setup_kwargs: Any) -> Any:
Expand Down Expand Up @@ -72,37 +75,36 @@ def get_source_files() -> List[Path]:
if fname.suffix == ".c":
source_files.append(fname)

source_files = [p.relative_to(PACKAGE_DIR.parent) for p in source_files]
source_files.insert(0, Path("openjpeg/_openjpeg.pyx"))
source_files = [p.relative_to(Path(__file__).parent) for p in source_files]
source_files.insert(0, PACKAGE_DIR / "_openjpeg.pyx")

return source_files


def setup_oj() -> None:
"""Run custom cmake."""
base_dir = PACKAGE_DIR / "src" / "openjpeg"
base_dir = LIB_DIR / "openjpeg"
p_openjpeg = base_dir / "src" / "lib" / "openjp2" / "openjpeg.c"

# Backup original CMakeLists.txt and openjpeg.c files
backup_dir = BUILD_TOOLS / "backup"
if os.path.exists(backup_dir):
shutil.rmtree(backup_dir)
if os.path.exists(BACKUP_DIR):
shutil.rmtree(BACKUP_DIR)

backup_dir.mkdir(exist_ok=True, parents=True)
BACKUP_DIR.mkdir(exist_ok=True, parents=True)

shutil.copy(
base_dir / "CMakeLists.txt",
backup_dir / "CMakeLists.txt.backup",
LIB_DIR / "openjpeg" / "CMakeLists.txt",
BACKUP_DIR / "CMakeLists.txt.backup",
)
shutil.copy(
p_openjpeg,
backup_dir / "openjpeg.c.backup",
OPENJPEG_SRC / "openjpeg.c",
BACKUP_DIR / "openjpeg.c.backup",
)

# Copy custom CMakeLists.txt file to openjpeg base dir
shutil.copy(
BUILD_TOOLS / "cmake" / "CMakeLists.txt",
base_dir,
LIB_DIR / "openjpeg" / "CMakeLists.txt",
)
# Edit openjpeg.c to remove the OPJ_API declaration
with p_openjpeg.open("r") as f:
Expand All @@ -115,21 +117,19 @@ def setup_oj() -> None:
with p_openjpeg.open("w") as f:
f.write("".join(data))

build_dir = base_dir / "build"
if os.path.exists(build_dir):
shutil.rmtree(build_dir)
if os.path.exists(BUILD_DIR):
shutil.rmtree(BUILD_DIR)

try:
os.remove(INTERFACE_SRC / "opj_config.h")
os.remove(INTERFACE_SRC / "opj_config_private.h")
except:
pass

os.mkdir(build_dir)
fpath = os.path.abspath(base_dir)
os.mkdir(BUILD_DIR)
cur_dir = os.getcwd()
os.chdir(build_dir)
subprocess.call(['cmake', fpath])
os.chdir(BUILD_DIR)
subprocess.call(['cmake', os.fspath((LIB_DIR / "openjpeg").resolve(strict=True))])
os.chdir(cur_dir)

# Turn off JPIP
Expand All @@ -142,26 +142,21 @@ def setup_oj() -> None:
def reset_oj() -> None:
# Restore submodule to original state
# Restore CMakeLists.txt and openjpeg.c files
base_dir = PACKAGE_DIR / "src" / "openjpeg"
build_dir = base_dir / "build"
backup_dir = BUILD_TOOLS / "backup"
p_openjpeg = base_dir / "src" / "lib" / "openjp2" / "openjpeg.c"

if (backup_dir / "CMakeLists.txt.backup").exists():
if (BACKUP_DIR / "CMakeLists.txt.backup").exists():
shutil.copy(
backup_dir / "CMakeLists.txt.backup",
base_dir / "CMakeLists.txt",
BACKUP_DIR / "CMakeLists.txt.backup",
LIB_DIR / "openjpeg" / "CMakeLists.txt",
)

if (backup_dir / "openjpeg.c.backup").exists():
if (BACKUP_DIR / "openjpeg.c.backup").exists():
shutil.copy(
BUILD_TOOLS / "backup" / "openjpeg.c.backup",
p_openjpeg,
BACKUP_DIR / "openjpeg.c.backup",
OPENJPEG_SRC / "openjpeg.c",
)

# Cleanup added directories
if os.path.exists(build_dir):
shutil.rmtree(build_dir)
if os.path.exists(BUILD_DIR):
shutil.rmtree(BUILD_DIR)

if os.path.exists(backup_dir):
shutil.rmtree(backup_dir)
if os.path.exists(BACKUP_DIR):
shutil.rmtree(BACKUP_DIR)
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 5150b74

Please sign in to comment.