Skip to content

Commit

Permalink
Switch to poetry and pyproject.toml (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaramallion authored Jan 3, 2024
1 parent bfb3362 commit 84c66fa
Show file tree
Hide file tree
Showing 13 changed files with 8,362 additions and 3,966 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/pytest-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: unit-tests

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:

jobs:
Expand All @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
arch: ['x64', 'x86']

steps:
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -110,7 +110,8 @@ jobs:
pip install pydicom pylibjpeg
pytest --cov openjpeg --ignore=openjpeg/src/openjpeg
- name: Switch to pydicom dev and rerun pytest
- 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
Expand Down
36 changes: 22 additions & 14 deletions .github/workflows/release-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ jobs:
- os: windows-latest
python: 311
platform_id: win32
- os: windows-latest
python: 312
platform_id: win32

# Windows 64 bit
- os: windows-latest
Expand All @@ -70,36 +73,33 @@ jobs:
- os: windows-latest
python: 311
platform_id: win_amd64
- os: windows-latest
python: 312
platform_id: win_amd64

# Linux 64 bit manylinux2010
# Linux 64 bit manylinux2014
- os: ubuntu-latest
python: 37
platform_id: manylinux_x86_64
manylinux_image: manylinux2010
manylinux_image: manylinux2014
- os: ubuntu-latest
python: 38
platform_id: manylinux_x86_64
manylinux_image: manylinux2010
manylinux_image: manylinux2014
- os: ubuntu-latest
python: 39
platform_id: manylinux_x86_64
manylinux_image: manylinux2010

# Linux 64 bit manylinux2014
- os: ubuntu-latest
python: 37
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
- os: ubuntu-latest
python: 38
python: 310
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
- os: ubuntu-latest
python: 39
python: 311
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
- os: ubuntu-latest
python: 310
python: 312
platform_id: manylinux_x86_64
manylinux_image: manylinux2014
- os: ubuntu-latest
Expand Down Expand Up @@ -136,6 +136,11 @@ jobs:
platform_id: macosx_x86_64
- os: macos-latest
python: 310
- os: macos-latest
python: 311
platform_id: macosx_x86_64
- os: macos-latest
python: 312
platform_id: macosx_x86_64
- os: macos-latest
python: 311
Expand All @@ -154,6 +159,9 @@ jobs:
- os: macos-latest
python: 311
platform_id: macosx_arm64
- os: macos-latest
python: 312
platform_id: macosx_arm64

steps:
- uses: actions/checkout@v3
Expand All @@ -174,7 +182,7 @@ jobs:
- name: Install cibuildwheel
run: |
python -m pip install -U pip
python -m pip install cibuildwheel==2.12.0
python -m pip install cibuildwheel==2.16.2
- name: Build wheels
env:
Expand Down Expand Up @@ -202,7 +210,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pylibjpeg-openjpeg

MIT License

Copyright (c) 2020 scaramallion
Copyright (c) 2020-2024 scaramallion

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

## pylibjpeg-openjpeg

A Python 3.7+ wrapper for
A Python 3.8+ wrapper for
[openjpeg](https://github.com/uclouvain/openjpeg), with a focus on use as a
plugin for [pylibjpeg](http://github.com/pydicom/pylibjpeg).

Expand Down
109 changes: 109 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@

import os
import sys
from pathlib import Path
import shutil
import subprocess
from typing import List, Any


PACKAGE_DIR = Path(__file__).parent / "openjpeg"
OPENJPEG_SRC = PACKAGE_DIR / "src" / "openjpeg" / "src" / "lib" / "openjp2"
INTERFACE_SRC = PACKAGE_DIR / "src" / "interface"


def build(setup_kwargs: Any) -> None:
from setuptools import Extension
from setuptools.dist import Distribution
import Cython.Compiler.Options
from Cython.Build import build_ext, cythonize
import numpy

setup_oj()

ext = Extension(
"_openjpeg",
[os.fspath(p) for p in get_source_files()],
language="c",
include_dirs=[
os.fspath(OPENJPEG_SRC),
os.fspath(INTERFACE_SRC),
numpy.get_include(),
# distutils.sysconfig.get_python_inc(),
],
extra_compile_args=[],
extra_link_args=[],
)

ext_modules = cythonize(
[ext],
include_path=ext.include_dirs,
language_level=3,
)

dist = Distribution({"ext_modules": ext_modules})
cmd = build_ext(dist)
cmd.ensure_finalized()
cmd.run()

for output in cmd.get_outputs():
output = Path(output)
relative_ext = output.relative_to(cmd.build_lib)
shutil.copyfile(output, relative_ext)

return setup_kwargs


def get_source_files() -> List[Path]:
"""Return a list of paths to the source files to be compiled."""
source_files = [
INTERFACE_SRC / "decode.c",
INTERFACE_SRC / "color.c",
]
for fname in OPENJPEG_SRC.glob("*"):
if fname.parts[-1].startswith("test"):
continue

if fname.parts[-1].startswith("bench"):
continue

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"))

return source_files


def setup_oj() -> None:
"""Run custom cmake."""
base_dir = os.path.join("openjpeg", "src", "openjpeg")

# Copy custom CMakeLists.txt file to openjpeg base dir
shutil.copy(
os.path.join("build_tools", "cmake", "CMakeLists.txt"),
base_dir
)
build_dir = os.path.join(base_dir, "build")
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)
cur_dir = os.getcwd()
os.chdir(build_dir)
subprocess.call(['cmake', fpath])
os.chdir(cur_dir)

# Turn off JPIP
if os.path.exists(INTERFACE_SRC / "opj_config.h"):
with open(INTERFACE_SRC / "opj_config.h", "a") as f:
f.write("\n")
f.write("#define USE_JPIP 0")
Loading

0 comments on commit 84c66fa

Please sign in to comment.