2009-02-21 21:33:52 -05:00
|
|
|
|
PEP: 376
|
|
|
|
|
Title: Changing the .egg-info structure
|
2009-02-22 17:42:22 -05:00
|
|
|
|
Version: $Revision$
|
|
|
|
|
Last-Modified: $Date$
|
2009-02-21 21:33:52 -05:00
|
|
|
|
Author: Tarek Ziadé <tarek@ziade.org>
|
|
|
|
|
Status: Draft
|
|
|
|
|
Type: Standards Track
|
|
|
|
|
Content-Type: text/x-rst
|
|
|
|
|
Created: 22-Feb-2009
|
2009-05-14 18:03:08 -04:00
|
|
|
|
Python-Version: 2.7, 3.2
|
2009-02-21 21:33:52 -05:00
|
|
|
|
Post-History:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Abstract
|
|
|
|
|
========
|
|
|
|
|
|
|
|
|
|
This PEP proposes various enhancements for Distutils:
|
|
|
|
|
|
2009-02-22 17:42:22 -05:00
|
|
|
|
- A new format for the .egg-info structure.
|
2009-04-13 17:14:19 -04:00
|
|
|
|
- Some APIs to read the meta-data of a project
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
Definitions
|
|
|
|
|
===========
|
2009-02-28 09:22:01 -05:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
A **project** is a Python application composed of one or many Python packages.
|
|
|
|
|
It is distributed using a `setup.py` script with Distutils and/or Setuptools.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
Once installed, one or several **packages** are added in Python's site-packages.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
Rationale
|
|
|
|
|
=========
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-05-14 05:32:29 -04:00
|
|
|
|
There are two problems right now in the way projects are installed in Python:
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
- There are too many ways to install a project in Python.
|
2009-05-14 18:07:21 -04:00
|
|
|
|
- There is no API to get the metadata of installed projects.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
How projects are installed
|
2009-02-21 21:33:52 -05:00
|
|
|
|
--------------------------
|
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
Right now, when a project is installed in Python, every package its contains
|
|
|
|
|
is installed in the `site-packages` directory with the Distutils `install`
|
|
|
|
|
command.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
The `install_egg_info` subcommand is called during this process, in order to
|
|
|
|
|
create an `.egg-info` file in the `site-packages` directory.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-05-14 18:08:59 -04:00
|
|
|
|
For example, if the `zlib` project (which contains one package) is installed,
|
2009-04-24 12:03:02 -04:00
|
|
|
|
two elements will be installed in `site-packages`::
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
- zlib
|
|
|
|
|
- zlib-2.5.2-py2.4.egg-info
|
|
|
|
|
|
|
|
|
|
Where `zlib` is the package, and `zlib-2.5.2-py2.4.egg-info` is
|
2009-02-21 21:33:52 -05:00
|
|
|
|
a file containing the package metadata as described in PEP 314.
|
|
|
|
|
|
|
|
|
|
This file corresponds to the file called `PKG-INFO`, built by
|
|
|
|
|
the `sdist` command.
|
|
|
|
|
|
|
|
|
|
The problem is that many people use `easy_install` (setuptools) or `pip`
|
2009-02-28 09:22:01 -05:00
|
|
|
|
to install their packages, and these third-party tools do not install
|
|
|
|
|
packages in the same way that Distutils does:
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
|
|
|
|
- `easy_install` creates an `EGG-INFO` directory inside an `.egg` directory,
|
2009-04-24 12:03:02 -04:00
|
|
|
|
and adds a `PKG-INFO` file inside this directory. The `.egg` directory
|
|
|
|
|
contains in that case the packages of the project.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
|
|
|
|
- `pip` creates an `.egg-info` directory inside the site-packages directory
|
2009-04-24 12:03:02 -04:00
|
|
|
|
and adds a `PKG-INFO` file inside it. Packages are installed in
|
|
|
|
|
site-packages directory in a regular way.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
|
|
|
|
They both add other files in the `EGG-INFO` or `.egg-info` directory, and
|
2009-04-24 12:03:02 -04:00
|
|
|
|
create or modify `.pth` files.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
Uninstall information
|
2009-02-21 21:33:52 -05:00
|
|
|
|
---------------------
|
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
Distutils doesn't provide any `uninstall` command. If you want to uninstall
|
|
|
|
|
a project, you have to be a power user and remove the various package
|
|
|
|
|
directories from the right `site-packages` directory, then look over the right
|
|
|
|
|
`pth` files. And this method differs, depending on the tools you are using.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
The worst issue is that you depend on the way the packager created his package.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
When you call `python setup.py install`, it will not be installed the same way
|
2009-04-24 12:03:02 -04:00
|
|
|
|
depending on the tool used by the packager (mainly Distutils or Setuptools).
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
But there's common behavior: files are copied in your installation.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
And there's a way to keep track of theses file, so to remove them.
|
|
|
|
|
|
|
|
|
|
What this PEP proposes
|
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
|
|
To address those issues, this PEP proposes a few changes:
|
|
|
|
|
|
|
|
|
|
- a new `.egg-info` structure using a directory;
|
|
|
|
|
- a list of elements this directory holds;
|
2009-04-24 12:03:02 -04:00
|
|
|
|
- new functions in `pkgutil` to be able to query the information
|
|
|
|
|
of installed projects.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
|
|
|
|
.egg-info becomes a directory
|
|
|
|
|
=============================
|
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
The first change would be to make `.egg-info` a directory and let it
|
2009-02-21 21:33:52 -05:00
|
|
|
|
hold the `PKG-INFO` file built by the `write_pkg_file` method.
|
|
|
|
|
|
|
|
|
|
This change will not impact Python itself, because this file is not
|
|
|
|
|
used anywhere yet in the standard library. So there's no need of
|
|
|
|
|
deprecation.
|
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
Although it will impact the `setuptools` and `pip` projects, but given
|
|
|
|
|
the fact that they already work with a directory that contains a
|
2009-02-21 21:33:52 -05:00
|
|
|
|
`PKG-INFO` file, the change will be small.
|
|
|
|
|
|
|
|
|
|
For example, if the `zlib` package is installed, two elements
|
|
|
|
|
will be installed in `site-packages`::
|
|
|
|
|
|
|
|
|
|
- zlib
|
2009-04-24 12:03:02 -04:00
|
|
|
|
- zlib-2.5.2.egg-info/
|
2009-02-21 21:33:52 -05:00
|
|
|
|
PKG-INFO
|
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
The Python version will also be removed from the .egg-info directory
|
|
|
|
|
name. To be able to implement this change, the impacted code in Distutils
|
|
|
|
|
is the `install_egg_info` command, and the various third-party projects.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
Adding a RECORD in the .egg-info directory
|
|
|
|
|
==========================================
|
2009-02-28 09:22:01 -05:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
A `RECORD` file will be added inside the `.egg-info` directory at installation
|
|
|
|
|
time.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
|
|
|
|
- the `RECORD` file will hold the list of installed files. These
|
|
|
|
|
correspond to the files listed by the `record` option of the `install`
|
2009-05-14 05:32:29 -04:00
|
|
|
|
command, and will always be generated. This will allow uninstallation, as
|
2009-04-24 12:03:02 -04:00
|
|
|
|
explained later in this PEP.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
|
|
|
|
The `install` command will record by default installed files in the
|
2009-04-24 12:03:02 -04:00
|
|
|
|
RECORD file, using these rules:
|
|
|
|
|
|
|
|
|
|
- if the installed file is located in a directory in `site-packages`,
|
|
|
|
|
it will be a '/'-separated relative path, no matter what is the target
|
|
|
|
|
system. This makes this information cross-compatible and allows simple
|
|
|
|
|
installation to be relocatable.
|
|
|
|
|
|
2009-05-14 05:32:29 -04:00
|
|
|
|
- if the installed file is located elsewhere in the system, a
|
2009-04-24 12:03:02 -04:00
|
|
|
|
'/'-separated absolute path is used.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
This will require changing the way the `install` command writes the record
|
2009-05-14 05:32:29 -04:00
|
|
|
|
file, so the old `record` behavior will be deprecated.
|
2009-04-24 12:03:02 -04:00
|
|
|
|
|
2009-02-21 21:33:52 -05:00
|
|
|
|
Back to our `zlib` example, we will have::
|
|
|
|
|
|
|
|
|
|
- zlib
|
2009-03-28 14:49:24 -04:00
|
|
|
|
- zlib-2.5.2.egg-info/
|
2009-02-21 21:33:52 -05:00
|
|
|
|
PKG-INFO
|
|
|
|
|
RECORD
|
|
|
|
|
|
|
|
|
|
New functions in pkgutil
|
|
|
|
|
========================
|
|
|
|
|
|
2009-04-13 16:52:58 -04:00
|
|
|
|
To use the `.egg-info` directory content, we need to add in the standard
|
|
|
|
|
library a set of APIs. The best place to put these APIs seems to be `pkgutil`.
|
|
|
|
|
|
2009-02-21 21:33:52 -05:00
|
|
|
|
The new functions added in the package are :
|
|
|
|
|
|
2009-04-13 16:52:58 -04:00
|
|
|
|
- get_egg_info(project_name) -> path or None
|
2009-02-23 20:01:04 -05:00
|
|
|
|
|
2009-05-14 17:52:58 -04:00
|
|
|
|
Scans all elements in `sys.path` and looks for all directories ending with
|
|
|
|
|
`.egg-info`. Returns the directory path that contains a PKG-INFO that matches
|
2009-04-13 16:52:58 -04:00
|
|
|
|
`project_name` for the `name` metadata. Notice that there should be at most
|
|
|
|
|
one result. The first result founded will be returned.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-02-23 20:01:04 -05:00
|
|
|
|
If the directory is not found, returns None.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-05-14 17:52:58 -04:00
|
|
|
|
XXX The implementation of `get_egg_info` will focus on minimizing the I/O
|
|
|
|
|
accesses.
|
|
|
|
|
|
2009-04-13 16:52:58 -04:00
|
|
|
|
- get_metadata(project_name) -> DistributionMetadata or None
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
|
|
|
|
Uses `get_egg_info` to get the `PKG-INFO` file, and returns a
|
|
|
|
|
`DistributionMetadata` instance that contains the metadata.
|
|
|
|
|
This will require a small change in `DistributionMetadata` (see #4908).
|
|
|
|
|
|
2009-04-13 16:52:58 -04:00
|
|
|
|
- get_egg_info_file(project_name, filename) -> file object or None
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
|
|
|
|
Uses `get_egg_info` and gets any file inside the directory,
|
|
|
|
|
pointed by filename.
|
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
Let's use it with our `zlib` example::
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
|
|
|
|
>>> from pkgutil import get_egg_info, get_metadata, get_egg_info_file
|
|
|
|
|
>>> get_egg_info('zlib')
|
2009-03-28 14:53:28 -04:00
|
|
|
|
'/opt/local/lib/python2.6/site-packages/zlib-2.5.2.egg-info'
|
2009-02-21 21:33:52 -05:00
|
|
|
|
>>> metadata = get_metadata('zlib')
|
|
|
|
|
>>> metadata.version
|
|
|
|
|
'2.5.2'
|
2009-05-07 05:02:23 -04:00
|
|
|
|
>>> get_egg_info_file('zlib', 'PKG-INFO').read()
|
2009-02-21 21:33:52 -05:00
|
|
|
|
some
|
|
|
|
|
...
|
|
|
|
|
files
|
|
|
|
|
|
2009-05-07 05:02:23 -04:00
|
|
|
|
Adding an Uninstall function
|
|
|
|
|
============================
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
Distutils provides a very basic way to install a project, which is running
|
|
|
|
|
the `install` command over the `setup.py` script of the distribution.
|
2009-03-28 15:08:48 -04:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
Distutils will provide a very basic `uninstall` command that will remove
|
|
|
|
|
all files listed in the `RECORD` file of a project, as long as they are not
|
2009-05-14 05:32:29 -04:00
|
|
|
|
mentioned in another `RECORD` file and as long as the package is installed
|
|
|
|
|
using the standard described earlier.
|
2009-03-28 15:08:48 -04:00
|
|
|
|
|
2009-05-14 05:32:29 -04:00
|
|
|
|
This command will be added in ``distutils.util`` and will take the name
|
|
|
|
|
of the project to uninstall as its argument. A call to uninstall will return a
|
|
|
|
|
list of uninstalled files::
|
2009-03-28 15:08:48 -04:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
>>> from distutils.util import uninstall
|
|
|
|
|
>>> uninstall('zlib')
|
2009-05-07 05:02:23 -04:00
|
|
|
|
['/opt/local/lib/python2.6/site-packages/zlib/file1',
|
|
|
|
|
'/opt/local/lib/python2.6/site-packages/zlib/file2']
|
|
|
|
|
|
|
|
|
|
If the project is not found, a ``DistutilsUninstallError`` will be raised.
|
2009-03-28 15:08:48 -04:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
To make it a reference API for third-party projects that wish to provide
|
2009-05-14 05:32:29 -04:00
|
|
|
|
an `uninstall feature`. The ``uninstall`` function can also be invoked with a
|
2009-04-24 12:03:02 -04:00
|
|
|
|
second callable argument, that will be invoked for each file to be removed.
|
2009-05-14 05:32:29 -04:00
|
|
|
|
If this callable returns `True`, the file will be removed.
|
2009-03-28 15:08:48 -04:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
Examples::
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
>>> def _remove_and_log(path):
|
|
|
|
|
... logging.info('Removing %s' % path)
|
|
|
|
|
... return True
|
|
|
|
|
>>> uninstall('zlib', _remove_and_log)
|
2009-05-07 05:02:23 -04:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
>>> def _dry_run(path):
|
|
|
|
|
... logging.info('Removing %s (dry run)' % path)
|
|
|
|
|
... return False
|
|
|
|
|
>>> uninstall('zlib', _dry_run)
|
2009-03-28 15:08:48 -04:00
|
|
|
|
|
2009-05-14 05:32:29 -04:00
|
|
|
|
Backward compatibility and roadmap
|
|
|
|
|
==================================
|
|
|
|
|
|
|
|
|
|
These changes will not introduce any compatibility problems with the previous
|
|
|
|
|
version of Distutils, and will also work with existing third-party tools.
|
|
|
|
|
|
2009-05-14 18:19:41 -04:00
|
|
|
|
Although, a backport of the new Distutils for 2.5, 2.6, 3.0 and 3.1 will be
|
|
|
|
|
provided so people can benefit from the new features.
|
|
|
|
|
|
2009-05-14 05:32:29 -04:00
|
|
|
|
The plan is to integrate them for Python 2.7 and Python 3.2
|
2009-03-28 15:08:48 -04:00
|
|
|
|
|
|
|
|
|
Aknowledgments
|
|
|
|
|
==============
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-03-28 15:08:48 -04:00
|
|
|
|
Jim Fulton, Ian Bicking, Phillip Eby, and many people at Pycon and Distutils-SIG.
|
2009-02-28 09:22:01 -05:00
|
|
|
|
|
2009-02-21 21:33:52 -05:00
|
|
|
|
Copyright
|
|
|
|
|
=========
|
|
|
|
|
|
|
|
|
|
This document has been placed in the public domain.
|
|
|
|
|
|
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
|
2009-02-21 21:33:52 -05:00
|
|
|
|
..
|
|
|
|
|
Local Variables:
|
|
|
|
|
mode: indented-text
|
|
|
|
|
indent-tabs-mode: nil
|
|
|
|
|
sentence-end-double-space: t
|
|
|
|
|
fill-column: 70
|
|
|
|
|
coding: utf-8
|
|
|
|
|
End:
|