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
12 changes: 5 additions & 7 deletions src/scancode/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,10 @@ def scancode(
cliutils.validate_option_dependencies(ctx)
pretty_params = get_pretty_params(ctx, generic_paths=test_mode)

# warn for outdated version and/or check for updates
from scancode.outdated import check_scancode_version_locally
outdated = check_scancode_version_locally()

if not outdated and check_version:
from scancode.outdated import check_scancode_version_remotely
outdated = check_scancode_version_remotely()
# Check for updates

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should ONLY happen if check_version. This way folks can elect to not do any such check

if check_version:
from scancode.outdated import check_scancode_version
outdated = check_scancode_version()

# run proper
success, _results = run_scan(
Expand Down Expand Up @@ -473,6 +470,7 @@ def scancode(
**kwargs
)

#echo outdated message if newer version is available
if not quiet and outdated:
echo_stderr(outdated, fg='yellow')

Expand Down
37 changes: 2 additions & 35 deletions src/scancode/outdated.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,6 @@ def total_seconds(td):
return val / 10 ** 6


def is_outdated(release_date):
"""
Return True if 90 days have passed since `release_date` datetime object.

For example:

>>> release_date = datetime.datetime(2020, 9, 23)
>>> is_outdated(release_date)
True
>>> release_date = datetime.datetime.utcnow()
>>> is_outdated(release_date)
False
"""
current_time = datetime.datetime.utcnow()
seconds_since_last_check = total_seconds(current_time - release_date)
ninety_days = 90 * 24 * 60 * 60
return seconds_since_last_check > ninety_days


class VersionCheckState:

def __init__(self):
Expand Down Expand Up @@ -133,24 +114,10 @@ def build_outdated_message(installed_version, release_date, newer_version=''):
'Visit https://github.com/nexB/scancode-toolkit/releases for details.'
)
return msg



def check_scancode_version_locally(
installed_version=scancode_version,
release_date=scancode_release_date,
):
"""
Return a message to display if outdated or None. Work offline, without a
PyPI remote check.
"""
if is_outdated(release_date):
return build_outdated_message(
installed_version=installed_version,
release_date=release_date,
)


def check_scancode_version_remotely(
def check_scancode_version(
installed_version=scancode_version,
release_date=scancode_release_date,
new_version_url='https://pypi.org/pypi/scancode-toolkit/json',
Expand Down
8 changes: 4 additions & 4 deletions tests/scancode/test_outdated.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def jget(*args, **kwargs):
assert outdated.fetch_newer_version(force=True) == '42.5.1'


def test_check_scancode_version_remotely():
def test_check_scancode_version():
from unittest import mock
pypi_mock_releases = {
'releases': {
Expand All @@ -126,7 +126,7 @@ def jget(*args, **kwargs):
status_code=200
)

result = outdated.check_scancode_version_remotely(force=True)
result = outdated.check_scancode_version(force=True)
assert result.startswith('WARNING: Outdated ScanCode')
assert 'A new version 42.5.1 is available' in result

Expand All @@ -153,7 +153,7 @@ def jget(*args, **kwargs):
status_code=200
)
assert not outdated.fetch_newer_version(force=True)
assert not outdated.check_scancode_version_remotely(force=True)
assert not outdated.check_scancode_version(force=True)


def test_fetch_newer_version_local_git_version():
Expand Down Expand Up @@ -184,7 +184,7 @@ def jget(*args, **kwargs):
)
assert not result

result = outdated.check_scancode_version_remotely(
result = outdated.check_scancode_version(
installed_version='3.1.2.post351.850399bc3',
force=True,
)
Expand Down