Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/executorch/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

"""ExecuTorch: A unified ML stack for on-device inference."""

try:
# ``version.py`` is generated at build time from ``version.txt`` (the single
# source of truth) by ``setup.py``, mirroring ``torch/version.py``.
from .version import __version__, git_version # noqa: F401
except ModuleNotFoundError:
# No generated ``version.py`` (e.g. an unbuilt source tree): fall back to the
# installed distribution metadata, then to a sentinel, so ``import executorch``
# never fails just because the version is unknown. A malformed (present but
# broken) ``version.py`` still raises, surfacing real packaging problems.
try:
from importlib.metadata import PackageNotFoundError, version as _version

try:
__version__ = _version("executorch")
except PackageNotFoundError:
__version__ = "0.0.0+unknown"
except Exception:
__version__ = "0.0.0+unknown"
git_version = None

__all__ = ["__version__", "git_version"]
19 changes: 19 additions & 0 deletions test/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import unittest


class VersionTest(unittest.TestCase):
def test_version_attributes_exposed(self) -> None:
# ``import executorch`` must succeed and expose the conventional
# ``__version__``/``git_version`` attributes (resolved from the generated
# version.py, or a graceful fallback in an unbuilt source tree).
import executorch

self.assertIsInstance(executorch.__version__, str)
self.assertTrue(executorch.__version__)
self.assertTrue(hasattr(executorch, "git_version"))
Loading