Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Add libpng and libjpeg-turbo requirement into conda recipe #2301

Merged
merged 107 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from 101 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
2b78943
Add libpng requirement into conda recipe
andfoy Jun 8, 2020
23255aa
Try to install libjpeg-turbo
andfoy Jun 8, 2020
006ab0c
Add PNG reading capabilities
r-zenine Feb 13, 2020
7b9ec24
Remove newline
andfoy Jun 11, 2020
f97a9f0
Add image extension to compilation instructions
andfoy Jun 11, 2020
ac6d26e
Include png functions as part of the main library
andfoy Jun 11, 2020
b14912e
Update CMakeLists
andfoy Jun 11, 2020
770cea5
Detect if building on conda-build
andfoy Jun 11, 2020
0861b80
Debug
andfoy Jun 11, 2020
a42a029
More debug messages
andfoy Jun 11, 2020
b7a19ea
Print globbed libreries
andfoy Jun 12, 2020
1afde4d
Print globbed libreries
andfoy Jun 12, 2020
386fd5b
Point to correct PNG path
andfoy Jun 12, 2020
2b5c469
Remove libJPEG preventively
andfoy Jun 12, 2020
0341aa5
Debug extension loading
andfoy Jun 12, 2020
721e5e3
Link libpng explicitly
andfoy Jun 12, 2020
2186d68
Link with PNG
andfoy Jun 12, 2020
b80fb08
Add libpng requirement into conda recipe
andfoy Jun 8, 2020
3d153f0
Try to install libjpeg-turbo
andfoy Jun 8, 2020
36b0a8f
Add PNG reading capabilities
r-zenine Feb 13, 2020
9d14d9e
Remove newline
andfoy Jun 11, 2020
852a289
Add image extension to compilation instructions
andfoy Jun 11, 2020
3e86f49
Include png functions as part of the main library
andfoy Jun 11, 2020
021e767
Update CMakeLists
andfoy Jun 11, 2020
e734175
Detect if building on conda-build
andfoy Jun 11, 2020
58c6524
Debug
andfoy Jun 11, 2020
b9295c1
More debug messages
andfoy Jun 11, 2020
02fa9d9
Print globbed libreries
andfoy Jun 12, 2020
6c757d4
Print globbed libreries
andfoy Jun 12, 2020
c207eab
Point to correct PNG path
andfoy Jun 12, 2020
a1aa2e6
Remove libJPEG preventively
andfoy Jun 12, 2020
34fc7d6
Debug extension loading
andfoy Jun 12, 2020
3ed2044
Link libpng explicitly
andfoy Jun 12, 2020
eaaf658
Link with PNG
andfoy Jun 12, 2020
3edae46
Merge branch 'add_libpng' of github.com:andfoy/vision into add_libpng
andfoy Jun 12, 2020
c17202e
Install libpng on conda-based wheel distributions
andfoy Jun 12, 2020
741f855
Add -y flag
andfoy Jun 12, 2020
a46f503
Add -y flag to yum
andfoy Jun 12, 2020
4bad033
Locate LibPNG on windows conda
andfoy Jun 12, 2020
b419fc1
Remove empty else
andfoy Jun 12, 2020
83eff79
Copy libpng16.so
andfoy Jun 12, 2020
eb2846f
Copy dylib on Mac
andfoy Jun 12, 2020
3563ef3
Improve check on Windows
andfoy Jun 13, 2020
347383f
Try to install ninja using conda on windows
andfoy Jun 15, 2020
51f6b48
Use libpng on Windows
andfoy Jun 15, 2020
ad00442
Package lib on windows wheel
andfoy Jun 15, 2020
4d82283
Point library to the correct place
andfoy Jun 15, 2020
32b2207
Include binaries as part of wheel
andfoy Jun 15, 2020
9a5aefe
Copy libpng.so on linux
andfoy Jun 15, 2020
a44c3b5
Look for png.h on Windows when using conda-build
andfoy Jun 15, 2020
dfcde68
Do not skip png tests on Mac/Win
andfoy Jun 15, 2020
d8d46d6
Restore libjpeg-turbo
andfoy Jun 15, 2020
eea8552
Install jpeg-turbo on wheel distributions
andfoy Jun 15, 2020
8c7dc31
Install libjpeg-turbo from conda-forge on wheel distributions
andfoy Jun 15, 2020
ee8148a
Do not pull av on conda-build
andfoy Jun 15, 2020
059fa42
Add pillow disclaimer
andfoy Jun 15, 2020
0ed1af6
Vendors libjpeg-turbo 2.0.4
r-zenine Feb 14, 2020
11d1a7a
Merge JPEG work
r-zenine Feb 15, 2020
3bb65ba
Remove submodules
andfoy Jun 15, 2020
c334d7e
Regenerate circle config
andfoy Jun 15, 2020
5650e59
Fix style issues
andfoy Jun 15, 2020
7894836
Fix C++ style issues
andfoy Jun 15, 2020
2da51d4
More style corrections
andfoy Jun 15, 2020
78455ae
Add JPEG-turbo to linking libraries
andfoy Jun 15, 2020
a0a383d
More style corrections
andfoy Jun 15, 2020
f143e2c
More style corrections
andfoy Jun 15, 2020
95cc941
More style corrections
andfoy Jun 15, 2020
1c9270a
Install libjpeg-turbo-devel
andfoy Jun 15, 2020
ee388e5
Install libturbo-jpeg on typing pipeline
andfoy Jun 15, 2020
462ed6c
Update Circle template
andfoy Jun 15, 2020
989db57
Windows and Unix turbojpeg have the same linking name
andfoy Jun 15, 2020
6e9ad0e
Install turbojpeg-devel instead of libjpeg-turbo
andfoy Jun 15, 2020
dd43bcd
Copy TurboJPEG binaries to wheel
andfoy Jun 15, 2020
e542e48
Move test image
andfoy Jun 16, 2020
b5fa45e
Move back test image
andfoy Jun 16, 2020
3e90556
Update JPEG test path
andfoy Jun 16, 2020
4e09af0
Remove dot from extension
andfoy Jun 16, 2020
c2e9bf3
Merge branch 'master' into add_libpng
andfoy Jun 17, 2020
8ac335e
Move image functions to extension
andfoy Jun 18, 2020
2adb87e
Use stdout arg in subprocess
andfoy Jun 18, 2020
44826a7
Disable image extension if libpng or turbojpeg are not found
andfoy Jun 18, 2020
1e830ea
Append libpng stdout
andfoy Jun 18, 2020
37c889b
Prevent list appending on lists
andfoy Jun 18, 2020
3cca366
Minor path correction
andfoy Jun 18, 2020
2a6ff9f
Minor error correction
andfoy Jun 18, 2020
b89b349
Add linking flags
andfoy Jun 18, 2020
264cb74
Merge branch 'add_libpng' of github.com:andfoy/vision into add_libpng
andfoy Jun 19, 2020
a0ce4ca
Style issues correction
andfoy Jun 19, 2020
bd752aa
Address minor review corrections
andfoy Jun 22, 2020
5259757
Refactor library search
andfoy Jun 23, 2020
3013247
Restore access index
andfoy Jun 23, 2020
9d8b1b5
Fix JPEG tests
andfoy Jun 23, 2020
7c3ec51
Update libpng version in Travis
andfoy Jun 23, 2020
158eec8
Add -y flag
andfoy Jun 23, 2020
269d8e5
Remove dot
andfoy Jun 23, 2020
273dc1a
Update libpng using apt
andfoy Jun 23, 2020
cfc7c75
Check libpng version
andfoy Jun 23, 2020
d32a5f0
Change libturbojpeg binary
andfoy Jun 23, 2020
051425b
Update import
andfoy Jun 23, 2020
3bc7323
Change call
andfoy Jun 23, 2020
6b87895
Restore av in conda recipe
andfoy Jun 24, 2020
af61f94
Merge with master
andfoy Jun 29, 2020
123fd3f
Minor error correction
andfoy Jun 29, 2020
831749c
Remove unused comment in travis.yml
andfoy Jun 29, 2020
558b0cb
Update README
andfoy Jun 29, 2020
8b2f507
Fix missing links
andfoy Jun 29, 2020
b560227
Remove fixes for 16.04
andfoy Jun 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ jobs:
- checkout
- run:
command: |
sudo apt-get update -y
sudo apt install -y libturbojpeg-dev
pip install --user --progress-bar off numpy mypy
pip install --user --progress-bar off --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
pip install --user --progress-bar off --editable .
Expand Down
2 changes: 2 additions & 0 deletions .circleci/config.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ jobs:
- checkout
- run:
command: |
sudo apt-get update -y
sudo apt install -y libturbojpeg-dev
pip install --user --progress-bar off numpy mypy
pip install --user --progress-bar off --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
pip install --user --progress-bar off --editable .
Expand Down
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ matrix:

before_install:
- sudo apt-get update
- sudo apt-get install -y libpng16-dev libturbojpeg
# Prevent static library to be picked up
- sudo ln -s /usr/lib/x86_64-linux-gnu/libturbojpeg.so.0.1.0 /usr/lib/x86_64-linux-gnu/libturbojpeg.so
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
Expand All @@ -18,6 +21,7 @@ before_install:
- conda info -a

- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION pytorch scipy -c pytorch-nightly
# LibPNG version in Ubuntu 16.04 is outdated
andfoy marked this conversation as resolved.
Show resolved Hide resolved
- source activate test-environment
- |
if [[ "$IMAGE_BACKEND" == "Pillow-SIMD" ]]; then
Expand Down
16 changes: 11 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,28 @@ if(WITH_CUDA)
endif()

find_package(Python3 COMPONENTS Development)

find_package(Torch REQUIRED)
find_package(PNG REQUIRED)


file(GLOB HEADERS torchvision/csrc/*.h)
file(GLOB OPERATOR_SOURCES torchvision/csrc/cpu/*.h torchvision/csrc/cpu/*.cpp torchvision/csrc/*.cpp)
file(GLOB IMAGE_HEADERS torchvision/csrc/cpu/image/*.h)
file(GLOB IMAGE_SOURCES torchvision/csrc/cpu/image/*.cpp)
file(GLOB OPERATOR_SOURCES torchvision/csrc/cpu/*.h torchvision/csrc/cpu/*.cpp ${IMAGE_HEADERS} ${IMAGE_SOURCES} ${HEADERS} torchvision/csrc/*.cpp)
if(WITH_CUDA)
file(GLOB OPERATOR_SOURCES ${OPERATOR_SOURCES} torchvision/csrc/cuda/*.h torchvision/csrc/cuda/*.cu)
endif()
file(GLOB MODELS_HEADERS torchvision/csrc/models/*.h)
file(GLOB MODELS_SOURCES torchvision/csrc/models/*.h torchvision/csrc/models/*.cpp)

add_library(${PROJECT_NAME} SHARED ${MODELS_SOURCES} ${OPERATOR_SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES} Python3::Python)
add_library(${PROJECT_NAME} SHARED ${MODELS_SOURCES} ${OPERATOR_SOURCES} ${IMAGE_SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES} ${PNG_LIBRARY} Python3::Python)
# target_link_libraries(${PROJECT_NAME} PRIVATE ${PNG_LIBRARY} Python3::Python)
set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME TorchVision)

target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${HEADERS}>
$<BUILD_INTERFACE:${HEADERS}:${PNG_INCLUDE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

include(GNUInstallDirs)
Expand Down Expand Up @@ -61,7 +67,7 @@ install(FILES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/cpu)
if(WITH_CUDA)
install(FILES
torchvision/csrc/cuda/vision_cuda.h
torchvision/csrc/cuda/vision_cuda.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/cuda)
endif()
install(FILES ${MODELS_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/models)
25 changes: 25 additions & 0 deletions packaging/build_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,34 @@ script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
export BUILD_TYPE=wheel
setup_env 0.7.0
setup_wheel_python

pip_install numpy pyyaml future "ninja==1.9.0.post1"
setup_pip_pytorch_version
python setup.py clean

# Copy binaries to be included in the wheel distribution
if [[ "$(uname)" == Darwin || "$OSTYPE" == "msys" ]]; then
python_exec="$(which python)"
bin_path=$(dirname $python_exec)
env_path=$(dirname $bin_path)
if [[ "$(uname)" == Darwin ]]; then
# Include LibPNG
cp "$env_path/lib/libpng16.dylib" torchvision
# Include TurboJPEG
cp "$env_path/lib/libturbojpeg.dylib" torchvision
else
# Include libPNG
cp "$bin_path/Library/lib/libpng.lib" torchvision
# Include TurboJPEG
cp "$bin_path/Library/lib/turbojpeg.lib" torchvision
fi
else
# Include LibPNG
cp "/usr/lib64/libpng.so" torchvision
# Include TurboJPEG
cp "/usr/lib64/libturbojpeg.so" torchvision
fi

if [[ "$OSTYPE" == "msys" ]]; then
IS_WHEEL=1 "$script_dir/windows/internal/vc_env_helper.bat" python setup.py bdist_wheel
else
Expand Down
6 changes: 6 additions & 0 deletions packaging/pkg_helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ setup_wheel_python() {
conda env remove -n "env$PYTHON_VERSION" || true
conda create -yn "env$PYTHON_VERSION" python="$PYTHON_VERSION"
conda activate "env$PYTHON_VERSION"
# Install libPNG from Anaconda (defaults)
conda install libpng -y
# Install libJPEG-turbo from conda-forge
conda install -y libjpeg-turbo -c conda-forge
else
# Install native CentOS libPNG, libJPEG-turbo
yum install -y libpng-devel turbojpeg-devel
case "$PYTHON_VERSION" in
2.7)
if [[ -n "$UNICODE_ABI" ]]; then
Expand Down
3 changes: 3 additions & 0 deletions packaging/torchvision/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
channel_sources:
- defaults,conda-forge
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it now safe to use conda-forge as well? At some point we had issues with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems only libturbojpeg is being pulled from there, so all other packages are being pulled from defaults or the main PyTorch channel


blas_impl:
- mkl # [x86_64]
c_compiler:
Expand Down
6 changes: 6 additions & 0 deletions packaging/torchvision/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ source:
requirements:
build:
- {{ compiler('c') }} # [win]
- libpng
- libjpeg-turbo

host:
- python
Expand All @@ -18,6 +20,10 @@ requirements:

run:
- python
- libpng
- libjpeg-turbo
# Pillow introduces unwanted conflicts with libjpeg-turbo, as it depends on jpeg
# The fix depends on https://github.com/conda-forge/conda-forge.github.io/issues/673
Comment on lines +25 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain when / how these conflicts materialize?
Could that lead to segfaults when the user imports torchvision and PIL?

Copy link
Contributor Author

@andfoy andfoy Jun 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conflict here is that we're substituting the libjpeg library, which is used primarily by Pillow, however this may not affect us as the ABI between jpegturbo and libjpeg is the same AFAIK.

Most Linux distributions distinguish between libturbojpeg (the library itself) and libjpeg-turbo (the libjpeg version using turbojpeg), thus, they do not have this problem, as we link against libturbojpeg, rather than against libjpeg-turbo.

In conda-forge, we have this conflict because the recipe for libjpeg-turbo produces both the turbo flavored libjpeg and libturbojpeg. I spoke to @isuruf, one of the maintainers in conda-forge, and he told me that they are working towards a solution in conda-forge/conda-forge.github.io#673, but right now there are no alternatives to this conflict.

I guess we are not having any problem with this conflicting installation, as the tests are passing. However, we should encourage users to install PyTorch and torchvision on a separate environment, so we prevent other errors that could be caused as part of this conflict and we're not aware of

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, this makes me a bit worried, because AFAIK we don't have tests running on OSX, only Linux and Windows (we do compile on OSX though).
So if there is a problem happening in OSX we wouldn't be able to see it in CI.

Do you think that, if we were to use libjpeg API, everything would be safer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't they running on the binary_macos_conda_*_pyxx CircleCI pipelines?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok, yeah, we were not running tests for OSX with wheels, only conda.

But still, do you think if we were to use libjpeg API it would make things safer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think right now we don't have much trouble on our setup, as we are linking against libturbojpeg and not libjpeg directly. If we were compilling against libjpeg, then we would be in trouble. Right now the only conflict that we have is the one on conda-forge.

A provisional solution would be compilling libturbojpeg (Without libjpeg) ourselves and publish it into the conda pytorch channel until conda-forge/conda-forge.github.io#673 is fixed. What do you think about this?

- pillow >=4.1.1
- numpy >=1.11
{{ environ.get('CONDA_PYTORCH_CONSTRAINT') }}
Expand Down
137 changes: 134 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
import sys
from setuptools import setup, find_packages
from pkg_resources import get_distribution, DistributionNotFound
from pkg_resources import parse_version, get_distribution, DistributionNotFound
import subprocess
import distutils.command.clean
import distutils.spawn
Expand Down Expand Up @@ -76,7 +76,76 @@ def write_version_file():
requirements.append(pillow_req + pillow_ver)


def find_library(name, vision_include):
this_dir = os.path.dirname(os.path.abspath(__file__))
build_prefix = os.environ.get('BUILD_PREFIX', None)
is_conda_build = build_prefix is not None

library_found = False
conda_installed = False
lib_folder = None
include_folder = None
library_header = '{0}.h'.format(name)

print('Running build on conda-build: {0}'.format(is_conda_build))
if is_conda_build:
# Add conda headers/libraries
if os.name == 'nt':
build_prefix = os.path.join(build_prefix, 'Library')
include_folder = os.path.join(build_prefix, 'include')
lib_folder = os.path.join(build_prefix, 'lib')
library_header_path = os.path.join(
include_folder, library_header)
library_found = os.path.isfile(library_header_path)
conda_installed = library_found
else:
# Check if using Anaconda to produce wheels
conda = distutils.spawn.find_executable('conda')
is_conda = conda is not None
print('Running build on conda: {0}'.format(is_conda))
if is_conda:
python_executable = sys.executable
py_folder = os.path.dirname(python_executable)
if os.name == 'nt':
env_path = os.path.join(py_folder, 'Library')
else:
env_path = os.path.dirname(py_folder)
lib_folder = os.path.join(env_path, 'lib')
include_folder = os.path.join(env_path, 'include')
library_header_path = os.path.join(
include_folder, library_header)
library_found = os.path.isfile(library_header_path)
conda_installed = library_found

# Try to locate turbojpeg in Linux standard paths
if not library_found:
if sys.platform == 'linux':
library_found = os.path.exists('/usr/include/{0}'.format(
library_header))
library_found = library_found or os.path.exists(
'/usr/local/include/{0}'.format(library_header))
else:
# Lookup in TORCHVISION_INCLUDE or in the package file
package_path = os.path.join(this_dir, 'torchvision')
for folder in vision_include + package_path:
andfoy marked this conversation as resolved.
Show resolved Hide resolved
candidate_path = os.path.join(folder, library_header)
library_found = os.path.exists(candidate_path)
if library_found:
break

return library_found, conda_installed, include_folder, lib_folder


def get_extensions():
vision_include = os.environ.get('TORCHVISION_INCLUDE', None)
vision_library = os.environ.get('TORCHVISION_LIBRARY', None)
vision_include = (vision_include.split(os.pathsep)
if vision_include is not None else [])
vision_library = (vision_library.split(os.pathsep)
if vision_library is not None else [])
include_dirs = vision_include
library_dirs = vision_library

this_dir = os.path.dirname(os.path.abspath(__file__))
extensions_dir = os.path.join(this_dir, 'torchvision', 'csrc')

Expand Down Expand Up @@ -149,13 +218,14 @@ def get_extensions():

sources = [os.path.join(extensions_dir, s) for s in sources]

include_dirs = [extensions_dir]
include_dirs += [extensions_dir]

ext_modules = [
extension(
'torchvision._C',
sources,
include_dirs=include_dirs,
library_dirs=library_dirs,
define_macros=define_macros,
extra_compile_args=extra_compile_args,
)
Expand All @@ -171,6 +241,65 @@ def get_extensions():
)
)

# Image reading extension
image_macros = []
image_include = [extensions_dir]
image_library = []
image_link_flags = []

# Locating libPNG
libpng = distutils.spawn.find_executable('libpng-config')
png_found = libpng is not None
image_macros += [('PNG_FOUND', str(int(png_found)))]
print('PNG found: {0}'.format(png_found))
if png_found:
png_version = subprocess.run([libpng, '--version'],
stdout=subprocess.PIPE)
png_version = png_version.stdout.strip().decode('utf-8')
print('libpng version: {0}'.format(png_version))
png_version = parse_version(png_version)
if png_version >= parse_version("1.6.0"):
print('Building torchvision with PNG image support')
png_lib = subprocess.run([libpng, '--libdir'],
stdout=subprocess.PIPE)
png_include = subprocess.run([libpng, '--I_opts'],
stdout=subprocess.PIPE)
image_library += [png_lib.stdout.strip().decode('utf-8')]
image_include += [png_include.stdout.strip().decode('utf-8')]
image_link_flags.append('png' if os.name != 'nt' else 'libpng')
else:
print('libpng installed version is less than 1.6.0, '
'disabling PNG support')
png_found = False

# Locating libjpegturbo
turbojpeg_info = find_library('turbojpeg', vision_include)
(turbojpeg_found, conda_installed,
turbo_include_folder, turbo_lib_folder) = turbojpeg_info

image_macros += [('JPEG_FOUND', str(int(turbojpeg_found)))]
print('turboJPEG found: {0}'.format(turbojpeg_found))
if turbojpeg_found:
print('Building torchvision with JPEG image support')
image_link_flags.append('turbojpeg')
if conda_installed:
image_library += [turbo_lib_folder]
image_include += [turbo_include_folder]

image_path = os.path.join(extensions_dir, 'cpu', 'image')
image_src = glob.glob(os.path.join(image_path, '*.cpp'))

if png_found or turbojpeg_found:
ext_modules.append(extension(
'torchvision.image',
image_src,
include_dirs=include_dirs + [image_path] + image_include,
library_dirs=library_dirs + image_library,
define_macros=image_macros,
libraries=image_link_flags,
extra_compile_args=extra_compile_args
))

ffmpeg_exe = distutils.spawn.find_executable('ffmpeg')
has_ffmpeg = ffmpeg_exe is not None

Expand Down Expand Up @@ -243,7 +372,9 @@ def run(self):

# Package info
packages=find_packages(exclude=('test',)),

package_data={
package_name: ['*.lib', '*.dylib', '*.so']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? We are able to package the _C.so without this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary to pack libpng/turbojpeg into the wheel distributions

},
zip_safe=False,
install_requires=requirements,
extras_require={
Expand Down
Loading