From 79720f173d6d906ce33e9cdfa3566ca2392383ee Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 13 Nov 2024 10:47:54 +0000 Subject: [PATCH 01/15] Let wheel names get the proper platform suffix --- .gitignore | 2 ++ setup.py | 37 ++++++++++++++++++++++++++++++++++++- src/torchcodec/__init__.py | 2 +- test/test_version.py | 6 ++++++ version.txt | 1 + 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 test/test_version.py create mode 100644 version.txt diff --git a/.gitignore b/.gitignore index 51bb5da3e..897bc09e3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ src/TorchCodec.egg-info/ *~ frame180.* # output from smoke test +src/torchcodec/version.py + docs/build # sphinx-gallery docs/source/generated_examples/ diff --git a/setup.py b/setup.py index 09690b321..59e9ed7f1 100644 --- a/setup.py +++ b/setup.py @@ -170,4 +170,39 @@ def copy_extensions_to_source(self): # See `CMakeBuild.build_extension()`. fake_extension = Extension(name="FAKE_NAME", sources=[]) -setup(ext_modules=[fake_extension], cmdclass={"build_ext": CMakeBuild}) + + +def get_and_write_version(): + if os.getenv("BUILD_VERSION"): + # BUILD_VERSION is set by the `test-infra` build jobs. It typically is + # the content of `version.txt` plus some suffix like "+cpu" or "+cu112". + # See + # https://github.com/pytorch/test-infra/blob/61e6da7a6557152eb9879e461a26ad667c15f0fd/tools/pkg-helpers/pytorch_pkg_helpers/version.py#L113 + version = os.getenv("BUILD_VERSION") + else: + with open(_ROOT_DIR / "version.txt") as f: + version = f.readline().strip() + + try: + sha = ( + subprocess.check_output( + ["git", "rev-parse", "HEAD"], cwd=str(_ROOT_DIR) + ) + .decode("ascii") + .strip() + ) + version += "+" + sha[:7] + except Exception: + print("INFO: Didn't find sha. Is this a git repo?") + + with open(_ROOT_DIR / "src/torchcodec/version.py", "w") as f: + f.write(f"__version__ = '{version}'\n") + + return version + + +setup( + version=get_and_write_version(), + ext_modules=[fake_extension], + cmdclass={"build_ext": CMakeBuild}, +) diff --git a/src/torchcodec/__init__.py b/src/torchcodec/__init__.py index a27a83e04..0195135a7 100644 --- a/src/torchcodec/__init__.py +++ b/src/torchcodec/__init__.py @@ -9,4 +9,4 @@ from ._frame import Frame, FrameBatch # usort:skip # noqa from . import decoders, samplers # noqa -__version__ = "0.0.4.dev" +from .version import __version__ # noqa: F401 diff --git a/test/test_version.py b/test/test_version.py new file mode 100644 index 000000000..396cbc98c --- /dev/null +++ b/test/test_version.py @@ -0,0 +1,6 @@ +import torchcodec + + +def test_version(): + # Basic test to make sure the attribute exists and is not empty + assert torchcodec.__version__ diff --git a/version.txt b/version.txt new file mode 100644 index 000000000..c730b7f47 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.0.4a0 From f0025c3f8fddcac41022b53de574769d97d39293 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 13 Nov 2024 11:00:36 +0000 Subject: [PATCH 02/15] Fix? --- setup.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/setup.py b/setup.py index 59e9ed7f1..7e7e515db 100644 --- a/setup.py +++ b/setup.py @@ -172,14 +172,13 @@ def copy_extensions_to_source(self): fake_extension = Extension(name="FAKE_NAME", sources=[]) -def get_and_write_version(): - if os.getenv("BUILD_VERSION"): - # BUILD_VERSION is set by the `test-infra` build jobs. It typically is - # the content of `version.txt` plus some suffix like "+cpu" or "+cu112". - # See - # https://github.com/pytorch/test-infra/blob/61e6da7a6557152eb9879e461a26ad667c15f0fd/tools/pkg-helpers/pytorch_pkg_helpers/version.py#L113 - version = os.getenv("BUILD_VERSION") - else: +def get_version(): + # BUILD_VERSION is set by the `test-infra` build jobs. It typically is + # the content of `version.txt` plus some suffix like "+cpu" or "+cu112". + # See + # https://github.com/pytorch/test-infra/blob/61e6da7a6557152eb9879e461a26ad667c15f0fd/tools/pkg-helpers/pytorch_pkg_helpers/version.py#L113 + version = os.getenv("BUILD_VERSION") + if not version: with open(_ROOT_DIR / "version.txt") as f: version = f.readline().strip() @@ -195,14 +194,19 @@ def get_and_write_version(): except Exception: print("INFO: Didn't find sha. Is this a git repo?") + return version + + +def write_version_file(version): with open(_ROOT_DIR / "src/torchcodec/version.py", "w") as f: f.write(f"__version__ = '{version}'\n") - return version +version = get_version() +write_version_file(version) setup( - version=get_and_write_version(), + version=version, ext_modules=[fake_extension], cmdclass={"build_ext": CMakeBuild}, ) From 46effd613c4cbebd82439ca585e9378cebac073e Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 13 Nov 2024 11:16:58 +0000 Subject: [PATCH 03/15] Hack --- src/torchcodec/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/torchcodec/__init__.py b/src/torchcodec/__init__.py index 0195135a7..b78f3b794 100644 --- a/src/torchcodec/__init__.py +++ b/src/torchcodec/__init__.py @@ -9,4 +9,7 @@ from ._frame import Frame, FrameBatch # usort:skip # noqa from . import decoders, samplers # noqa -from .version import __version__ # noqa: F401 +__version__ = "1.2.2" +# try: +# from .version import __version__ # noqa: F401 + From b1e73bf087416a94640ca75330ad9956247760e9 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 13 Nov 2024 11:19:28 +0000 Subject: [PATCH 04/15] hack again? --- src/torchcodec/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/torchcodec/__init__.py b/src/torchcodec/__init__.py index b78f3b794..97f00c56e 100644 --- a/src/torchcodec/__init__.py +++ b/src/torchcodec/__init__.py @@ -9,7 +9,7 @@ from ._frame import Frame, FrameBatch # usort:skip # noqa from . import decoders, samplers # noqa -__version__ = "1.2.2" -# try: -# from .version import __version__ # noqa: F401 - +try: + from .version import __version__ # noqa: F401 +except ImportError: + pass From 109a7ed8c8600eae9aa530f9c61c8dde6c23ea60 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 13 Nov 2024 11:24:27 +0000 Subject: [PATCH 05/15] :( --- src/torchcodec/__init__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/torchcodec/__init__.py b/src/torchcodec/__init__.py index 97f00c56e..f3fff8d6f 100644 --- a/src/torchcodec/__init__.py +++ b/src/torchcodec/__init__.py @@ -9,7 +9,4 @@ from ._frame import Frame, FrameBatch # usort:skip # noqa from . import decoders, samplers # noqa -try: - from .version import __version__ # noqa: F401 -except ImportError: - pass +__version__ = "0.0.1" From d19fc84e020c5fc88848d3fa4324157a9d5dfed5 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 13 Nov 2024 11:33:22 +0000 Subject: [PATCH 06/15] try --- src/torchcodec/__init__.py | 8 +++++++- test/test_version.py | 3 +-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/torchcodec/__init__.py b/src/torchcodec/__init__.py index f3fff8d6f..3ea5d94b5 100644 --- a/src/torchcodec/__init__.py +++ b/src/torchcodec/__init__.py @@ -9,4 +9,10 @@ from ._frame import Frame, FrameBatch # usort:skip # noqa from . import decoders, samplers # noqa -__version__ = "0.0.1" + +__version__ = "0.0.0" # Fake version, just makes sure wheel building works + +try: + from .version import __version__ # noqa: F401 +except ImportError: + pass diff --git a/test/test_version.py b/test/test_version.py index 396cbc98c..36901d11e 100644 --- a/test/test_version.py +++ b/test/test_version.py @@ -2,5 +2,4 @@ def test_version(): - # Basic test to make sure the attribute exists and is not empty - assert torchcodec.__version__ + assert torchcodec.__version__ != "0.0.0" From 4d1376ccce8649d9d42f0f80e6c5440469338473 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 13 Nov 2024 13:15:26 +0000 Subject: [PATCH 07/15] AAAG --- packaging/post_build_script.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packaging/post_build_script.sh b/packaging/post_build_script.sh index ca8fd1337..6d67b1d2d 100755 --- a/packaging/post_build_script.sh +++ b/packaging/post_build_script.sh @@ -8,6 +8,12 @@ wheel_path=$(pwd)/$(find dist -type f -name "*.whl") echo "Wheel content:" unzip -l $wheel_path +if [[ "$wheel_path" == *"0.0.0"* ]]; then + echo "Wrong wheel version :'(" + exit 1 +fi + + unamestr=$(uname) if [[ "$unamestr" == 'Linux' ]]; then ext="so" From 0f6a5e34da85eb6b1c7f3a01f85327a709a00cc4 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 13 Nov 2024 13:19:45 +0000 Subject: [PATCH 08/15] Fix? --- setup.py | 2 +- src/torchcodec/__init__.py | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 7e7e515db..5ff6afca6 100644 --- a/setup.py +++ b/setup.py @@ -199,7 +199,7 @@ def get_version(): def write_version_file(version): with open(_ROOT_DIR / "src/torchcodec/version.py", "w") as f: - f.write(f"__version__ = '{version}'\n") + f.write(f"def _get_version(): return '{version}'\n") version = get_version() diff --git a/src/torchcodec/__init__.py b/src/torchcodec/__init__.py index 3ea5d94b5..93f8f90a6 100644 --- a/src/torchcodec/__init__.py +++ b/src/torchcodec/__init__.py @@ -9,10 +9,6 @@ from ._frame import Frame, FrameBatch # usort:skip # noqa from . import decoders, samplers # noqa +from .version import _get_version -__version__ = "0.0.0" # Fake version, just makes sure wheel building works - -try: - from .version import __version__ # noqa: F401 -except ImportError: - pass +__version__ = _get_version() From 6bd6ed95cb2b94e8431e888b4d62f9917468ba94 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 13 Nov 2024 13:22:08 +0000 Subject: [PATCH 09/15] AAAAAAAAAAAH --- src/torchcodec/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/torchcodec/__init__.py b/src/torchcodec/__init__.py index 93f8f90a6..ae784deba 100644 --- a/src/torchcodec/__init__.py +++ b/src/torchcodec/__init__.py @@ -11,4 +11,7 @@ from .version import _get_version -__version__ = _get_version() +try: + __version__ = _get_version() +except Exception: + __version__ = "0.0.0" From b20500d8e26b244f01d1ccb4f490026fd9a38c2c Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 13 Nov 2024 13:31:43 +0000 Subject: [PATCH 10/15] aa --- src/torchcodec/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/torchcodec/__init__.py b/src/torchcodec/__init__.py index ae784deba..88da57ff0 100644 --- a/src/torchcodec/__init__.py +++ b/src/torchcodec/__init__.py @@ -14,4 +14,4 @@ try: __version__ = _get_version() except Exception: - __version__ = "0.0.0" + pass From 137dc73dd779cc605cc3ad4bf994e582c6f6f36c Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 13 Nov 2024 14:25:12 +0000 Subject: [PATCH 11/15] UOJEFGOJAENFJANEF --- pyproject.toml | 2 +- setup.py | 24 +++++++++++------------- src/torchcodec/__init__.py | 7 +------ test/test_version.py | 3 ++- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 058b71e71..cc94d8d85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ GitHub = "https://github.com/pytorch/torchcodec" Documentation = "https://pytorch.org/torchcodec/stable/index.html" [tool.setuptools.dynamic] -version = {attr = "torchcodec.__version__"} +version = {file = "version.txt"} [build-system] requires = ["setuptools>=61.0"] diff --git a/setup.py b/setup.py index 5ff6afca6..7952d2eec 100644 --- a/setup.py +++ b/setup.py @@ -173,15 +173,16 @@ def copy_extensions_to_source(self): def get_version(): - # BUILD_VERSION is set by the `test-infra` build jobs. It typically is - # the content of `version.txt` plus some suffix like "+cpu" or "+cu112". - # See - # https://github.com/pytorch/test-infra/blob/61e6da7a6557152eb9879e461a26ad667c15f0fd/tools/pkg-helpers/pytorch_pkg_helpers/version.py#L113 - version = os.getenv("BUILD_VERSION") - if not version: + if version := os.getenv("BUILD_VERSION"): + # BUILD_VERSION is set by the `test-infra` build jobs. It typically is + # the content of `version.txt` plus some suffix like "+cpu" or "+cu112". + # See + # https://github.com/pytorch/test-infra/blob/61e6da7a6557152eb9879e461a26ad667c15f0fd/tools/pkg-helpers/pytorch_pkg_helpers/version.py#L113 + with open(_ROOT_DIR / "version.txt", "w") as f: + f.write(f"{version}") + else: with open(_ROOT_DIR / "version.txt") as f: version = f.readline().strip() - try: sha = ( subprocess.check_output( @@ -194,16 +195,13 @@ def get_version(): except Exception: print("INFO: Didn't find sha. Is this a git repo?") - return version - + with open(_ROOT_DIR / "src/torchcodec/version.py") as f: + f.write(f"__version__ = '{version}'\n") -def write_version_file(version): - with open(_ROOT_DIR / "src/torchcodec/version.py", "w") as f: - f.write(f"def _get_version(): return '{version}'\n") + return version version = get_version() -write_version_file(version) setup( version=version, diff --git a/src/torchcodec/__init__.py b/src/torchcodec/__init__.py index 88da57ff0..f9fd9751f 100644 --- a/src/torchcodec/__init__.py +++ b/src/torchcodec/__init__.py @@ -9,9 +9,4 @@ from ._frame import Frame, FrameBatch # usort:skip # noqa from . import decoders, samplers # noqa -from .version import _get_version - -try: - __version__ = _get_version() -except Exception: - pass +from .version import __version__ diff --git a/test/test_version.py b/test/test_version.py index 36901d11e..a17fcc649 100644 --- a/test/test_version.py +++ b/test/test_version.py @@ -2,4 +2,5 @@ def test_version(): - assert torchcodec.__version__ != "0.0.0" + assert "+cpu" not in torchcodec.__version__ + assert "+cu" not in torchcodec.__version__ From 7b7293bd55c6dbcdd4bf5f6aee3921ada9b56a1f Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Wed, 13 Nov 2024 14:25:47 +0000 Subject: [PATCH 12/15] AEJFNAJENF --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7952d2eec..7fc680b0c 100644 --- a/setup.py +++ b/setup.py @@ -195,7 +195,7 @@ def get_version(): except Exception: print("INFO: Didn't find sha. Is this a git repo?") - with open(_ROOT_DIR / "src/torchcodec/version.py") as f: + with open(_ROOT_DIR / "src/torchcodec/version.py", "w") as f: f.write(f"__version__ = '{version}'\n") return version From fbb1ee017ec3d0c322927c75b5735b83fde5f159 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Mon, 18 Nov 2024 09:58:51 +0000 Subject: [PATCH 13/15] Try --- setup.py | 11 ++++------- src/torchcodec/__init__.py | 5 ++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 7fc680b0c..7909af77e 100644 --- a/setup.py +++ b/setup.py @@ -172,7 +172,7 @@ def copy_extensions_to_source(self): fake_extension = Extension(name="FAKE_NAME", sources=[]) -def get_version(): +def set_version(): if version := os.getenv("BUILD_VERSION"): # BUILD_VERSION is set by the `test-infra` build jobs. It typically is # the content of `version.txt` plus some suffix like "+cpu" or "+cu112". @@ -195,16 +195,13 @@ def get_version(): except Exception: print("INFO: Didn't find sha. Is this a git repo?") - with open(_ROOT_DIR / "src/torchcodec/version.py", "w") as f: - f.write(f"__version__ = '{version}'\n") + with open(_ROOT_DIR / "src/torchcodec/version.py", "w") as f: + f.write(f"__version__ = '{version}'\n") - return version - -version = get_version() +set_version() setup( - version=version, ext_modules=[fake_extension], cmdclass={"build_ext": CMakeBuild}, ) diff --git a/src/torchcodec/__init__.py b/src/torchcodec/__init__.py index f9fd9751f..2b83eb035 100644 --- a/src/torchcodec/__init__.py +++ b/src/torchcodec/__init__.py @@ -9,4 +9,7 @@ from ._frame import Frame, FrameBatch # usort:skip # noqa from . import decoders, samplers # noqa -from .version import __version__ +try: + from .version import __version__ # noqa: F401 +except Exception: + pass From 18e573bd6a2d12f540f69e472a40c24a57e06f53 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Mon, 18 Nov 2024 10:31:44 +0000 Subject: [PATCH 14/15] Fix test --- packaging/post_build_script.sh | 6 ------ setup.py | 4 ++-- test/test_version.py | 3 +-- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/packaging/post_build_script.sh b/packaging/post_build_script.sh index 6d67b1d2d..ca8fd1337 100755 --- a/packaging/post_build_script.sh +++ b/packaging/post_build_script.sh @@ -8,12 +8,6 @@ wheel_path=$(pwd)/$(find dist -type f -name "*.whl") echo "Wheel content:" unzip -l $wheel_path -if [[ "$wheel_path" == *"0.0.0"* ]]; then - echo "Wrong wheel version :'(" - exit 1 -fi - - unamestr=$(uname) if [[ "$unamestr" == 'Linux' ]]; then ext="so" diff --git a/setup.py b/setup.py index 7909af77e..7588c000f 100644 --- a/setup.py +++ b/setup.py @@ -172,7 +172,7 @@ def copy_extensions_to_source(self): fake_extension = Extension(name="FAKE_NAME", sources=[]) -def set_version(): +def _write_version_files(): if version := os.getenv("BUILD_VERSION"): # BUILD_VERSION is set by the `test-infra` build jobs. It typically is # the content of `version.txt` plus some suffix like "+cpu" or "+cu112". @@ -199,7 +199,7 @@ def set_version(): f.write(f"__version__ = '{version}'\n") -set_version() +_write_version_files() setup( ext_modules=[fake_extension], diff --git a/test/test_version.py b/test/test_version.py index a17fcc649..2f7d659c8 100644 --- a/test/test_version.py +++ b/test/test_version.py @@ -2,5 +2,4 @@ def test_version(): - assert "+cpu" not in torchcodec.__version__ - assert "+cu" not in torchcodec.__version__ + assert torchcodec.__version__ From d0eafbff2d560dfeeb42dc1ecb7525ede2a9573a Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Mon, 18 Nov 2024 10:44:39 +0000 Subject: [PATCH 15/15] Add version print --- test/decoders/manual_smoke_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/decoders/manual_smoke_test.py b/test/decoders/manual_smoke_test.py index 562b3d128..6bdc91ff2 100644 --- a/test/decoders/manual_smoke_test.py +++ b/test/decoders/manual_smoke_test.py @@ -9,6 +9,8 @@ import torchcodec from torchvision.io.image import write_png +print(f"{torchcodec.__version__ = }") + decoder = torchcodec.decoders._core.create_from_file( str(Path(__file__).parent / "../resources/nasa_13013.mp4") )