Skip to content

Commit 39faf36

Browse files
committed
Refactor version retrieval to use importlib.metadata for improved reliability
1 parent 1cb4150 commit 39faf36

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

trl/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from importlib.metadata import PackageNotFoundError, version
1516
from pathlib import Path
1617
from typing import TYPE_CHECKING
1718

1819
from .import_utils import OptionalDependencyNotAvailable, _LazyModule, is_diffusers_available
1920

2021

21-
# Read version from VERSION file
22-
_version_file = Path(__file__).parent.parent / "VERSION"
2322
try:
24-
with open(_version_file, encoding="utf-8") as f:
25-
__version__ = f.read().strip()
26-
except FileNotFoundError:
23+
__version__ = version("trl")
24+
except PackageNotFoundError:
2725
__version__ = "unknown"
2826

2927
_import_structure = {

0 commit comments

Comments
 (0)