Skip to content

Commit 0b51d94

Browse files
authored
Add wheel building job
2 parents a4ab9b6 + d69690b commit 0b51d94

File tree

11 files changed

+123
-10
lines changed

11 files changed

+123
-10
lines changed

.github/workflows/linux_wheel.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build Linux wheel
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- nightly
8+
- main
9+
- release/*
10+
tags:
11+
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
12+
workflow_dispatch:
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }}
16+
cancel-in-progress: true
17+
18+
permissions:
19+
id-token: write
20+
contents: write
21+
22+
defaults:
23+
run:
24+
shell: bash -l -eo pipefail {0}
25+
26+
jobs:
27+
28+
generate-matrix:
29+
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
30+
with:
31+
package-type: wheel
32+
os: linux
33+
test-infra-repository: pytorch/test-infra
34+
test-infra-ref: main
35+
with-xpu: disable
36+
with-rocm: disable
37+
with-cuda: disable
38+
build-python-only: "disable"
39+
40+
build:
41+
needs: generate-matrix
42+
strategy:
43+
fail-fast: false
44+
name: Build and Upload Linux wheel
45+
uses: pytorch/test-infra/.github/workflows/build_wheels_linux.yml@main
46+
with:
47+
repository: pytorch-labs/torchvision-extra-decoders
48+
ref: ""
49+
test-infra-repository: pytorch/test-infra
50+
test-infra-ref: main
51+
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
52+
pre-script: packaging/pre_build_script.sh
53+
package-name: torchvision-extra-decoders
54+
trigger-event: ${{ github.event_name }}

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.0.1
4+
hooks:
5+
- id: check-docstring-first
6+
- id: check-toml
7+
- id: check-yaml
8+
exclude: packaging/.*
9+
args:
10+
- --allow-multiple-documents
11+
- id: mixed-line-ending
12+
args: [--fix=lf]
13+
- id: end-of-file-fixer
14+
15+
- repo: https://github.com/omnilib/ufmt
16+
rev: v1.3.3
17+
hooks:
18+
- id: ufmt
19+
additional_dependencies:
20+
- black == 22.3.0
21+
- usort == 1.0.2
22+
23+
- repo: https://github.com/PyCQA/flake8
24+
rev: 5.0.4
25+
hooks:
26+
- id: flake8
27+
args: [--config=setup.cfg]

packaging/pre_build_script.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
conda install libavif libheic -c conda-forge -yq

setup.cfg

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[bdist_wheel]
2+
universal=1
3+
4+
[metadata]
5+
license_files = LICENSE
6+
7+
[pep8]
8+
max-line-length = 120
9+
10+
[flake8]
11+
# note: we ignore all 501s (line too long) anyway as they're taken care of by black
12+
max-line-length = 120
13+
ignore = E203, E402, W503, W504, F821, E501, B, C4, EXE
14+
per-file-ignores =
15+
__init__.py: F401, F403, F405
16+
exclude = venv

setup.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
# This software may be used and distributed according to the terms of the
44
# GNU Lesser General Public License version 2.
55

6-
import sys
76
import os
7+
import sys
88
from pathlib import Path
9+
910
from setuptools import find_packages, setup
1011

1112
from torch.utils.cpp_extension import BuildExtension, CppExtension
1213

14+
1315
def find_library(header):
1416
# returns (found, include dir, library dir)
1517
# if include dir or library dir is None, it means that the library is in
@@ -44,17 +46,19 @@ def find_library(header):
4446

4547
def make_extension():
4648

47-
heic_found, heic_include_dir, heic_library_dir = find_library(header="libheif/heif_cxx.h")
49+
heic_found, heic_include_dir, heic_library_dir = find_library(
50+
header="libheif/heif_cxx.h"
51+
)
4852
if not heic_found:
4953
raise RuntimeError("Couldn't find libheic!")
50-
54+
5155
print(f"{heic_include_dir = }")
5256
print(f"{heic_library_dir = }")
5357

5458
avif_found, avif_include_dir, avif_library_dir = find_library(header="avif/avif.h")
5559
if not avif_found:
5660
raise RuntimeError("Couldn't find libavif!")
57-
61+
5862
print(f"{heic_include_dir = }")
5963
print(f"{heic_library_dir = }")
6064

@@ -71,6 +75,14 @@ def make_extension():
7175
)
7276

7377

78+
def get_requirements():
79+
pytorch_dep = os.getenv("TORCH_PACKAGE_NAME", "torch")
80+
if os.getenv("PYTORCH_VERSION"):
81+
pytorch_dep += "==" + os.getenv("PYTORCH_VERSION")
82+
83+
return [pytorch_dep]
84+
85+
7486
if __name__ == "__main__":
7587

7688
with open("README.md") as f:
@@ -91,7 +103,7 @@ def make_extension():
91103
packages=find_packages(exclude=("test",)),
92104
package_data={PACKAGE_NAME: ["*.dll", "*.dylib", "*.so"]},
93105
zip_safe=False,
94-
install_requires=[],
106+
install_requires=get_requirements(),
95107
python_requires=">=3.9",
96108
ext_modules=[make_extension()],
97109
cmdclass={

torchvision_extra_decoders/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# GNU Lesser General Public License version 2.
55

66
from pathlib import Path
7+
78
import torch
89

910

torchvision_extra_decoders/csrc/common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ bool should_this_return_rgb_or_rgba(
4242
return !has_alpha;
4343
}
4444

45-
} // namespace extra_decoders_ns
45+
} // namespace extra_decoders_ns

torchvision_extra_decoders/csrc/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ bool should_this_return_rgb_or_rgba(
2424
ImageReadMode mode,
2525
bool has_alpha);
2626

27-
} // namespace extra_decoders_ns
27+
} // namespace extra_decoders_ns

torchvision_extra_decoders/csrc/decode_avif.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ torch::Tensor decode_avif(
8686
return out.permute({2, 0, 1}); // return CHW, channels-last
8787
}
8888

89-
} // namespace extra_decoders_ns
89+
} // namespace extra_decoders_ns

torchvision_extra_decoders/csrc/decode_heic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,4 @@ torch::Tensor decode_heic(
125125
return out.permute({2, 0, 1});
126126
}
127127

128-
} // namespace extra_decoders_ns
128+
} // namespace extra_decoders_ns

0 commit comments

Comments
 (0)