3030
3131import datetime
3232import json
33+ import os
3334import logging
34- from os import path
35+ import sys
3536
3637from packvers import version as packaging_version
3738import requests
5455
5556SELFCHECK_DATE_FMT = "%Y-%m-%dT%H:%M:%SZ"
5657
58+ TRACE = os .environ .get ('SCANCODE_DEBUG_OUTDATED' , False )
59+
60+ def logger_debug (* args ):
61+ pass
62+
63+
5764logger = logging .getLogger (__name__ )
58- # logging.basicConfig(stream=sys.stdout)
59- # logger.setLevel(logging.WARNING)
65+
66+ if TRACE :
67+
68+ if TRACE :
69+ logging .basicConfig (stream = sys .stdout )
70+ logger .setLevel (logging .DEBUG )
71+
72+ def logger_debug (* args ):
73+ return logger .debug (' ' .join (isinstance (a , str ) and a or repr (a ) for a in args ))
6074
6175
6276def total_seconds (td ):
@@ -70,7 +84,7 @@ def total_seconds(td):
7084class VersionCheckState :
7185
7286 def __init__ (self ):
73- self .statefile_path = path .join (
87+ self .statefile_path = os . path .join (
7488 scancode_cache_dir , 'scancode-version-check.json' )
7589 self .lockfile_path = self .statefile_path + '.lockfile'
7690 # Load the existing state
@@ -154,6 +168,11 @@ def fetch_newer_version(
154168 State is stored in the scancode_cache_dir.
155169 If `force` is True, redo a PyPI remote check.
156170 """
171+ # If installed version is from git describe, only use the first part of it
172+ # i.e. `v31.2.1-343-gd9d2e19e32` -> `v31.2.1`
173+ if "-" in installed_version :
174+ installed_version = installed_version .split ("-" )[0 ]
175+
157176 try :
158177 installed_version = packaging_version .parse (installed_version )
159178 state = VersionCheckState ()
@@ -185,6 +204,10 @@ def fetch_newer_version(
185204
186205 latest_version = packaging_version .parse (latest_version )
187206
207+ if TRACE :
208+ logger_debug (f"installed_version: { installed_version } , latest version: { latest_version } " )
209+ logger_debug (f"installed_version < latest_version: { installed_version < latest_version } " )
210+
188211 # Determine if our latest_version is older
189212 if (installed_version < latest_version
190213 and installed_version .base_version != latest_version .base_version ):
0 commit comments