File python-torchvision.spec of Package python-torchvision-stable

#
# spec file for package python-torchvision
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

%define skip_python313 1

%global flavor @BUILD_FLAVOR@%{nil}
%global upstream_name vision
%global pytorch_version 2.3.1
%if 0%{?suse_version} > 1500
%global ffmpeg_version 6
%else
%global ffmpeg_version 4
%endif

%if "%{flavor}" == "standard"
%bcond_with cuda
%bcond_with rocm
%endif

%if "%{flavor}" == "rocm"
%bcond_without rocm
%global rocm_major 6
%global rocm_minor 2
%global rocm_release %{rocm_major}.%{rocm_minor}
%global pkg_suffix -rocm-%{rocm_major}-%{rocm_minor}
%endif

%if "%{flavor}" == "cuda-10-2"
%bcond_without cuda
%define cudaver 10-2
%endif

%{?sle15_python_module_pythons}
Name:           python-torchvision-stable%{?pkg_suffix}
Version:        0.18.1
Release:        0
Summary:        Datasets, Transforms and Models specific to Computer Vision
License:        BSD-3-Clause
URL:            https://github.com/pytorch/%{upstream_name}
Source:         %{url}/archive/refs/tags/v%{version}.tar.gz#/python-torchvision-%{version}.tar.gz

Patch0:         torchvision-fix-build.patch

BuildRequires:  %{python_module pip}
BuildRequires:  %{python_module setuptools}
BuildRequires:  %{python_module torch-stable%{?pkg_suffix}-devel = %pytorch_version}
BuildRequires:  %{python_module torch-stable%{?pkg_suffix} = %pytorch_version}
BuildRequires:  cmake
BuildRequires:  fdupes
BuildRequires:  ffmpeg-%{ffmpeg_version}
BuildRequires:  ffmpeg-%{ffmpeg_version}-libavcodec-devel
BuildRequires:  ffmpeg-%{ffmpeg_version}-libavfilter-devel
BuildRequires:  ffmpeg-%{ffmpeg_version}-libavformat-devel
BuildRequires:  ffmpeg-%{ffmpeg_version}-libavutil-devel
BuildRequires:  ffmpeg-%{ffmpeg_version}-libpostproc-devel
BuildRequires:  ffmpeg-%{ffmpeg_version}-libswresample-devel
BuildRequires:  ffmpeg-%{ffmpeg_version}-libswscale-devel

%if 0%{?sle_version} == 150600
BuildRequires:  gcc12-c++
BuildRequires:  libstdc++6-devel-gcc12
%else
BuildRequires:  gcc-c++
BuildRequires:  libstdc++-devel
%endif

%if %{with rocm}
BuildRequires:  rocm-cmake
BuildRequires:  rocm-rpm-macros

# this one pulls in the ROCm Clang package
BuildRequires:  rocm-release(hip-devel) = %{rocm_release}
BuildRequires:  cmake(COMgr-ROCm) = %{rocm_release}
BuildRequires:  cmake(LLVM-ROCm) = %{rocm_release}
BuildRequires:  cmake(rocm-runtime) = %{rocm_release}

BuildRequires:  rocm-release(rocm-core-devel) = %{rocm_release}

Provides:       python-torchvision = %version
Provides:       rocm-release(python-torchvision) = %{rocm_release}
%endif

BuildRequires:  libjpeg-devel
BuildRequires:  libpng-devel
BuildRequires:  ninja
BuildRequires:  python-rpm-macros
Requires:       python-pytorch%{?pkg_suffix} = %pytorch_version
ExcludeArch:    %ix86

%if "%flavor" == ""
ExclusiveArch:  do_not_build
%endif

%python_subpackages

%description
The torchvision package consists of popular datasets,
model architectures, and common image transformations
for computer vision.

%prep
%autosetup -p1 -n %{upstream_name}-%{version}

%build
%define buildvars \
  export LC_ALL="C.UTF-8" \
  export TORCHVISION_INCLUDE=/usr/include/ffmpeg \
  export BUILD_VERSION=%{version} \
  export MAX_JOBS=%{?jobs} \
  %if %{with rocm} \
  export PYTORCH_ROCM_ARCH="%{list_sep rocm_gpu_list ;}" \
  export CC=clang-rocm \
  export CXX=clang++-rocm \
  export TORCH_DONT_CHECK_COMPILER_ABI=1 \
  %else \
  %if 0%{?sle_version} == 150600 \
  export CXX=g++-12 \
  export CC=gcc-12 \
  %endif \
  %endif \
  %{nil}

%buildvars
%python_build

%install
%buildvars
%python_install

%python_expand %fdupes %{buildroot}/%{$python_sitearch}/*

%files %{python_files}
%license LICENSE
%doc README.md
%{python_sitearch}/torchvision*

%changelog
openSUSE Build Service is sponsored by