Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cryptic error when a dependency's PKG_INFO/METADATA is missing #5082

Closed
nvictus opened this issue Mar 18, 2018 · 4 comments · Fixed by #6542
Closed

Cryptic error when a dependency's PKG_INFO/METADATA is missing #5082

nvictus opened this issue Mar 18, 2018 · 4 comments · Fixed by #6542
Labels
auto-locked Outdated issues that have been locked by automation type: enhancement Improvements to functionality

Comments

@nvictus
Copy link

nvictus commented Mar 18, 2018

  • Pip version: 9.0.1
  • Python version: 3.6.4
  • Operating system: Ubuntu 17.10

Description:

Pip crashes with a cryptic error when it doesn't find a dependency's package metadata.

What I've run:

A certain dependency was installed using conda and was lacking a PKG-INFO file in the egg-info. When installing the desired package, pip fails right after processing the dependency with this error traceback:

Exception:
Traceback (most recent call last):
  File "/home/nezar/miniconda3/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/nezar/miniconda3/lib/python3.6/site-packages/pip/commands/install.py", line 335, in run
    wb.build(autobuilding=True)
  File "/home/nezar/miniconda3/lib/python3.6/site-packages/pip/wheel.py", line 756, in build
    self.requirement_set.prepare_files(self.finder)
  File "/home/nezar/miniconda3/lib/python3.6/site-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/home/nezar/miniconda3/lib/python3.6/site-packages/pip/req/req_set.py", line 666, in _prepare_file
    check_dist_requires_python(dist)
  File "/home/nezar/miniconda3/lib/python3.6/site-packages/pip/utils/packaging.py", line 48, in check_dist_requires_python
    feed_parser.feed(metadata)
  File "/home/nezar/miniconda3/lib/python3.6/email/feedparser.py", line 175, in feed
    self._input.push(data)
  File "/home/nezar/miniconda3/lib/python3.6/email/feedparser.py", line 103, in push
    self._partial.write(data)
TypeError: string argument expected, got 'NoneType'

On inspecting pip/utils/packaging.py:

def get_metadata(dist):
    if (isinstance(dist, pkg_resources.DistInfoDistribution) and
            dist.has_metadata('METADATA')):
        return dist.get_metadata('METADATA')
    elif dist.has_metadata('PKG-INFO'):
        return dist.get_metadata('PKG-INFO')


def check_dist_requires_python(dist):
    metadata = get_metadata(dist)
    feed_parser = FeedParser()
    feed_parser.feed(metadata)
    pkg_info_dict = feed_parser.close()
    requires_python = pkg_info_dict.get('Requires-Python')
    try:
        if not check_requires_python(requires_python):
            raise exceptions.UnsupportedPythonVersion(
                "%s requires Python '%s' but the running Python is %s" % (
                    dist.project_name,
                    requires_python,
                    '.'.join(map(str, sys.version_info[:3])),)
            )
    except specifiers.InvalidSpecifier as e:
        logger.warning(
            "Package %s has an invalid Requires-Python entry %s - %s" % (
                dist.project_name, requires_python, e))
        return

get_metadata is returning None when it doesn't find anything, which causes feed_parser to crash.

@pradyunsg pradyunsg added this to the Print Better Error Messages milestone Apr 8, 2018
@pradyunsg pradyunsg added the type: enhancement Improvements to functionality label Apr 8, 2018
@pradyunsg
Copy link
Member

pradyunsg commented Nov 10, 2018

@cytolentino Hi!

Could you take a look at this issue? There should probably be a conditional somewhere, that prevents us from passing None to feed_parser, aborting early. :)

@cytolentino
Copy link
Contributor

Hi @pradyunsg! I've just had a look at this and it seems like someone else has already fixed this (see here). That said, I've added in a regression test for this case to confirm that it's fixed over here: PR #6003 :)

@cjerdonek cjerdonek added type: bug A confirmed bug or unintended behavior and removed type: enhancement Improvements to functionality labels May 26, 2019
@cjerdonek
Copy link
Member

cjerdonek commented May 26, 2019

Marking this as a bug because pip shouldn't necessarily be crashing here (at least sometimes I don't think).

@cjerdonek
Copy link
Member

cjerdonek commented May 26, 2019

I posted a fix for this (PR #6542). However, I only addressed the "enhancement" aspect (better error message) because in working on the patch I found that it should probably continue to error out (at least for now).

If there are other get_metadata() callers in the code base that shouldn't be erroring out in this situation, that should probably be handled on a case-by-case basis in different issues (when they are filed). There are many callers of get_metadata(), so I don't think we'd want to do a blanket "fix."

@cjerdonek cjerdonek added type: enhancement Improvements to functionality and removed kind: crash For situations where pip crashes type: bug A confirmed bug or unintended behavior labels May 26, 2019
@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 26, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation type: enhancement Improvements to functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants