Skip to content

Commit

Permalink
Prevent building a wheel if BUILD_AGAINST_ALL_FFMPEG_FROM_S3 is not s…
Browse files Browse the repository at this point in the history
…et (#31)

Summary:
When we build a wheel (typically in preparation of a new release), we should always build against our non-GPL FFmpeg libraries on S3, i.e. `BUILD_AGAINST_ALL_FFMPEG_FROM_S3` should be set. This PR enforces that, and should prevent us from pushing a problematic wheel on PyPI.

There might be good reasons to build a wheel against a specific installed version (e.g. maybe internally, or for debugging, or for an esoteric local setup). We still allow that if  `I_SWEAR_I_KNOW_WHAT_IM_DOING` is set (happy to consider other names...)

Pull Request resolved: #31

Reviewed By: scotts

Differential Revision: D58646821

Pulled By: NicolasHug

fbshipit-source-id: a1b40945960ccdd2f4c868642a918fb125935e45
  • Loading branch information
NicolasHug authored and facebook-github-bot committed Jun 17, 2024
1 parent 45d5c28 commit e1e0352
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import os
import subprocess
import sys
from pathlib import Path

import torch
Expand Down Expand Up @@ -89,15 +90,28 @@ def get_ext_filename(self, fullname):
return ext_filename


NOT_A_LICENSE_VIOLATION_VAR = "I_CONFIRM_THIS_IS_NOT_A_LICENSE_VIOLATION"
BUILD_AGAINST_ALL_FFMPEG_FROM_S3_VAR = "BUILD_AGAINST_ALL_FFMPEG_FROM_S3"
not_a_license_violation = os.getenv(NOT_A_LICENSE_VIOLATION_VAR) is not None
build_against_all_ffmpeg_from_s3 = (
os.getenv(BUILD_AGAINST_ALL_FFMPEG_FROM_S3_VAR) is not None
)
if "bdist_wheel" in sys.argv and not (
build_against_all_ffmpeg_from_s3 or not_a_license_violation
):
raise ValueError(
"It looks like you're trying to build a wheel. "
f"You probably want to set {BUILD_AGAINST_ALL_FFMPEG_FROM_S3_VAR}. "
f"If you have a good reason *not* to, then set {NOT_A_LICENSE_VIOLATION_VAR}."
)

# If BUILD_AGAINST_ALL_FFMPEG_FROM_S3 is set then we want to build against all
# ffmpeg major version that are available on our S3 bucket.
# If BUILD_AGAINST_ALL_FFMPEG_FROM_S3 is not set, we only build against the
# installed FFmpeg. We don't know what FFmpeg version that is, so we build
# `libtorchcodec.so` without any version suffix. We could probably figure out
# the version number by invoking `pkg-config --modversion`.
FFMPEG_MAJOR_VERSIONS = (
(4, 5, 6, 7) if os.getenv("BUILD_AGAINST_ALL_FFMPEG_FROM_S3") is not None else ("",)
)
FFMPEG_MAJOR_VERSIONS = (4, 5, 6, 7) if build_against_all_ffmpeg_from_s3 else ("",)
extensions = [
Extension(
# The names here must be kept in sync with the target names in the
Expand Down

0 comments on commit e1e0352

Please sign in to comment.