Skip to content
Merged
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
10 changes: 8 additions & 2 deletions src/fosslight_util/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import sys
import pkg_resources
try:
from importlib.metadata import version, PackageNotFoundError
except ImportError:
from importlib_metadata import version, PackageNotFoundError # Python <3.8

_HELP_MESSAGE_COMMON = """
_______ _______ _______ _______ ___ ___ __
Expand Down Expand Up @@ -50,7 +53,10 @@ def print_help_msg(self, exitopt: bool) -> None:
def print_package_version(pkg_name: str, msg: str = "", exitopt: bool = True) -> str:
if msg == "":
msg = f"{pkg_name} Version:"
cur_version = pkg_resources.get_distribution(pkg_name).version
try:
cur_version = version(pkg_name)
except PackageNotFoundError:
cur_version = "unknown"

if exitopt:
print(f'{msg} {cur_version}')
Expand Down
10 changes: 8 additions & 2 deletions src/fosslight_util/set_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import logging
import os
from pathlib import Path
import pkg_resources
import sys
import platform
from . import constant as constant
Expand All @@ -15,6 +14,11 @@
from typing import Tuple
from logging import Logger

try:
from importlib.metadata import version, PackageNotFoundError
except ImportError:
from importlib_metadata import version, PackageNotFoundError # Python <3.8


def init_check_latest_version(pkg_version="", main_package_name=""):

Expand Down Expand Up @@ -92,9 +96,11 @@ def init_log(log_file: str, create_file: bool = True, stream_log_level: int = lo
if main_package_name != "":
pkg_info = main_package_name
try:
pkg_version = pkg_resources.get_distribution(main_package_name).version
pkg_version = version(main_package_name)
init_check_latest_version(pkg_version, main_package_name)
pkg_info = main_package_name + " v" + pkg_version
except PackageNotFoundError:
logger.debug('Cannot check the version: Package not found')
except Exception as error:
logger.debug('Cannot check the version:' + str(error))
_result_log["Tool Info"] = pkg_info
Expand Down