#11632 closed defect (fixed)
get_pkginfo() doesn't work for MySQLdb and trac.core
| Reported by: | Jun Omae | Owned by: | Jun Omae | 
|---|---|---|---|
| Priority: | normal | Milestone: | 1.0.2 | 
| Component: | general | Version: | |
| Severity: | normal | Keywords: | setuptools | 
| Cc: | Branch: | ||
| Release Notes: | 
           
Improve   | 
      ||
| API Changes: | |||
| Internal Changes: | |||
Description (last modified by )
trac.util.get_pkginfo() function retrieves PKG-INFO for the specified module. The function usually is used to provide System Information and Installed Plugins.
However, if the module is non-toplevel module or isn't matched with package name, it doesn't work as expected.
>>> from trac.util import get_pkginfo >>> import trac, trac.core, MySQLdb, psycopg2 >>> for mod in (trac, trac.core, MySQLdb, psycopg2): ... mod.__name__, get_pkginfo(mod).get('version', '???') ... ('trac', '1.0.1') ('trac.core', '???') ('MySQLdb', '???') ('psycopg2', '2.0.14')
trac.core and MySQLdb are specified in tags/trac-1.0.1/trac/env.py@:643#L625 and tags/trac-1.0.1/trac/db/mysql_backend.py@:94#L90.
We could check that file path is included in SOURCES.txt of the metadata to fix it.
Attachments (0)
Change History (7)
comment:1 by , 11 years ago
| Description: | modified (diff) | 
|---|
comment:2 by , 11 years ago
On 1.0-stable I get same result shown in comment:description:
>>> from trac.util import get_pkginfo >>> import trac, trac.core, MySQLdb, psycopg2 >>> for mod in (trac, trac.core, MySQLdb, psycopg2): ... mod.__name__, get_pkginfo(mod).get('version', '???') ... ('trac', '1.0.2dev-r0') ('trac.core', '???') ('MySQLdb', '???') ('psycopg2', '2.4.5')
On jomae.git@t11632 there seems to be trouble with psycopg2:
>>> from trac.util import get_pkginfo >>> import trac, trac.core, MySQLdb, psycopg2 >>> for mod in (trac, trac.core, MySQLdb, psycopg2): ... mod.__name__, get_pkginfo(mod).get('version', '???') ... ('trac', '1.0.2dev-r0') ('trac.core', '1.0.2dev-r0') ('MySQLdb', '1.2.3') ('psycopg2', '???')
Tests pass for me on both 1.0-stable and jomae.git@t11632 (Python 2.7 / Ubuntu 13.04).
follow-up: 4 comment:3 by , 11 years ago
It might have something to do with psycopg2 being compressed:
$ ls -al /usr/share/pyshared/psycopg2-2.4.5.egg-info -rw-r--r-- 1 root root 1581 Nov 7 2012 /usr/share/pyshared/psycopg2-2.4.5.egg-info
>>> from pkg_resources import get_distribution >>> dist = get_distribution('psycopg2') >>> print dist psycopg2 2.4.5 >>> print dist.get_metadata('top_level.txt') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/user/Workspace/tracdev/local/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py", line 1546, in get_metadata raise KeyError("No metadata except PKG-INFO is available") KeyError: 'No metadata except PKG-INFO is available'
follow-up: 5 comment:4 by , 11 years ago
Thanks for testing.
It might have something to do with
psycopg2being compressed:$ ls -al /usr/share/pyshared/psycopg2-2.4.5.egg-info -rw-r--r-- 1 root root 1581 Nov 7 2012 /usr/share/pyshared/psycopg2-2.4.5.egg-info
It doesn't seems python-psycopg2 package in Ubuntu provides top_level.txt and SOURCES.txt. python-mysqldb package provides the metadata.
$ dpkg -L python-psycopg2 | egrep '(top_level|SOURCES).txt' | wc -l 0 $ dpkg -L python-mysqldb | egrep '(top_level|SOURCES).txt' /usr/share/pyshared/MySQL_python-1.2.3.egg-info/SOURCES.txt /usr/share/pyshared/MySQL_python-1.2.3.egg-info/top_level.txt /usr/lib/python2.7/dist-packages/MySQL_python-1.2.3.egg-info/SOURCES.txt /usr/lib/python2.7/dist-packages/MySQL_python-1.2.3.egg-info/top_level.txt
However, I also get the same issue if psycopg2 is installed by pip and ubuntu pacakge isn't used. SOURCES.txt in psycopg2 doesn't have psyscopg2/__init__.py entry.
$ grep '^psycopg2' ~/venv/py25-1.0/lib/python2.5/site-packages/psycopg2-2.5.2-py2.5.egg-info/SOURCES.txt psycopg2.egg-info/PKG-INFO psycopg2.egg-info/SOURCES.txt psycopg2.egg-info/dependency_links.txt psycopg2.egg-info/top_level.txt $ grep '__init__.py$' ~/venv/py25-1.0/lib/python2.5/site-packages/psycopg2-2.5.2-py2.5.egg-info/SOURCES.txt lib/__init__.py tests/__init__.py
Reconsidering that case, I think we could use Distribution.has_resource (installed by easy_install) and installed-files.txt metadata (installed by pip) before checking SOURCES.txt. It works well on both uncompressed egg and compressed egg. See jomae.git@t11632.1.
comment:5 by , 11 years ago
Replying to jomae:
Reconsidering that case, I think we could use
Distribution.has_resource(installed by easy_install) andinstalled-files.txtmetadata (installed by pip) before checkingSOURCES.txt. It works well on both uncompressed egg and compressed egg. See jomae.git@t11632.1.
Those changes work well,
>>> from trac.util import get_pkginfo >>> import trac, trac.core, MySQLdb, psycopg2 >>> for mod in (trac, trac.core, MySQLdb, psycopg2): ... mod.__name__, get_pkginfo(mod).get('version', '???') ... ('trac', '1.0.2dev-r0') ('trac.core', '1.0.2dev-r0') ('MySQLdb', '1.2.3') ('psycopg2', '2.4.5')
comment:6 by , 11 years ago
| Milestone: | next-stable-1.0.x → 1.0.2 | 
|---|---|
| Release Notes: | modified (diff) | 
| Resolution: | → fixed | 
| Status: | new → closed | 
comment:7 by , 11 years ago
| Owner: | set to | 
|---|



  
Proposed changes in jomae.git@t11632.