Martin Weinelt ae4a1a485a
treewide: add explicit format attribute for Python packages
If a Python package does not come with either `format` or `pyproject` we
consider it a setuptools build, that calls `setup.py` directly, which is
deprecated.

This change, as a first step, migrates a large chunk of these packages to
set setuptools as their explicit format

This is so we can unify the problem space for the next step of the
migration.
2025-07-02 05:56:47 +02:00

108 lines
2.2 KiB
Nix

{
lib,
stdenv,
torch,
apple-sdk_13,
buildPythonPackage,
darwinMinVersionHook,
fetchFromGitHub,
# nativeBuildInputs
libpng,
ninja,
which,
# buildInputs
libjpeg_turbo,
# dependencies
numpy,
pillow,
scipy,
# tests
pytest,
writableTmpDirAsHomeHook,
}:
let
inherit (torch) cudaCapabilities cudaPackages cudaSupport;
pname = "torchvision";
version = "0.22.1";
in
buildPythonPackage {
format = "setuptools";
inherit pname version;
stdenv = torch.stdenv;
src = fetchFromGitHub {
owner = "pytorch";
repo = "vision";
tag = "v${version}";
hash = "sha256-KYIhd0U2HdvNt/vjQ8wA/6l/ZCF8wBm4NrOMgBtoWG4=";
};
nativeBuildInputs = [
libpng
ninja
which
] ++ lib.optionals cudaSupport [ cudaPackages.cuda_nvcc ];
buildInputs =
[
libjpeg_turbo
libpng
torch.cxxdev
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
# This should match the SDK used by `torch` above
apple-sdk_13
# error: unknown type name 'MPSGraphCompilationDescriptor'; did you mean 'MPSGraphExecutionDescriptor'?
# https://developer.apple.com/documentation/metalperformanceshadersgraph/mpsgraphcompilationdescriptor/
(darwinMinVersionHook "12.0")
];
dependencies = [
numpy
pillow
torch
scipy
];
env =
{
TORCHVISION_INCLUDE = "${libjpeg_turbo.dev}/include/";
TORCHVISION_LIBRARY = "${libjpeg_turbo}/lib/";
}
// lib.optionalAttrs cudaSupport {
TORCH_CUDA_ARCH_LIST = "${lib.concatStringsSep ";" cudaCapabilities}";
FORCE_CUDA = 1;
};
# tests download big datasets, models, require internet connection, etc.
doCheck = false;
pythonImportsCheck = [ "torchvision" ];
nativeCheckInputs = [
pytest
writableTmpDirAsHomeHook
];
checkPhase = ''
py.test test --ignore=test/test_datasets_download.py
'';
meta = {
description = "PyTorch vision library";
homepage = "https://pytorch.org/";
changelog = "https://github.com/pytorch/vision/releases/tag/v${version}";
license = lib.licenses.bsd3;
platforms = with lib.platforms; linux ++ lib.optionals (!cudaSupport) darwin;
maintainers = with lib.maintainers; [ GaetanLepage ];
};
}