[Distutils] unparseable sdist filenames

PJ Eby pje at telecommunity.com
Mon Sep 30 20:38:03 CEST 2013


On Mon, Sep 30, 2013 at 1:55 PM, Marcus Smith <qwcode at gmail.com> wrote:
> so, take a case like so  "pytest-xdist-dev.tar.gz" (or any sdist with "-" in
> the project name, and a version starting with a string)
>
> I think it's like so:
> - pkg_resources.Distribution.from_location will treat "xdist-dev" as the
> version.
> - distlib.util.split_filename won't parse it because versions have to start
> with [0-9].

For these APIs, these are reasonable defaults, because they are
intended only to parse *unambiguous* filenames.  Neither API should be
used with sdist files, because sdist filenames are ambiguous and
cannot therefore be parsed to a single name.

The setuptools.package_index API, however, *does* support parsing
sdist names, it's just that it generates a *list* of possibilities,
rather than a single unambiguous interpretation of the filename.  If
you ask it to parse the example you gave, you will get a list of:

* Project "pydist", version "xdist-dev"
* Project "pydist-xdist", version "dev"
* Project "pydist-xdist-dev", no version

Thus, tools using this API can contextually decide which to consider
the "real" interpretation, based on context.  This method is used by
easy_install; I don't know if pip does as well.

> - pip will accept this as a "pytest" archive and install it potentially if
> no other version matches greater.

Does it also accept it as "pytest-xdist"?


> what's the right answer?

It depends on what you want, and whether what you want is compatible
with reality.  ;-)


> The historical-compatible answer is to be confused when projects have "-".
> so stay confused? or get rigid like distlib?

The future sdist format should not be ambiguous like this.  Dealing
with ambiguity in past packages is for the moment something of a
requirement if you are making a general-use tool.


More information about the Distutils-SIG mailing list