text stringlengths 0 888 |
|---|
from_location, from_filename (w/path normalization) |
Releases may have zero or more "Requirements", which indicate |
what releases of another project the release requires in order to |
function. A Requirement names the other project, expresses some criteria |
as to what releases of that project are acceptable, and lists any "Extras" |
that the requiring release may need from that project. (An Extra is an |
optional feature of a Release, that can only be used if its additional |
Requirements are satisfied.) |
The Working Set |
--------------- |
A collection of active distributions is called a Working Set. Note that a |
Working Set can contain any importable distribution, not just pluggable ones. |
For example, the Python standard library is an importable distribution that |
will usually be part of the Working Set, even though it is not pluggable. |
Similarly, when you are doing development work on a project, the files you are |
editing are also a Distribution. (And, with a little attention to the |
directory names used, and including some additional metadata, such a |
"development distribution" can be made pluggable as well.) |
>>> from pkg_resources import WorkingSet |
A working set's entries are the sys.path entries that correspond to the active |
distributions. By default, the working set's entries are the items on |
``sys.path``:: |
>>> ws = WorkingSet() |
>>> ws.entries == sys.path |
True |
But you can also create an empty working set explicitly, and add distributions |
to it:: |
>>> ws = WorkingSet([]) |
>>> ws.add(dist) |
>>> ws.entries |
['http://example.com/something'] |
>>> dist in ws |
True |
>>> Distribution('foo',version="") in ws |
False |
And you can iterate over its distributions:: |
>>> list(ws) |
[Bar 0.9 (http://example.com/something)] |
Adding the same distribution more than once is a no-op:: |
>>> ws.add(dist) |
>>> list(ws) |
[Bar 0.9 (http://example.com/something)] |
For that matter, adding multiple distributions for the same project also does |
nothing, because a working set can only hold one active distribution per |
project -- the first one added to it:: |
>>> ws.add( |
... Distribution( |
... 'http://example.com/something', project_name="Bar", |
... version="7.2" |
... ) |
... ) |
>>> list(ws) |
[Bar 0.9 (http://example.com/something)] |
You can append a path entry to a working set using ``add_entry()``:: |
>>> ws.entries |
['http://example.com/something'] |
>>> ws.add_entry(pkg_resources.__file__) |
>>> ws.entries |
['http://example.com/something', '...pkg_resources...'] |
Multiple additions result in multiple entries, even if the entry is already in |
the working set (because ``sys.path`` can contain the same entry more than |
once):: |
>>> ws.add_entry(pkg_resources.__file__) |
>>> ws.entries |
['...example.com...', '...pkg_resources...', '...pkg_resources...'] |
And you can specify the path entry a distribution was found under, using the |
optional second parameter to ``add()``:: |
>>> ws = WorkingSet([]) |
>>> ws.add(dist,"foo") |
>>> ws.entries |
['foo'] |
But even if a distribution is found under multiple path entries, it still only |
shows up once when iterating the working set: |
>>> ws.add_entry(ws.entries[0]) |
>>> list(ws) |
[Bar 0.9 (http://example.com/something)] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.