Skip to content

Commit

Permalink
Merge pull request #78 from ericdill/firmer-stdlib-list-checking
Browse files Browse the repository at this point in the history
Only even try to import stdlib-list if we're less than py39
  • Loading branch information
ericdill authored Jan 4, 2023
2 parents e7d8463 + 63106c5 commit fe41c72
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions depfinder/stdliblist.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import sys
import logging

logger = logging.getLogger('depfinder')
MAJOR, MINOR = sys.version_info.major, sys.version_info.minor

try:
from stdlib_list import stdlib_list
pyver = '%s.%s' % (sys.version_info.major, sys.version_info.minor)
builtin_modules = stdlib_list(pyver)
del pyver
except ImportError:
# assuming py>=3.10
if MAJOR == 3 and MINOR >= 10:
builtin_modules = list(set(list(sys.stdlib_module_names) + list(sys.builtin_module_names)))
else:
try:
from stdlib_list import stdlib_list
pyver = '%s.%s' % (MAJOR, MINOR)
builtin_modules = stdlib_list(pyver)
del pyver
except ImportError:
logger.exception('stdlib-list required for python <= 3.9')
raise

0 comments on commit fe41c72

Please sign in to comment.