Skip to content

Commit

Permalink
wip, working but needs testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwal committed Dec 13, 2024
1 parent 5b1caf9 commit e06867e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 145 deletions.
41 changes: 41 additions & 0 deletions vpdq/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# CMake to build the Python binding for vpdq. This is built with the Python scikit-build-core build backend.
# This compiles vpdq and compiles the Cython and then links vpdq to the compiled Cython.

cmake_minimum_required(VERSION 3.15...3.30)
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ version selection")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Compile pdq and vpdq to produce their library files.
add_subdirectory(cpp)

# Build the Cython bindings.
# Create the cpp file from the Cython pyx file, compile it, and link it to vpdq.

find_package(
Python
COMPONENTS Interpreter Development.Module
REQUIRED)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/python/vpdq.cpp
COMMENT
"Making ${CMAKE_CURRENT_BINARY_DIR}/python/vpdq.cpp from ${CMAKE_CURRENT_SOURCE_DIR}/python/vpdq.pyx"
COMMAND Python::Interpreter -m cython
"${CMAKE_CURRENT_SOURCE_DIR}/python/vpdq.pyx" --output-file "${CMAKE_CURRENT_SOURCE_DIR}/python/vpdq.cpp"
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/python/vpdq.pyx
VERBATIM)

python_add_library(vpdq MODULE ${CMAKE_CURRENT_SOURCE_DIR}/python/vpdq.cpp WITH_SOABI)

# Link pdq and vpdq to the vpdq Cython library
target_link_libraries(vpdq PUBLIC pdqlib)
target_link_libraries(vpdq PUBLIC vpdqlib)

# Note: The install directory determines the module directory.
# For example, if it's changed to 'foo', then in python you would have to do
# 'from foo import vpdq' to use the module.
# Leaving it at '.' allows for just 'import vpdq'.
install(TARGETS vpdq DESTINATION .)
1 change: 0 additions & 1 deletion vpdq/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ include README.md

graft cpp
prune cpp/build
exclude cpp/libraries-dirs.txt

graft python
6 changes: 0 additions & 6 deletions vpdq/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,3 @@ add_subdirectory(vpdq)
# CLI programs
# TODO: Make this a custom command/option. This isn't necessary to just build the library.
add_subdirectory(apps)

# Write the libav* library dirs to a new-line delimited file for Cython to be able to locate LIBAV files
# TODO: Make this a custom command or something. This isn't necessary on every run.
string(REPLACE ";" "\n" LIBRARY_DIRS "${LIBAV_STATIC_LIBRARY_DIRS}")
set(LIBRARY_DIRS_FILE "libraries-dirs.txt")
file(WRITE ${LIBRARY_DIRS_FILE} "${LIBRARY_DIRS}")
25 changes: 11 additions & 14 deletions vpdq/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
[build-system]
requires = [
"setuptools >= 61.0",
"wheel",
"cython",
"cmake",
]
build-backend = "setuptools.build_meta"
requires = ["scikit-build-core", "cython"]
build-backend = "scikit_build_core.build"

[project]
name = "vpdq"
Expand All @@ -16,11 +11,13 @@ readme = {file = "python/README.md", content-type = "text/markdown"}
license = {file = "LICENSE.txt"}
dynamic = ["version", "scripts", "entry-points"]

[tool.setuptools]
include-package-data = true
[tool.scikit-build.metadata.version]
provider = "scikit_build_core.metadata.regex"
input = "version.txt"

[tool.setuptools.packages.find]
where = ["python"] # list of folders that contain the packages (["."] by default)
include = ["vpdq.pyx"] # package names should match these glob patterns (["*"] by default)
exclude = [] # exclude packages matching these glob patterns (empty by default)
namespaces = false # to disable scanning PEP 420 namespaces (true by default)
# Regex explanation:
# ^ matches the start of the line.
# ?P<value> is the named capture group with the name value. scikit is expecting this.
# \S+ matches any non-whitespace characters, assuming the version is a single token.
# $ ensures the match ends at the end of the line.
regex = "^(?P<value>\\S+)$"
124 changes: 0 additions & 124 deletions vpdq/setup.py

This file was deleted.

0 comments on commit e06867e

Please sign in to comment.