Skip to content

Commit

Permalink
Fix Pip-18 Incompatibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
kojiromike committed Aug 2, 2018
1 parent a322ca0 commit 033a7c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 4 additions & 1 deletion important/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@


def _base_module_name(import_statement):
return import_statement.module.split('.')[0]
try:
return import_statement.module.split('.')[0]
except AttributeError:
return ''


def check_unused_requirements(imports, requirements):
Expand Down
16 changes: 12 additions & 4 deletions important/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@

import pip

from pip.commands.show import search_packages_info
from pip.req import parse_requirements as pip_parse_requirements
try:
from pip.commands.show import search_packages_info
from pip.req import parse_requirements as pip_parse_requirements
except ImportError:
from pip._internal.commands.show import search_packages_info
from pip._internal.req import parse_requirements as pip_parse_requirements


RE_SHEBANG = re.compile('^#![^\n]*python[0-9]?$')
Expand Down Expand Up @@ -117,8 +121,12 @@ def parse_dir_imports(current_directory, exclusions=None):


def parse_requirements(filename):
requirements = pip_parse_requirements(filename,
session=pip.download.PipSession())
try:
requirements = pip_parse_requirements(filename,
session=pip.download.PipSession())
except AttributeError:
requirements = pip_parse_requirements(filename,
session=pip._internal.download.PipSession())
for requirement in requirements:
if not requirement.name:
raise ValueError(
Expand Down

0 comments on commit 033a7c7

Please sign in to comment.