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.
|
|
|
|
|
- An install script to install a package in Python.
|
|
|
|
|
- An uninstall script to uninstall a package in Python.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
|
2009-02-21 21:33:52 -05:00
|
|
|
|
Rationale
|
|
|
|
|
=========
|
|
|
|
|
|
|
|
|
|
There are three problems right now in the way packages
|
|
|
|
|
are installed in Python:
|
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
- There are too many ways to install a package in Python.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
|
|
|
|
- There is no way to uninstall a package.
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
How packages are installed
|
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
|
|
Right now, when a package is installed in Python, using the
|
|
|
|
|
Distutils `install` command, the `install_egg_info` subcommand is
|
|
|
|
|
called in order to create an `.egg-info` file in the site-packages directory,
|
|
|
|
|
right beside the package itself.
|
|
|
|
|
|
|
|
|
|
For example, if the `zlib` package is installed, two elements
|
|
|
|
|
will be installed in `site-packages`::
|
|
|
|
|
|
|
|
|
|
- zlib
|
|
|
|
|
- zlib-2.5.2-py2.6.egg-info
|
|
|
|
|
|
|
|
|
|
Where `zlib` is the package itself, and `zlib-2.5.2-py2.6.egg-info` is
|
|
|
|
|
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,
|
|
|
|
|
and adds a `PKG-INFO` file inside this directory, amongst other files.
|
|
|
|
|
|
|
|
|
|
- `pip` creates an `.egg-info` directory inside the site-packages directory
|
2009-02-28 09:22:01 -05:00
|
|
|
|
besides the package, and adds a `PKG-INFO` file inside it.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
|
|
|
|
They both add other files in the `EGG-INFO` or `.egg-info` directory, and
|
|
|
|
|
create or modify `.pth` files. `pip` also creates one `.pth` file
|
|
|
|
|
per installed package, which may lead to slow initialisation of Python.
|
|
|
|
|
|
|
|
|
|
The uninstall command
|
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
|
|
Python doesn't provide any `uninstall` command. If you want to uninstall
|
|
|
|
|
a package, you have to be a power user and remove the package directory
|
|
|
|
|
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-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
|
|
|
|
|
depending on the tool used by the packager (distutils or setuptools).
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
Installing a package
|
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
|
|
There are too many different ways to install a package in Python:
|
|
|
|
|
|
|
|
|
|
- by hand, by getting a distribution and running the install command
|
|
|
|
|
- using `easy_install`, the script provided by setuptools
|
|
|
|
|
- using `pip`
|
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
The problem is: they do not install the package the same way,
|
2009-02-21 21:33:52 -05:00
|
|
|
|
and Python should provide one and only one way to do it.
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
- some new functions in `pkgutil`
|
2009-02-28 09:22:01 -05:00
|
|
|
|
- addition of an install and an uninstall script
|
|
|
|
|
|
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
|
|
|
|
|
- zlib-2.5.2-py2.6.egg-info/
|
|
|
|
|
PKG-INFO
|
|
|
|
|
|
|
|
|
|
To be able to implement this change, the impacted code in Distutils
|
|
|
|
|
is the `install_egg_info` command.
|
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
|
2009-02-21 21:33:52 -05:00
|
|
|
|
Adding MANIFEST and RECORD in the .egg-info directory
|
|
|
|
|
=====================================================
|
|
|
|
|
|
|
|
|
|
Some files can be added inside the `.egg-info` directory at installation
|
|
|
|
|
time. They will all be UPPERCASE files.
|
|
|
|
|
|
|
|
|
|
- the `MANIFEST` file built by the `sdist` command. Notice that
|
2009-02-28 09:22:01 -05:00
|
|
|
|
some fixes were made lately on the default file names added in `MANIFEST`
|
2009-02-21 21:33:52 -05:00
|
|
|
|
when `MANIFEST.in` is not provided (see #2279 for instance).
|
|
|
|
|
|
|
|
|
|
- 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-02-21 21:33:52 -05:00
|
|
|
|
explained later in this PEP.
|
|
|
|
|
|
|
|
|
|
The `install` command will record by default installed files in the
|
|
|
|
|
RECORD file.
|
|
|
|
|
|
|
|
|
|
The `sdist` module will introduce an `EGG_INFO_FILES` constant to list
|
|
|
|
|
all files located in the `.egg-info` directory::
|
|
|
|
|
|
|
|
|
|
from collections import namedtuple
|
|
|
|
|
|
|
|
|
|
EggInfos = namedtuple('EggInfo', 'manifest record pkg_info')
|
|
|
|
|
|
|
|
|
|
# files added in egg-info
|
|
|
|
|
EGG_INFO_FILES = EggInfos('MANIFEST', 'RECORD', 'PKG-INFO')
|
|
|
|
|
|
|
|
|
|
Back to our `zlib` example, we will have::
|
|
|
|
|
|
|
|
|
|
- zlib
|
|
|
|
|
- zlib-2.5.2-py2.6.egg-info/
|
|
|
|
|
PKG-INFO
|
|
|
|
|
MANIFEST
|
|
|
|
|
RECORD
|
|
|
|
|
|
2009-02-23 20:01:04 -05:00
|
|
|
|
XXX See if we want to keep the 2.5.2-py2.6 part
|
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
|
2009-02-21 21:33:52 -05:00
|
|
|
|
New functions in pkgutil
|
|
|
|
|
========================
|
|
|
|
|
|
|
|
|
|
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`.
|
|
|
|
|
|
|
|
|
|
The new functions added in the package are :
|
|
|
|
|
|
2009-02-23 20:01:04 -05:00
|
|
|
|
- get_egg_info(pkg_name) -> path or None
|
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
Scans all site-packages directories and looks for all `pkg_name.egg-info`
|
|
|
|
|
directories. Returns the directory path that contains a PKG-INFO that matches
|
2009-02-23 20:01:04 -05:00
|
|
|
|
`pkg_name` for the `name` metadata. Notice that there should be at most
|
2009-02-28 09:22:01 -05:00
|
|
|
|
one result. If more than one path matches the pkg_name, a DistutilsError
|
2009-02-23 20:01:04 -05:00
|
|
|
|
is raised.
|
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
|
|
|
|
|
|
|
|
|
- get_metadata(pkg_name) -> DistributionMetadata or None
|
|
|
|
|
|
|
|
|
|
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).
|
|
|
|
|
|
|
|
|
|
- get_egg_info_file(pkg_name, filename) -> file object or None
|
|
|
|
|
|
|
|
|
|
Uses `get_egg_info` and gets any file inside the directory,
|
|
|
|
|
pointed by filename.
|
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
filename can be any value found in `distutils.sdist.EGG_INFO_FILES`.
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
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')
|
|
|
|
|
'/opt/local/lib/python2.6/site-packages/zlib-2.5.2-py2.6.egg-info'
|
|
|
|
|
>>> metadata = get_metadata('zlib')
|
|
|
|
|
>>> metadata.version
|
|
|
|
|
'2.5.2'
|
|
|
|
|
>>> from distutils.dist import EGG_INFO_FILES
|
2009-02-23 20:01:04 -05:00
|
|
|
|
>>> get_egg_info_file('zlib', EGG_INFO_FILES.manifest).read()
|
2009-02-21 21:33:52 -05:00
|
|
|
|
some
|
|
|
|
|
...
|
|
|
|
|
files
|
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
|
2009-02-21 21:33:52 -05:00
|
|
|
|
Adding an install and an uninstall script
|
|
|
|
|
=========================================
|
|
|
|
|
|
|
|
|
|
`easy_install` and `pip` does basically the same work, besides other features
|
|
|
|
|
that are not discussed here.
|
|
|
|
|
|
|
|
|
|
- they look for the package at PyPI
|
|
|
|
|
- they download it and build it
|
|
|
|
|
- they install it inside the site-packages directory
|
|
|
|
|
- they add an entry in a .pth file
|
|
|
|
|
|
|
|
|
|
A new script called `install.py` is added in a new directory called `scripts`
|
2009-02-28 09:22:01 -05:00
|
|
|
|
in Distutils, and lets people run an installation using::
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
$ python -m distutils.scripts.install zlib
|
2009-02-21 21:33:52 -05:00
|
|
|
|
|
2009-02-28 09:22:01 -05:00
|
|
|
|
An uninstall command is added as well that removes the files recorded
|
|
|
|
|
in the RECORD file. This removal will warn on files that no longer exist
|
2009-02-21 21:33:52 -05:00
|
|
|
|
and will not take care of side effects, like the removal of a file
|
|
|
|
|
used by another element of the system.
|
|
|
|
|
|
|
|
|
|
XXX work to be done here : specification of the two commands
|
|
|
|
|
(probably a mix of easy_install and pip)
|
|
|
|
|
|
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:
|