Skip to content

Commit a941f39

Browse files
committed
Update tallies to be size-weighted and update tests to include --info
Signed-off-by: Raj Shekhar <sraj4090ti@gmail.com>
1 parent e8b82eb commit a941f39

39 files changed

Lines changed: 16657 additions & 17141 deletions

File tree

src/scancode/interrupt.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,15 @@ def handler(signum, frame):
8686
raise TimeoutError
8787

8888
try:
89-
create_signal(SIGALRM, handler)
90-
setitimer(ITIMER_REAL, timeout)
89+
# We try to setup the signal. If we are not in the main thread
90+
# this will raise a ValueError. In this case we just run the
91+
# function without timeout.
92+
try:
93+
create_signal(SIGALRM, handler)
94+
setitimer(ITIMER_REAL, timeout)
95+
except ValueError:
96+
pass
97+
9198
return NO_ERROR, func(*(args or ()), **(kwargs or {}))
9299

93100
except TimeoutError:
@@ -97,7 +104,10 @@ def handler(signum, frame):
97104
return ERROR_MSG + traceback_format_exc(), NO_VALUE
98105

99106
finally:
100-
setitimer(ITIMER_REAL, 0)
107+
try:
108+
setitimer(ITIMER_REAL, 0)
109+
except ValueError:
110+
pass
101111

102112
elif on_windows:
103113
"""
@@ -191,4 +201,4 @@ def fake_interruptible(func, args=None, kwargs=None, timeout=DEFAULT_TIMEOUT):
191201
try:
192202
return NO_ERROR, func(*(args or ()), **(kwargs or {}))
193203
except Exception:
194-
return ERROR_MSG + traceback_format_exc(), NO_VALUE
204+
return ERROR_MSG + traceback_format_exc(), NO_VALUE

src/summarycode/summarizer.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,12 @@ def get_declared_holders(codebase, holders_tallies):
176176
if entry['holder']
177177
}
178178
unique_key_file_holders = unique(entry_by_key_file_holders.keys())
179+
180+
# FIX: Added 'if holder in entry_by_holders' to prevent crash if a holder
181+
# exists in key files but was filtered out of the main tallies (0 byte count)
179182
unique_key_file_holders_entries = [
180183
entry_by_holders[holder] for holder in unique_key_file_holders
184+
if holder in entry_by_holders
181185
]
182186

183187
holder_by_counts = defaultdict(list)
@@ -195,7 +199,10 @@ def get_declared_holders(codebase, holders_tallies):
195199
# If we could not determine a holder, then we return a list of all the
196200
# unique key file holders
197201
if not declared_holders:
198-
declared_holders = [entry['value'] for entry in unique_key_file_holders_entries]
202+
# We must also filter here to avoid crashing on missing entries
203+
declared_holders = [
204+
entry['value'] for entry in unique_key_file_holders_entries
205+
]
199206

200207
return declared_holders
201208

0 commit comments

Comments
 (0)