tdsmith / homebrew-pypi-poet

Generates Homebrew resource stanzas for Python packages.
MIT License
140 stars 30 forks source link

problems creating formula for gprof2dot #16

Closed zbeekman closed 8 years ago

zbeekman commented 9 years ago

I think the source of the issue is that poet is trying to fetch information for urllib2 which appears to be part of the standard python library. Give it a try yourself to take a look at the debugging output:

$ poet gprof2dot
Traceback (most recent call last):
  File "/usr/local/bin/poet", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/poet/poet.py", line 203, in main
    print(resources_for(package))
  File "/usr/local/lib/python2.7/site-packages/poet/poet.py", line 157, in resources_for
    nodes = make_graph(package)
  File "/usr/local/lib/python2.7/site-packages/poet/poet.py", line 131, in make_graph
    package_data = research_package(package, dependencies[package]['version'])
  File "/usr/local/lib/python2.7/site-packages/poet/poet.py", line 95, in research_package
    format(name, version or ''))
  File "/usr/local/homebrew/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/homebrew/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/usr/local/homebrew/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/local/homebrew/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 475, in error
    return self._call_chain(*args)
  File "/usr/local/homebrew/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/local/homebrew/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 558, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found

gprof2dot is available through pip/PyPi

tdsmith commented 9 years ago

The problem is that gprof2dot's versions aren't PEP 440-compliant. pip returns a normalized version from pip.get_installed_distributions() (2015.2.3 instead of 2015.02.03) but pypi doesn't accept a normalized version in its API (https://pypi.python.org/pypi/gprof2dot/2015.2.3/json 404s, https://pypi.python.org/pypi/gprof2dot/2015.02.03/json does not).

poet could try to work around this by making a more generic call to pypi and working harder to interpret it but I'm not feeling inspired.

I really should add better error handling, though.

jrfonseca commented 9 years ago

The problem is that gprof2dot's versions aren't PEP 440-compliant.

https://www.python.org/dev/peps/pep-0440/ states that "Date based release segments are also permitted. " and gives a bunch of examples such as "2012.04".

So PEP 440 compliance doesn't look like the problem to me.

tdsmith commented 9 years ago

That's fair; I shouldn't have said "compliant." This is allowed and works normally for version comparison purposes. I should have said that the normalized and canonical versions are non-identical, following the rule at https://www.python.org/dev/peps/pep-0440/#integer-normalization.

zbeekman commented 9 years ago

I'm closing this since I was able to get a Formula worked up... not sure if there are any issues that need further attention, however. Feel free to re-open, @tdsmith

tdsmith commented 8 years ago

It really is a poet bug, so I'll leave it open.

tdsmith commented 8 years ago

I think the best way to normalize the version is to steal this code from pip:

https://github.com/pypa/pip/blob/a6e329fef41a95d688533886b4e0fe24a8551621/pip/_vendor/pkg_resources/__init__.py#L1360-L1369

def safe_version(version):
    """
    Convert an arbitrary string to a standard version string
    """
    try:
        # normalize the version
        return str(packaging.version.Version(version))
    except packaging.version.InvalidVersion:
        version = version.replace(' ','.')
        return re.sub('[^A-Za-z0-9.]+', '-', version)