Skip to content

Commit

Permalink
feat(deps): conditional dependency
Browse files Browse the repository at this point in the history
Only install `stdlib_list` for python versions up to 3.9.

From 3.10 onwards there is a way to get that from within python standard
lib.
  • Loading branch information
gforcada committed Nov 29, 2022
1 parent 80a8ab1 commit fc96659
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def read(filename):
zip_safe=False,
install_requires=[
'setuptools',
'stdlib-list',
'stdlib-list; python_version < "3.10"',
'cached-property',
'toml',
],
Expand Down
27 changes: 19 additions & 8 deletions z3c/dependencychecker/db.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import logging
import sys

from stdlib_list import stdlib_list

from z3c.dependencychecker.dotted_name import DottedName

logger = logging.getLogger(__name__)


# starting from python 3.10 the list of builtin methods are available directly
PY_10_OR_HIGHER = True
if sys.version_info[1] < 10:
PY_10_OR_HIGHER = False
from stdlib_list import stdlib_list


class ImportsDatabase:
"""Store all imports and requirements of a package
Expand Down Expand Up @@ -349,13 +354,19 @@ def _discard_if_found_obj_in_list(obj, obj_list):

@staticmethod
def _build_std_library():
python_version = sys.version_info
libraries = stdlib_list(
'{}.{}'.format(
python_version[0],
python_version[1],
if PY_10_OR_HIGHER:
# see https://github.com/jackmaney/python-stdlib-list/issues/55
libraries = list(
set(list(sys.stdlib_module_names) + list(sys.builtin_module_names))
)
else:
python_version = sys.version_info
libraries = stdlib_list(
'{}.{}'.format(
python_version[0],
python_version[1],
)
)
)

fake_std_libraries = [DottedName(x) for x in libraries]
return fake_std_libraries
Expand Down

0 comments on commit fc96659

Please sign in to comment.