Skip to content

Commit

Permalink
Update to use python system logger in license_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
netsettler committed Jul 28, 2023
1 parent 663616f commit 902f5c6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
15 changes: 8 additions & 7 deletions dcicutils/license_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import datetime
import io
import json
import logging
# import logging
import os
import re
import subprocess
import warnings

try:
import piplicenses
Expand All @@ -30,8 +31,8 @@
from dcicutils.misc_utils import PRINT, get_error_message, local_attrs


logging.basicConfig()
logger = logging.getLogger(__name__)
# logging.basicConfig()
# logger = logging.getLogger(__name__)

_FRAMEWORK = 'framework'
_LANGUAGE = 'language'
Expand Down Expand Up @@ -270,7 +271,7 @@ def report(message):
if analysis:
analysis.miscellaneous.append(message)
else:
logger.warning(message)
warnings.warn(message)
parsed = cls.parse_simple_license_file(filename=filename)
if check_license_title:
license_title = parsed['license-title']
Expand Down Expand Up @@ -488,11 +489,11 @@ class MyOrgLicenseChecker(LicenseChecker):
cls.analyze_license_file(analysis=analysis)
cls.show_unacceptable_licenses(analysis=analysis)
if analysis.unexpected_missing:
logger.warning(there_are(analysis.unexpected_missing, kind='unexpectedly missing license', punctuate=True))
warnings.warn(there_are(analysis.unexpected_missing, kind='unexpectedly missing license', punctuate=True))
if analysis.no_longer_missing:
logger.warning(there_are(analysis.no_longer_missing, kind='no-longer-missing license', punctuate=True))
warnings.warn(there_are(analysis.no_longer_missing, kind='no-longer-missing license', punctuate=True))
for message in analysis.miscellaneous:
logger.warning(message)
warnings.warn(message)
if analysis.unacceptable:
raise LicenseAcceptabilityCheckFailure(unacceptable_licenses=analysis.unacceptable)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "7.6.0.2b5"
version = "7.6.0.2b6"
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down
8 changes: 4 additions & 4 deletions test/test_license_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
LicenseFrameworkRegistry, LicenseFramework, PythonLicenseFramework, JavascriptLicenseFramework,
LicenseAnalysis, LicenseChecker, LicenseStatus, LicenseFileParser,
LicenseCheckFailure, LicenseOwnershipCheckFailure, LicenseAcceptabilityCheckFailure,
logger as license_logger,
warnings as license_utils_warnings_module,
)
from dcicutils.misc_utils import ignored, file_contents
from dcicutils.qa_utils import printed_output, MockFileSystem
Expand Down Expand Up @@ -371,7 +371,7 @@ def check_license_checker_full_scenario_failing(*, perturb_setup, checker,
file=fp)
print(license_text_for_testing, file=fp)

with mock.patch.object(license_logger, 'warning') as mock_license_logger:
with mock.patch.object(license_utils_warnings_module, 'warn') as mock_license_logger:

license_warnings = []

Expand Down Expand Up @@ -520,7 +520,7 @@ def test_license_checker_full_scenario_succeeding():

with mock.patch.object(PythonLicenseFramework, "get_dependencies") as mock_get_dependencies:

with mock.patch.object(license_logger, 'warning') as mock_license_logger:
with mock.patch.object(license_utils_warnings_module, 'warn') as mock_license_logger:

license_warnings = []

Expand Down Expand Up @@ -655,7 +655,7 @@ def test_validate_simple_license_file():

with mfs.mock_exists_open_remove():

with mock.patch.object(license_logger, 'warning') as mock_license_logger:
with mock.patch.object(license_utils_warnings_module, 'warn') as mock_license_logger:

license_warnings = []

Expand Down

0 comments on commit 902f5c6

Please sign in to comment.