Skip to content

Commit

Permalink
Updating to be able to handle astroid 2.0 node names but keep backwar…
Browse files Browse the repository at this point in the history
…ds compatibility too
  • Loading branch information
Carl committed Jul 22, 2018
1 parent 3cfcefd commit 5c97a18
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
16 changes: 16 additions & 0 deletions 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


7 changes: 4 additions & 3 deletions requirements_detector/detect.py
Expand Up @@ -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


Expand Down Expand Up @@ -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?
Expand All @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -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"
Expand All @@ -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',
)

Expand Down

0 comments on commit 5c97a18

Please sign in to comment.