-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
|
||
import pkg_resources | ||
# Updated imports | ||
from importlib.metadata import version, PackageNotFoundError | ||
from injector import inject | ||
from packaging.version import Version | ||
|
||
from mobt.VersionChecker import version_checker_logger | ||
from mobt.VersionChecker.Suppliers.SupplierInterface import SupplierInterface | ||
|
||
|
||
@inject | ||
@dataclass(frozen=True) | ||
class LocalInstallation(SupplierInterface): | ||
|
||
def get_version(self) -> Optional[Version]: | ||
version = pkg_resources.get_distribution('mob-tool').version | ||
version_checker_logger().debug(f'Version installed locally: {version}') | ||
try: | ||
# Using importlib.metadata.version to get the package version | ||
version_str = version('mob-tool') | ||
version_checker_logger().debug(f'Version installed locally: {version_str}') | ||
|
||
return Version(version) | ||
return Version(version_str) | ||
except PackageNotFoundError: | ||
# Handle the case where the package is not found | ||
version_checker_logger().debug('mob-tool package not found locally.') | ||
return None |