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
|
|
|
|
|
Python-Version: 2.7, 3.1
|
|
|
|
|
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-04-24 12:03:02 -04:00
|
|
|
|
There are three 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-02-28 09:22:01 -05:00
|
|
|
|
- There is no API to get the metadata of installed packages.
|
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-04-24 12:03:02 -04:00
|
|
|
|
For example, if the `zlib` project is installed (which contains one package),
|
|
|
|
|
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-02-28 09:22:01 -05:00
|
|
|
|
command, and will always be generated. This will allow uninstall, 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.
|
|
|
|
|
|
|
|
|
|
- if the installed file is located elswhere in the system, a
|
|
|
|
|
'/'-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
|
|
|
|
|
file, so the old `record` behavior will be deprecated.
|
|
|
|
|
XXX see how to handle old record (new option, or wait for 2 version?)
|
|
|
|
|
|
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-04-13 16:52:58 -04:00
|
|
|
|
Scans all site-packages directories and looks for all `project_name.egg-info`
|
2009-02-28 09:22:01 -05:00
|
|
|
|
directories. 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-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
|
|
|
|
|
mentioned in another `RECORD` file.
|
2009-03-28 15:08:48 -04:00
|
|
|
|
|
2009-04-24 12:03:02 -04:00
|
|
|
|
This command will be added in the `util` module and will take the name
|
2009-05-07 05:02:23 -04:00
|
|
|
|
of the project to uninstall. A call to uninstall will return a list
|
|
|
|
|
of uninstalled files. If the project is not found, a Distutils::
|
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
|
|
|
|
|
an `uninstall feature`. The `uninstall` API can also be invoked with a
|
|
|
|
|
second callable argument, that will be invoked for each file to be removed.
|
|
|
|
|
If it 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|