• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1=====================================
2The Internal Structure of Python Eggs
3=====================================
4
5STOP! This is not the first document you should read!
6
7
8
9.. contents:: **Table of Contents**
10
11
12----------------------
13Eggs and their Formats
14----------------------
15
16A "Python egg" is a logical structure embodying the release of a
17specific version of a Python project, comprising its code, resources,
18and metadata. There are multiple formats that can be used to physically
19encode a Python egg, and others can be developed. However, a key
20principle of Python eggs is that they should be discoverable and
21importable. That is, it should be possible for a Python application to
22easily and efficiently find out what eggs are present on a system, and
23to ensure that the desired eggs' contents are importable.
24
25There are two basic formats currently implemented for Python eggs:
26
271. ``.egg`` format: a directory or zipfile *containing* the project's
28   code and resources, along with an ``EGG-INFO`` subdirectory that
29   contains the project's metadata
30
312. ``.egg-info`` format: a file or directory placed *adjacent* to the
32   project's code and resources, that directly contains the project's
33   metadata.
34
35Both formats can include arbitrary Python code and resources, including
36static data files, package and non-package directories, Python
37modules, C extension modules, and so on.  But each format is optimized
38for different purposes.
39
40The ``.egg`` format is well-suited to distribution and the easy
41uninstallation or upgrades of code, since the project is essentially
42self-contained within a single directory or file, unmingled with any
43other projects' code or resources.  It also makes it possible to have
44multiple versions of a project simultaneously installed, such that
45individual programs can select the versions they wish to use.
46
47The ``.egg-info`` format, on the other hand, was created to support
48backward-compatibility, performance, and ease of installation for system
49packaging tools that expect to install all projects' code and resources
50to a single directory (e.g. ``site-packages``).  Placing the metadata
51in that same directory simplifies the installation process, since it
52isn't necessary to create ``.pth`` files or otherwise modify
53``sys.path`` to include each installed egg.
54
55Its disadvantage, however, is that it provides no support for clean
56uninstallation or upgrades, and of course only a single version of a
57project can be installed to a given directory. Thus, support from a
58package management tool is required. (This is why setuptools' "install"
59command refers to this type of egg installation as "single-version,
60externally managed".)  Also, they lack sufficient data to allow them to
61be copied from their installation source.  easy_install can "ship" an
62application by copying ``.egg`` files or directories to a target
63location, but it cannot do this for ``.egg-info`` installs, because
64there is no way to tell what code and resources belong to a particular
65egg -- there may be several eggs "scrambled" together in a single
66installation location, and the ``.egg-info`` format does not currently
67include a way to list the files that were installed.  (This may change
68in a future version.)
69
70
71Code and Resources
72==================
73
74The layout of the code and resources is dictated by Python's normal
75import layout, relative to the egg's "base location".
76
77For the ``.egg`` format, the base location is the ``.egg`` itself. That
78is, adding the ``.egg`` filename or directory name to ``sys.path``
79makes its contents importable.
80
81For the ``.egg-info`` format, however, the base location is the
82directory that *contains* the ``.egg-info``, and thus it is the
83directory that must be added to ``sys.path`` to make the egg importable.
84(Note that this means that the "normal" installation of a package to a
85``sys.path`` directory is sufficient to make it an "egg" if it has an
86``.egg-info`` file or directory installed alongside of it.)
87
88
89Project Metadata
90=================
91
92If eggs contained only code and resources, there would of course be
93no difference between them and any other directory or zip file on
94``sys.path``.  Thus, metadata must also be included, using a metadata
95file or directory.
96
97For the ``.egg`` format, the metadata is placed in an ``EGG-INFO``
98subdirectory, directly within the ``.egg`` file or directory.  For the
99``.egg-info`` format, metadata is stored directly within the
100``.egg-info`` directory itself.
101
102The minimum project metadata that all eggs must have is a standard
103Python ``PKG-INFO`` file, named ``PKG-INFO`` and placed within the
104metadata directory appropriate to the format.  Because it's possible for
105this to be the only metadata file included, ``.egg-info`` format eggs
106are not required to be a directory; they can just be a ``.egg-info``
107file that directly contains the ``PKG-INFO`` metadata.  This eliminates
108the need to create a directory just to store one file.  This option is
109*not* available for ``.egg`` formats, since setuptools always includes
110other metadata.  (In fact, setuptools itself never generates
111``.egg-info`` files, either; the support for using files was added so
112that the requirement could easily be satisfied by other tools, such
113as distutils).
114
115In addition to the ``PKG-INFO`` file, an egg's metadata directory may
116also include files and directories representing various forms of
117optional standard metadata (see the section on `Standard Metadata`_,
118below) or user-defined metadata required by the project.  For example,
119some projects may define a metadata format to describe their application
120plugins, and metadata in this format would then be included by plugin
121creators in their projects' metadata directories.
122
123
124Filename-Embedded Metadata
125==========================
126
127To allow introspection of installed projects and runtime resolution of
128inter-project dependencies, a certain amount of information is embedded
129in egg filenames.  At a minimum, this includes the project name, and
130ideally will also include the project version number.  Optionally, it
131can also include the target Python version and required runtime
132platform if platform-specific C code is included.  The syntax of an
133egg filename is as follows::
134
135    name ["-" version ["-py" pyver ["-" required_platform]]] "." ext
136
137The "name" and "version" should be escaped using the ``to_filename()``
138function provided by ``pkg_resources``, after first processing them with
139``safe_name()`` and ``safe_version()`` respectively.  These latter two
140functions can also be used to later "unescape" these parts of the
141filename.  (For a detailed description of these transformations, please
142see the "Parsing Utilities" section of the ``pkg_resources`` manual.)
143
144The "pyver" string is the Python major version, as found in the first
1453 characters of ``sys.version``.  "required_platform" is essentially
146a distutils ``get_platform()`` string, but with enhancements to properly
147distinguish Mac OS versions.  (See the ``get_build_platform()``
148documentation in the "Platform Utilities" section of the
149``pkg_resources`` manual for more details.)
150
151Finally, the "ext" is either ``.egg`` or ``.egg-info``, as appropriate
152for the egg's format.
153
154Normally, an egg's filename should include at least the project name and
155version, as this allows the runtime system to find desired project
156versions without having to read the egg's PKG-INFO to determine its
157version number.
158
159Setuptools, however, only includes the version number in the filename
160when an ``.egg`` file is built using the ``bdist_egg`` command, or when
161an ``.egg-info`` directory is being installed by the
162``install_egg_info`` command. When generating metadata for use with the
163original source tree, it only includes the project name, so that the
164directory will not have to be renamed each time the project's version
165changes.
166
167This is especially important when version numbers change frequently, and
168the source metadata directory is kept under version control with the
169rest of the project.  (As would be the case when the project's source
170includes project-defined metadata that is not generated from by
171setuptools from data in the setup script.)
172
173
174Egg Links
175=========
176
177In addition to the ``.egg`` and ``.egg-info`` formats, there is a third
178egg-related extension that you may encounter on occasion: ``.egg-link``
179files.
180
181These files are not eggs, strictly speaking. They simply provide a way
182to reference an egg that is not physically installed in the desired
183location. They exist primarily as a cross-platform alternative to
184symbolic links, to support "installing" code that is being developed in
185a different location than the desired installation location. For
186example, if a user is developing an application plugin in their home
187directory, but the plugin needs to be "installed" in an application
188plugin directory, running "setup.py develop -md /path/to/app/plugins"
189will install an ``.egg-link`` file in ``/path/to/app/plugins``, that
190tells the egg runtime system where to find the actual egg (the user's
191project source directory and its ``.egg-info`` subdirectory).
192
193``.egg-link`` files are named following the format for ``.egg`` and
194``.egg-info`` names, but only the project name is included; no version,
195Python version, or platform information is included.  When the runtime
196searches for available eggs, ``.egg-link`` files are opened and the
197actual egg file/directory name is read from them.
198
199Each ``.egg-link`` file should contain a single file or directory name,
200with no newlines.  This filename should be the base location of one or
201more eggs.  That is, the name must either end in ``.egg``, or else it
202should be the parent directory of one or more ``.egg-info`` format eggs.
203
204As of setuptools 0.6c6, the path may be specified as a platform-independent
205(i.e. ``/``-separated) relative path from the directory containing the
206``.egg-link`` file, and a second line may appear in the file, specifying a
207platform-independent relative path from the egg's base directory to its
208setup script directory.  This allows installation tools such as EasyInstall
209to find the project's setup directory and build eggs or perform other setup
210commands on it.
211
212
213-----------------
214Standard Metadata
215-----------------
216
217In addition to the minimum required ``PKG-INFO`` metadata, projects can
218include a variety of standard metadata files or directories, as
219described below.  Except as otherwise noted, these files and directories
220are automatically generated by setuptools, based on information supplied
221in the setup script or through analysis of the project's code and
222resources.
223
224Most of these files and directories are generated via "egg-info
225writers" during execution of the setuptools ``egg_info`` command, and
226are listed in the ``egg_info.writers`` entry point group defined by
227setuptools' own ``setup.py`` file.
228
229Project authors can register their own metadata writers as entry points
230in this group (as described in the setuptools manual under "Adding new
231EGG-INFO Files") to cause setuptools to generate project-specific
232metadata files or directories during execution of the ``egg_info``
233command.  It is up to project authors to document these new metadata
234formats, if they create any.
235
236
237``.txt`` File Formats
238=====================
239
240Files described in this section that have ``.txt`` extensions have a
241simple lexical format consisting of a sequence of text lines, each line
242terminated by a linefeed character (regardless of platform).  Leading
243and trailing whitespace on each line is ignored, as are blank lines and
244lines whose first nonblank character is a ``#`` (comment symbol).  (This
245is the parsing format defined by the ``yield_lines()`` function of
246the ``pkg_resources`` module.)
247
248All ``.txt`` files defined by this section follow this format, but some
249are also "sectioned" files, meaning that their contents are divided into
250sections, using square-bracketed section headers akin to Windows
251``.ini`` format.  Note that this does *not* imply that the lines within
252the sections follow an ``.ini`` format, however.  Please see an
253individual metadata file's documentation for a description of what the
254lines and section names mean in that particular file.
255
256Sectioned files can be parsed using the ``split_sections()`` function;
257see the "Parsing Utilities" section of the ``pkg_resources`` manual for
258for details.
259
260
261Dependency Metadata
262===================
263
264
265``requires.txt``
266----------------
267
268This is a "sectioned" text file.  Each section is a sequence of
269"requirements", as parsed by the ``parse_requirements()`` function;
270please see the ``pkg_resources`` manual for the complete requirement
271parsing syntax.
272
273The first, unnamed section (i.e., before the first section header) in
274this file is the project's core requirements, which must be installed
275for the project to function.  (Specified using the ``install_requires``
276keyword to ``setup()``).
277
278The remaining (named) sections describe the project's "extra"
279requirements, as specified using the ``extras_require`` keyword to
280``setup()``.  The section name is the name of the optional feature, and
281the section body lists that feature's dependencies.
282
283Note that it is not normally necessary to inspect this file directly;
284``pkg_resources.Distribution`` objects have a ``requires()`` method
285that can be used to obtain ``Requirement`` objects describing the
286project's core and optional dependencies.
287
288
289``setup_requires.txt``
290----------------------
291
292Much like ``requires.txt`` except represents the requirements
293specified by the ``setup_requires`` parameter to the Distribution.
294
295
296``dependency_links.txt``
297------------------------
298
299A list of dependency URLs, one per line, as specified using the
300``dependency_links`` keyword to ``setup()``.  These may be direct
301download URLs, or the URLs of web pages containing direct download
302links, and will be used by EasyInstall to find dependencies, as though
303the user had manually provided them via the ``--find-links`` command
304line option.  Please see the setuptools manual and EasyInstall manual
305for more information on specifying this option, and for information on
306how EasyInstall processes ``--find-links`` URLs.
307
308
309``depends.txt`` -- Obsolete, do not create!
310-------------------------------------------
311
312This file follows an identical format to ``requires.txt``, but is
313obsolete and should not be used.  The earliest versions of setuptools
314required users to manually create and maintain this file, so the runtime
315still supports reading it, if it exists.  The new filename was created
316so that it could be automatically generated from ``setup()`` information
317without overwriting an existing hand-created ``depends.txt``, if one
318was already present in the project's source ``.egg-info`` directory.
319
320
321``namespace_packages.txt`` -- Namespace Package Metadata
322========================================================
323
324A list of namespace package names, one per line, as supplied to the
325``namespace_packages`` keyword to ``setup()``.  Please see the manuals
326for setuptools and ``pkg_resources`` for more information about
327namespace packages.
328
329
330``entry_points.txt`` -- "Entry Point"/Plugin Metadata
331=====================================================
332
333This is a "sectioned" text file, whose contents encode the
334``entry_points`` keyword supplied to ``setup()``.  All sections are
335named, as the section names specify the entry point groups in which the
336corresponding section's entry points are registered.
337
338Each section is a sequence of "entry point" lines, each parseable using
339the ``EntryPoint.parse`` classmethod; please see the ``pkg_resources``
340manual for the complete entry point parsing syntax.
341
342Note that it is not necessary to parse this file directly; the
343``pkg_resources`` module provides a variety of APIs to locate and load
344entry points automatically.  Please see the setuptools and
345``pkg_resources`` manuals for details on the nature and uses of entry
346points.
347
348
349The ``scripts`` Subdirectory
350============================
351
352This directory is currently only created for ``.egg`` files built by
353the setuptools ``bdist_egg`` command.  It will contain copies of all
354of the project's "traditional" scripts (i.e., those specified using the
355``scripts`` keyword to ``setup()``).  This is so that they can be
356reconstituted when an ``.egg`` file is installed.
357
358The scripts are placed here using the distutils' standard
359``install_scripts`` command, so any ``#!`` lines reflect the Python
360installation where the egg was built.  But instead of copying the
361scripts to the local script installation directory, EasyInstall writes
362short wrapper scripts that invoke the original scripts from inside the
363egg, after ensuring that sys.path includes the egg and any eggs it
364depends on.  For more about `script wrappers`_, see the section below on
365`Installation and Path Management Issues`_.
366
367
368Zip Support Metadata
369====================
370
371
372``native_libs.txt``
373-------------------
374
375A list of C extensions and other dynamic link libraries contained in
376the egg, one per line.  Paths are ``/``-separated and relative to the
377egg's base location.
378
379This file is generated as part of ``bdist_egg`` processing, and as such
380only appears in ``.egg`` files (and ``.egg`` directories created by
381unpacking them).  It is used to ensure that all libraries are extracted
382from a zipped egg at the same time, in case there is any direct linkage
383between them.  Please see the `Zip File Issues`_ section below for more
384information on library and resource extraction from ``.egg`` files.
385
386
387``eager_resources.txt``
388-----------------------
389
390A list of resource files and/or directories, one per line, as specified
391via the ``eager_resources`` keyword to ``setup()``.  Paths are
392``/``-separated and relative to the egg's base location.
393
394Resource files or directories listed here will be extracted
395simultaneously, if any of the named resources are extracted, or if any
396native libraries listed in ``native_libs.txt`` are extracted.  Please
397see the setuptools manual for details on what this feature is used for
398and how it works, as well as the `Zip File Issues`_ section below.
399
400
401``zip-safe`` and ``not-zip-safe``
402---------------------------------
403
404These are zero-length files, and either one or the other should exist.
405If ``zip-safe`` exists, it means that the project will work properly
406when installed as an ``.egg`` zipfile, and conversely the existence of
407``not-zip-safe`` means the project should not be installed as an
408``.egg`` file.  The ``zip_safe`` option to setuptools' ``setup()``
409determines which file will be written. If the option isn't provided,
410setuptools attempts to make its own assessment of whether the package
411can work, based on code and content analysis.
412
413If neither file is present at installation time, EasyInstall defaults
414to assuming that the project should be unzipped.  (Command-line options
415to EasyInstall, however, take precedence even over an existing
416``zip-safe`` or ``not-zip-safe`` file.)
417
418Note that these flag files appear only in ``.egg`` files generated by
419``bdist_egg``, and in ``.egg`` directories created by unpacking such an
420``.egg`` file.
421
422
423
424``top_level.txt`` -- Conflict Management Metadata
425=================================================
426
427This file is a list of the top-level module or package names provided
428by the project, one Python identifier per line.
429
430Subpackages are not included; a project containing both a ``foo.bar``
431and a ``foo.baz`` would include only one line, ``foo``, in its
432``top_level.txt``.
433
434This data is used by ``pkg_resources`` at runtime to issue a warning if
435an egg is added to ``sys.path`` when its contained packages may have
436already been imported.
437
438(It was also once used to detect conflicts with non-egg packages at
439installation time, but in more recent versions, setuptools installs eggs
440in such a way that they always override non-egg packages, thus
441preventing a problem from arising.)
442
443
444``SOURCES.txt`` -- Source Files Manifest
445========================================
446
447This file is roughly equivalent to the distutils' ``MANIFEST`` file.
448The differences are as follows:
449
450* The filenames always use ``/`` as a path separator, which must be
451  converted back to a platform-specific path whenever they are read.
452
453* The file is automatically generated by setuptools whenever the
454  ``egg_info`` or ``sdist`` commands are run, and it is *not*
455  user-editable.
456
457Although this metadata is included with distributed eggs, it is not
458actually used at runtime for any purpose.  Its function is to ensure
459that setuptools-built *source* distributions can correctly discover
460what files are part of the project's source, even if the list had been
461generated using revision control metadata on the original author's
462system.
463
464In other words, ``SOURCES.txt`` has little or no runtime value for being
465included in distributed eggs, and it is possible that future versions of
466the ``bdist_egg`` and ``install_egg_info`` commands will strip it before
467installation or distribution.  Therefore, do not rely on its being
468available outside of an original source directory or source
469distribution.
470
471
472------------------------------
473Other Technical Considerations
474------------------------------
475
476
477Zip File Issues
478===============
479
480Although zip files resemble directories, they are not fully
481substitutable for them.  Most platforms do not support loading dynamic
482link libraries contained in zipfiles, so it is not possible to directly
483import C extensions from ``.egg`` zipfiles.  Similarly, there are many
484existing libraries -- whether in Python or C -- that require actual
485operating system filenames, and do not work with arbitrary "file-like"
486objects or in-memory strings, and thus cannot operate directly on the
487contents of zip files.
488
489To address these issues, the ``pkg_resources`` module provides a
490"resource API" to support obtaining either the contents of a resource,
491or a true operating system filename for the resource.  If the egg
492containing the resource is a directory, the resource's real filename
493is simply returned.  However, if the egg is a zipfile, then the
494resource is first extracted to a cache directory, and the filename
495within the cache is returned.
496
497The cache directory is determined by the ``pkg_resources`` API; please
498see the ``set_cache_path()`` and ``get_default_cache()`` documentation
499for details.
500
501
502The Extraction Process
503----------------------
504
505Resources are extracted to a cache subdirectory whose name is based
506on the enclosing ``.egg`` filename and the path to the resource.  If
507there is already a file of the correct name, size, and timestamp, its
508filename is returned to the requester.  Otherwise, the desired file is
509extracted first to a temporary name generated using
510``mkstemp(".$extract",target_dir)``, and then its timestamp is set to
511match the one in the zip file, before renaming it to its final name.
512(Some collision detection and resolution code is used to handle the
513fact that Windows doesn't overwrite files when renaming.)
514
515If a resource directory is requested, all of its contents are
516recursively extracted in this fashion, to ensure that the directory
517name can be used as if it were valid all along.
518
519If the resource requested for extraction is listed in the
520``native_libs.txt`` or ``eager_resources.txt`` metadata files, then
521*all* resources listed in *either* file will be extracted before the
522requested resource's filename is returned, thus ensuring that all
523C extensions and data used by them will be simultaneously available.
524
525
526Extension Import Wrappers
527-------------------------
528
529Since Python's built-in zip import feature does not support loading
530C extension modules from zipfiles, the setuptools ``bdist_egg`` command
531generates special import wrappers to make it work.
532
533The wrappers are ``.py`` files (along with corresponding ``.pyc``
534and/or ``.pyo`` files) that have the same module name as the
535corresponding C extension.  These wrappers are located in the same
536package directory (or top-level directory) within the zipfile, so that
537say, ``foomodule.so`` will get a corresponding ``foo.py``, while
538``bar/baz.pyd`` will get a corresponding ``bar/baz.py``.
539
540These wrapper files contain a short stanza of Python code that asks
541``pkg_resources`` for the filename of the corresponding C extension,
542then reloads the module using the obtained filename.  This will cause
543``pkg_resources`` to first ensure that all of the egg's C extensions
544(and any accompanying "eager resources") are extracted to the cache
545before attempting to link to the C library.
546
547Note, by the way, that ``.egg`` directories will also contain these
548wrapper files.  However, Python's default import priority is such that
549C extensions take precedence over same-named Python modules, so the
550import wrappers are ignored unless the egg is a zipfile.
551
552
553Installation and Path Management Issues
554=======================================
555
556Python's initial setup of ``sys.path`` is very dependent on the Python
557version and installation platform, as well as how Python was started
558(i.e., script vs. ``-c`` vs. ``-m`` vs. interactive interpreter).
559In fact, Python also provides only two relatively robust ways to affect
560``sys.path`` outside of direct manipulation in code: the ``PYTHONPATH``
561environment variable, and ``.pth`` files.
562
563However, with no cross-platform way to safely and persistently change
564environment variables, this leaves ``.pth`` files as EasyInstall's only
565real option for persistent configuration of ``sys.path``.
566
567But ``.pth`` files are rather strictly limited in what they are allowed
568to do normally.  They add directories only to the *end* of ``sys.path``,
569after any locally-installed ``site-packages`` directory, and they are
570only processed *in* the ``site-packages`` directory to start with.
571
572This is a double whammy for users who lack write access to that
573directory, because they can't create a ``.pth`` file that Python will
574read, and even if a sympathetic system administrator adds one for them
575that calls ``site.addsitedir()`` to allow some other directory to
576contain ``.pth`` files, they won't be able to install newer versions of
577anything that's installed in the systemwide ``site-packages``, because
578their paths will still be added *after* ``site-packages``.
579
580So EasyInstall applies two workarounds to solve these problems.
581
582The first is that EasyInstall leverages ``.pth`` files' "import" feature
583to manipulate ``sys.path`` and ensure that anything EasyInstall adds
584to a ``.pth`` file will always appear before both the standard library
585and the local ``site-packages`` directories.  Thus, it is always
586possible for a user who can write a Python-read ``.pth`` file to ensure
587that their packages come first in their own environment.
588
589Second, when installing to a ``PYTHONPATH`` directory (as opposed to
590a "site" directory like ``site-packages``) EasyInstall will also install
591a special version of the ``site`` module.  Because it's in a
592``PYTHONPATH`` directory, this module will get control before the
593standard library version of ``site`` does.  It will record the state of
594``sys.path`` before invoking the "real" ``site`` module, and then
595afterwards it processes any ``.pth`` files found in ``PYTHONPATH``
596directories, including all the fixups needed to ensure that eggs always
597appear before the standard library in sys.path, but are in a relative
598order to one another that is defined by their ``PYTHONPATH`` and
599``.pth``-prescribed sequence.
600
601The net result of these changes is that ``sys.path`` order will be
602as follows at runtime:
603
6041. The ``sys.argv[0]`` directory, or an empty string if no script
605   is being executed.
606
6072. All eggs installed by EasyInstall in any ``.pth`` file in each
608   ``PYTHONPATH`` directory, in order first by ``PYTHONPATH`` order,
609   then normal ``.pth`` processing order (which is to say alphabetical
610   by ``.pth`` filename, then by the order of listing within each
611   ``.pth`` file).
612
6133. All eggs installed by EasyInstall in any ``.pth`` file in each "site"
614   directory (such as ``site-packages``), following the same ordering
615   rules as for the ones on ``PYTHONPATH``.
616
6174. The ``PYTHONPATH`` directories themselves, in their original order
618
6195. Any paths from ``.pth`` files found on ``PYTHONPATH`` that were *not*
620   eggs installed by EasyInstall, again following the same relative
621   ordering rules.
622
6236. The standard library and "site" directories, along with the contents
624   of any ``.pth`` files found in the "site" directories.
625
626Notice that sections 1, 4, and 6 comprise the "normal" Python setup for
627``sys.path``.  Sections 2 and 3 are inserted to support eggs, and
628section 5 emulates what the "normal" semantics of ``.pth`` files on
629``PYTHONPATH`` would be if Python natively supported them.
630
631For further discussion of the tradeoffs that went into this design, as
632well as notes on the actual magic inserted into ``.pth`` files to make
633them do these things, please see also the following messages to the
634distutils-SIG mailing list:
635
636* http://mail.python.org/pipermail/distutils-sig/2006-February/006026.html
637* http://mail.python.org/pipermail/distutils-sig/2006-March/006123.html
638
639
640Script Wrappers
641---------------
642
643EasyInstall never directly installs a project's original scripts to
644a script installation directory.  Instead, it writes short wrapper
645scripts that first ensure that the project's dependencies are active
646on sys.path, before invoking the original script.  These wrappers
647have a #! line that points to the version of Python that was used to
648install them, and their second line is always a comment that indicates
649the type of script wrapper, the project version required for the script
650to run, and information identifying the script to be invoked.
651
652The format of this marker line is::
653
654    "# EASY-INSTALL-" script_type ": " tuple_of_strings "\n"
655
656The ``script_type`` is one of ``SCRIPT``, ``DEV-SCRIPT``, or
657``ENTRY-SCRIPT``.  The ``tuple_of_strings`` is a comma-separated
658sequence of Python string constants.  For ``SCRIPT`` and ``DEV-SCRIPT``
659wrappers, there are two strings: the project version requirement, and
660the script name (as a filename within the ``scripts`` metadata
661directory).  For ``ENTRY-SCRIPT`` wrappers, there are three:
662the project version requirement, the entry point group name, and the
663entry point name.  (See the "Automatic Script Creation" section in the
664setuptools manual for more information about entry point scripts.)
665
666In each case, the project version requirement string will be a string
667parseable with the ``pkg_resources`` modules' ``Requirement.parse()``
668classmethod.  The only difference between a ``SCRIPT`` wrapper and a
669``DEV-SCRIPT`` is that a ``DEV-SCRIPT`` actually executes the original
670source script in the project's source tree, and is created when the
671"setup.py develop" command is run.  A ``SCRIPT`` wrapper, on the other
672hand, uses the "installed" script written to the ``EGG-INFO/scripts``
673subdirectory of the corresponding ``.egg`` zipfile or directory.
674(``.egg-info`` eggs do not have script wrappers associated with them,
675except in the "setup.py develop" case.)
676
677The purpose of including the marker line in generated script wrappers is
678to facilitate introspection of installed scripts, and their relationship
679to installed eggs.  For example, an uninstallation tool could use this
680data to identify what scripts can safely be removed, and/or identify
681what scripts would stop working if a particular egg is uninstalled.
682
683