Edgewall Software

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#11632 closed defect (fixed)

get_pkginfo() doesn't work for MySQLdb and trac.core — at Version 6

Reported by: Jun Omae Owned by:
Priority: normal Milestone: 1.0.2
Component: general Version:
Severity: normal Keywords: setuptools
Cc: Branch:
Release Notes:

Improve trac.util.get_pkginfo() for non-toplevel module and module which doesn't match with package name.

API Changes:
Internal Changes:

Description (last modified by Jun Omae)

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.

Change History (6)

comment:1 by Jun Omae, 10 years ago

Description: modified (diff)

Proposed changes in jomae.git@t11632.

comment:2 by Ryan J Ollos, 10 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).

Last edited 10 years ago by Ryan J Ollos (previous) (diff)

comment:3 by Ryan J Ollos, 10 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'

in reply to:  3 ; comment:4 by Jun Omae, 10 years ago

Thanks for testing.

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

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.

in reply to:  4 comment:5 by Ryan J Ollos, 10 years ago

Replying to jomae:

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.

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 Jun Omae, 10 years ago

Milestone: next-stable-1.0.x1.0.2
Release Notes: modified (diff)
Resolution: fixed
Status: newclosed

On Windows, get_pkginfo() for package installed by pip doesn't work cause entries in installed-files.txt are used backslash. I revised the patch using os.path.normpath() for that case.

Committed in [12840] and merged to trunk in [12841].

Note: See TracTickets for help on using tickets.