Skip to content

Commit

Permalink
Fix version
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasHug committed Nov 11, 2024
1 parent 3feb1a5 commit fdd5518
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ dist/
*/**/*~
*~

torchvision_extra_decoders/version.py

docs/build
# sphinx-gallery
docs/source/auto_examples/
Expand Down
32 changes: 31 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,43 @@
# GNU Lesser General Public License version 2.

import os
import subprocess
import sys
from pathlib import Path

from setuptools import find_packages, setup

from torch.utils.cpp_extension import BuildExtension, CppExtension

ROOT_DIR = Path(__file__).absolute().parent


# Same version logic as in torchvision
def get_and_write_version():
with open(ROOT_DIR / "version.txt") as f:
version = f.readline().strip()
sha = "Unknown"

try:
sha = (
subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=str(ROOT_DIR))
.decode("ascii")
.strip()
)
except Exception:
pass

if os.getenv("BUILD_VERSION"):
version = os.getenv("BUILD_VERSION")
elif sha != "Unknown":
version += "+" + sha[:7]

with open(ROOT_DIR / "torchvision_extra_decoders/version.py", "w") as f:
f.write(f"__version__ = '{version}'\n")
f.write(f"git_version = {repr(sha)}\n")

return version


def find_library(header):
# returns (found, include dir, library dir)
Expand Down Expand Up @@ -92,7 +122,7 @@ def get_requirements():

setup(
name=PACKAGE_NAME,
version="0.0.1.dev",
version=get_and_write_version(),
author="PyTorch Team",
author_email="[email protected]",
url="TODO",
Expand Down
5 changes: 5 additions & 0 deletions torchvision_extra_decoders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

import torch

try:
from .version import __version__ # noqa: F401
except ImportError:
pass


def expose_extra_decoders():
suffix = ".so" # TODO: make this cross-platform
Expand Down
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1.dev

0 comments on commit fdd5518

Please sign in to comment.