Skip to content

Commit

Permalink
MAINT: remove standard images from built package (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
FirefoxMetzger committed May 28, 2023
1 parent c93536c commit 6288f19
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 101 deletions.
Empty file.
99 changes: 0 additions & 99 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
"""

import os
import os.path as op
import sys
import shutil
from distutils.core import Command
from distutils.command.sdist import sdist
from distutils.command.build_py import build_py
from itertools import chain

try:
Expand All @@ -33,12 +27,6 @@
from distutils.core import setup # Supports anything else


try:
from wheel.bdist_wheel import bdist_wheel
except ImportError:
bdist_wheel = object


name = "imageio"
description = "Library for reading and writing a wide range of image, video, scientific, and volumetric data formats."

Expand Down Expand Up @@ -87,91 +75,12 @@

# Prepare resources dir
package_data = [
"resources/shipped_resources_go_here",
"resources/*.*",
"resources/images/*.*",
"resources/freeimage/*.*",
"py.typed",
"**/*.pyi",
"*.pyi",
]


def _set_crossplatform_resources(resource_dir):
import imageio

# Clear now
if op.isdir(resource_dir):
shutil.rmtree(resource_dir)
os.mkdir(resource_dir)
open(op.join(resource_dir, "shipped_resources_go_here"), "wb")

# Load images
for fname in [
"images/chelsea.png",
"images/chelsea.zip",
"images/astronaut.png",
"images/newtonscradle.gif",
"images/cockatoo.mp4",
"images/realshort.mp4",
"images/stent.npz",
]:
imageio.core.get_remote_file(fname, resource_dir, force_download=True)


def _set_platform_resources(resource_dir, platform):
import imageio

# Create file to show platform
assert platform
open(op.join(resource_dir, "platform_%s" % platform), "wb")

# Load freeimage
fname = imageio.plugins.freeimage.FNAME_PER_PLATFORM[platform]
imageio.core.get_remote_file(
"freeimage/" + fname, resource_dir, force_download=True
)


class test_command(Command):
user_options = []

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
from imageio import testing

os.environ["IMAGEIO_NO_INTERNET"] = "1" # run tests without inet
sys.exit(testing.test_unit())


class build_with_fi(build_py):
def run(self):
# Download images and libs
import imageio

resource_dir = imageio.core.resource_dirs()[0]
_set_crossplatform_resources(resource_dir)
_set_platform_resources(resource_dir, imageio.core.get_platform())
# Build as normal
build_py.run(self)


class build_with_images(sdist):
def run(self):
# Download images
import imageio

resource_dir = imageio.core.resource_dirs()[0]
_set_crossplatform_resources(resource_dir)
# Build as normal
sdist.run(self)


# pinned to > 8.3.2 due to security vulnerability
# See: https://github.com/advisories/GHSA-98vv-pw6r-q6q4
install_requires = ["numpy", "pillow >= 8.3.2"]
Expand Down Expand Up @@ -216,14 +125,6 @@ def run(self):


setup(
cmdclass={
# 'bdist_wheel_all': bdist_wheel_all,
# 'sdist_all': sdist_all,
"build_with_images": build_with_images,
"build_with_fi": build_with_fi,
"sdist": build_with_images,
"test": test_command,
},
name=name,
version=__version__,
author="imageio contributors",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@ def test_apng_metadata(tmp_path, test_images):
assert metadata == metadata2


def test_write_format_warning():
frames = iio.imread("imageio:chelsea.png")
def test_write_format_warning(test_images):
frames = iio.imread(test_images / "chelsea.png")
bytes_image = iio.imwrite("<bytes>", frames, extension=".png", plugin="pillow")

with pytest.warns(UserWarning):
Expand Down

0 comments on commit 6288f19

Please sign in to comment.