[Distutils] use of '_' in package name causing version parsing issue?

P.J. Eby pje at telecommunity.com
Thu Mar 11 05:39:08 CET 2010

At 09:50 AM 3/10/2010 +0530, Baiju M wrote:
>I spend some time with Buildout and setuptools code to identify the issue.
>I will try to explain my findings.
>1. Buildout is relying on pkg_resources.Requirement.parse function to
>     get the "project_name" like this:
>      pkg_resources.Requirement.parse('jiva_interface').project_name
>     I can see from the code of `Requirement` class that, the `__init__`
>     method is deprecated and recommend to use `parse`
>     function.

It is undocumented, not deprecated.  You are simply not supposed to 
create instances via that (private) constructor.

>  Does this mean that we should not use the attributes
>     of an instance of `Requirement` class?  This is very important as
>     the `parse` function return a list of instances of `Requirement` class.

Requirement objects are documented; see:


>    So, if it is acceptable to use the "project_name" attribute, then
>    Buildout can rely on it, right ?


>    According to this code, this will be the result:
>      pkg_resources.safe_name('jiva_interface')
>      'jiva-interface'
>    And:
>      pkg_resources.Requirement.parse('jiva_interface').project_name
>      'jiva-interface'
>     Is this behavior correct ?

Yes it is. All non-alphanumeric, non-dot characters are replaced with 
'-' in a project name.  This turns project names like e.g. "Foo's Bar 
Factory" into their canonical form (i.e., "Foo-s-Bar-Factory").

>     If you think what setuptools doing is fine, we will make changes
>     in Buildout code to use the "safe_name" method where ever it directly
>     get "project_name".

Why do you think you need that?  (Most likely, you are mistaken, 
since the only reason the unsafe_name attribute exists is to deal 
with a limitation in older versions of the PyPI software, which did 
not support doing "safe_name" redirection.)

If you can describe what you're actually trying to do with this 
information, perhaps there is a safer/more documented way that I can suggest.

More information about the Distutils-SIG mailing list