Skip to content

Commit

Permalink
[torchcodec] Add rudimentary support for OSX build
Browse files Browse the repository at this point in the history
Summary: After these changes I was able to install and run torchcodec on my OSX laptop.

Reviewed By: scotts

Differential Revision: D59065917

fbshipit-source-id: c1025f6c0cbd60de9dc95d7d9cc501b1bf5ad3a6
  • Loading branch information
ahmadsharif1 authored and facebook-github-bot committed Jun 26, 2024
1 parent 0de0c5e commit d4c35f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
13 changes: 11 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,17 @@ def copy_extensions_to_source(self):
This is called by setuptools at the end of .run() during editable installs.
"""
self.get_finalized_command("build_py")

for so_file in self._install_prefix.glob("*.so"):
extension = ""
if sys.platform == "linux":
extension = "so"
elif sys.platform == "darwin":
extension = "dylib"
else:
raise NotImplementedError(
"Platforms other than linux/darwin are not supported yet"
)

for so_file in self._install_prefix.glob(f"*.{extension}"):
assert "libtorchcodec" in so_file.name
destination = Path("src/torchcodec/") / so_file.name
print(f"Copying {so_file} to {destination}")
Expand Down
12 changes: 11 additions & 1 deletion src/torchcodec/_internally_replaced_utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import importlib
import os
import sys


# Copy pasted from torchvision
# https://github.com/pytorch/vision/blob/947ae1dc71867f28021d5bc0ff3a19c249236e2a/torchvision/_internally_replaced_utils.py#L25
def _get_extension_path(lib_name):
lib_dir = os.path.dirname(__file__)
extension_suffixes = []
if sys.platform == "linux":
extension_suffixes = importlib.machinery.EXTENSION_SUFFIXES
elif sys.platform == "darwin":
extension_suffixes = importlib.machinery.EXTENSION_SUFFIXES + [".dylib"]
else:
raise NotImplementedError(
"Platforms other than linux/darwin are not supported yet"
)
loader_details = (
importlib.machinery.ExtensionFileLoader,
importlib.machinery.EXTENSION_SUFFIXES,
extension_suffixes,
)

extfinder = importlib.machinery.FileFinder(lib_dir, loader_details)
Expand Down

0 comments on commit d4c35f1

Please sign in to comment.