Skip to content

Commit 79720f1

Browse files
committed
Let wheel names get the proper platform suffix
1 parent b43fadb commit 79720f1

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
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/

setup.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,39 @@ 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 get_and_write_version():
176+
if 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+
version = os.getenv("BUILD_VERSION")
182+
else:
183+
with open(_ROOT_DIR / "version.txt") as f:
184+
version = f.readline().strip()
185+
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+
return version
202+
203+
204+
setup(
205+
version=get_and_write_version(),
206+
ext_modules=[fake_extension],
207+
cmdclass={"build_ext": CMakeBuild},
208+
)

src/torchcodec/__init__.py

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

12-
__version__ = "0.0.4.dev"
12+
from .version import __version__ # noqa: F401

test/test_version.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import torchcodec
2+
3+
4+
def test_version():
5+
# Basic test to make sure the attribute exists and is not empty
6+
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)