Skip to content

Commit 095599a

Browse files
authored
Let wheel names get the proper platform suffix (#366)
1 parent 5106161 commit 095599a

File tree

7 files changed

+50
-3
lines changed

7 files changed

+50
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ src/TorchCodec.egg-info/
1010
*~
1111
frame180.* # output from smoke test
1212

13+
src/torchcodec/version.py
14+
1315
docs/build
1416
# sphinx-gallery
1517
docs/source/generated_examples/

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ GitHub = "https://github.com/pytorch/torchcodec"
1414
Documentation = "https://pytorch.org/torchcodec/stable/index.html"
1515

1616
[tool.setuptools.dynamic]
17-
version = {attr = "torchcodec.__version__"}
17+
version = {file = "version.txt"}
1818

1919
[build-system]
2020
requires = ["setuptools>=61.0"]

setup.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,38 @@ def copy_extensions_to_source(self):
170170

171171
# See `CMakeBuild.build_extension()`.
172172
fake_extension = Extension(name="FAKE_NAME", sources=[])
173-
setup(ext_modules=[fake_extension], cmdclass={"build_ext": CMakeBuild})
173+
174+
175+
def _write_version_files():
176+
if version := os.getenv("BUILD_VERSION"):
177+
# BUILD_VERSION is set by the `test-infra` build jobs. It typically is
178+
# the content of `version.txt` plus some suffix like "+cpu" or "+cu112".
179+
# See
180+
# https://github.com/pytorch/test-infra/blob/61e6da7a6557152eb9879e461a26ad667c15f0fd/tools/pkg-helpers/pytorch_pkg_helpers/version.py#L113
181+
with open(_ROOT_DIR / "version.txt", "w") as f:
182+
f.write(f"{version}")
183+
else:
184+
with open(_ROOT_DIR / "version.txt") as f:
185+
version = f.readline().strip()
186+
try:
187+
sha = (
188+
subprocess.check_output(
189+
["git", "rev-parse", "HEAD"], cwd=str(_ROOT_DIR)
190+
)
191+
.decode("ascii")
192+
.strip()
193+
)
194+
version += "+" + sha[:7]
195+
except Exception:
196+
print("INFO: Didn't find sha. Is this a git repo?")
197+
198+
with open(_ROOT_DIR / "src/torchcodec/version.py", "w") as f:
199+
f.write(f"__version__ = '{version}'\n")
200+
201+
202+
_write_version_files()
203+
204+
setup(
205+
ext_modules=[fake_extension],
206+
cmdclass={"build_ext": CMakeBuild},
207+
)

src/torchcodec/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@
99
from ._frame import Frame, FrameBatch # usort:skip # noqa
1010
from . import decoders, samplers # noqa
1111

12-
__version__ = "0.0.4.dev"
12+
try:
13+
from .version import __version__ # noqa: F401
14+
except Exception:
15+
pass

test/decoders/manual_smoke_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import torchcodec
1010
from torchvision.io.image import write_png
1111

12+
print(f"{torchcodec.__version__ = }")
13+
1214
decoder = torchcodec.decoders._core.create_from_file(
1315
str(Path(__file__).parent / "../resources/nasa_13013.mp4")
1416
)

test/test_version.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import torchcodec
2+
3+
4+
def test_version():
5+
assert torchcodec.__version__

version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.4a0

0 commit comments

Comments
 (0)