[Distutils] Q about best practices now (or near future)

PJ Eby pje at telecommunity.com
Fri Jul 19 00:23:33 CEST 2013


On Thu, Jul 18, 2013 at 4:36 PM, Paul Moore <p.f.moore at gmail.com> wrote:
> As regards console scripts, I think they should be rewritten to remove the
> dependency on pkg_resources. That should be a setuptools fix,

As others have already mentioned, this is not a bug but a feature.
Setuptools-generated scripts are linked to a specific version of the
project, which means that you can install more than one version by
renaming the scripts or installing the scripts to different
directories.

While other strategies are definitely possible, distlib's approach is
not backward-compatible, as it means installing new versions of a
project will change *existing scripts'* semantics, even if you
installed the previous version's scripts to different locations and
intended them to remain accessible.

If you want an example of doing it right, see buildout, which
hardcodes the entire sys.path of a script to refer to the exact
versions of all dependencies; while this has different failure modes
(i.e., dependence on absolute paths), it is more stable as to script
semantics even than setuptools' default behavior.

> maybe triggered by a flag (possibly implied by
> --single-version-externally-managed, as the pkg_resources complexity is only
> needed when multi-versions are involved).

That option does not preclude the existence of multiple versions, or
the possibility of installing the same script to different directories
for different installed versions.

If you *must* do this, I suggest using buildout's approach of
hardwiring sys.path in the script, only strengthened by checking for
the actual existence and versions, rather than distlib's anything-goes
approach.

(Of course, as Donald points out, this won't do anything for those
scripts that themselves make use of other packages' entry points: they
will have a runtime dependency on pkg_resources anyway.)


More information about the Distutils-SIG mailing list