From 5c97a189a0c673596246cbbf8400f28d1ec6f88b Mon Sep 17 00:00:00 2001 From: Carl Date: Sun, 22 Jul 2018 10:11:46 +0200 Subject: [PATCH] Updating to be able to handle astroid 2.0 node names but keep backwards compatibility too --- requirements_detector/__compat__.py | 16 ++++++++++++++++ requirements_detector/detect.py | 7 ++++--- setup.py | 3 ++- 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 requirements_detector/__compat__.py diff --git a/requirements_detector/__compat__.py b/requirements_detector/__compat__.py new file mode 100644 index 0000000..00e458a --- /dev/null +++ b/requirements_detector/__compat__.py @@ -0,0 +1,16 @@ +# Various shims to deal with node renames between astroid versions - astroid 2.0 renamed +# some of the nodes used by this library so for backwards compatibility, old names are +# translated to new. + +try: + from astroid import Call +except ImportError: + from astroid import CallFunc as Call + + +try: + from astroid import AssignName +except ImportError: + from astroid import AssName as AssignName + + diff --git a/requirements_detector/detect.py b/requirements_detector/detect.py index f1700a1..e194296 100644 --- a/requirements_detector/detect.py +++ b/requirements_detector/detect.py @@ -2,7 +2,8 @@ import os import sys from astroid.builder import AstroidBuilder -from astroid import MANAGER, CallFunc, Name, Assign, Keyword, List, Tuple, Const, AssName +from astroid import MANAGER, Name, Assign, Keyword, List, Tuple, Const +from requirements_detector.__compat__ import Call, AssignName from requirements_detector.requirement import DetectedRequirement @@ -130,7 +131,7 @@ def walk(self, node=None): node = node or self._ast # test to see if this is a call to setup() - if isinstance(node, CallFunc): + if isinstance(node, Call): for child_node in node.get_children(): if isinstance(child_node, Name) and child_node.name == 'setup': # TODO: what if this isn't actually the distutils setup? @@ -139,7 +140,7 @@ def walk(self, node=None): for child_node in node.get_children(): if top and isinstance(child_node, Assign): for target in child_node.targets: - if isinstance(target, AssName): + if isinstance(target, AssignName): self._top_level_assigns[target.name] = child_node.value self.walk(child_node) diff --git a/setup.py b/setup.py index d34dbd8..a445bf7 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ import sys -_version = "0.5.2" +_version = "0.6" _packages = find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]) _short_description = "Python tool to find and list requirements of a Python project" @@ -21,6 +21,7 @@ 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'License :: OSI Approved :: MIT License', )