This file is indexed.

/usr/share/doc/python-setuptools-doc/html/pkg_resources.html is in python-setuptools-doc 39.0.1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Package Discovery and Resource Access using pkg_resources &#8212; Python  documentation</title>
    <link rel="stylesheet" href="_static/nature.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Supporting both Python 2 and Python 3 with Setuptools" href="python3.html" />
    <link rel="prev" title="Easy Install" href="easy_install.html" /> 
  </head>
  <body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="python3.html" title="Supporting both Python 2 and Python 3 with Setuptools"
             accesskey="N">next</a></li>
        <li class="right" >
          <a href="easy_install.html" title="Easy Install"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Python  documentation</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="package-discovery-and-resource-access-using-pkg-resources">
<h1><a class="toc-backref" href="#id1">Package Discovery and Resource Access using <code class="docutils literal"><span class="pre">pkg_resources</span></code></a><a class="headerlink" href="#package-discovery-and-resource-access-using-pkg-resources" title="Permalink to this headline"></a></h1>
<p>The <code class="docutils literal"><span class="pre">pkg_resources</span></code> module distributed with <code class="docutils literal"><span class="pre">setuptools</span></code> provides an API
for Python libraries to access their resource files, and for extensible
applications and frameworks to automatically discover plugins.  It also
provides runtime support for using C extensions that are inside zipfile-format
eggs, support for merging packages that have separately-distributed modules or
subpackages, and APIs for managing Python’s current “working set” of active
packages.</p>
<div class="contents topic" id="table-of-contents">
<p class="topic-title first"><strong>Table of Contents</strong></p>
<ul class="simple">
<li><a class="reference internal" href="#package-discovery-and-resource-access-using-pkg-resources" id="id1">Package Discovery and Resource Access using <code class="docutils literal"><span class="pre">pkg_resources</span></code></a><ul>
<li><a class="reference internal" href="#overview" id="id2">Overview</a></li>
<li><a class="reference internal" href="#api-reference" id="id3">API Reference</a><ul>
<li><a class="reference internal" href="#namespace-package-support" id="id4">Namespace Package Support</a></li>
<li><a class="reference internal" href="#workingset-objects" id="id5"><code class="docutils literal"><span class="pre">WorkingSet</span></code> Objects</a><ul>
<li><a class="reference internal" href="#basic-workingset-methods" id="id6">Basic <code class="docutils literal"><span class="pre">WorkingSet</span></code> Methods</a></li>
<li><a class="reference internal" href="#workingset-methods-and-attributes" id="id7"><code class="docutils literal"><span class="pre">WorkingSet</span></code> Methods and Attributes</a></li>
<li><a class="reference internal" href="#receiving-change-notifications" id="id8">Receiving Change Notifications</a></li>
<li><a class="reference internal" href="#locating-plugins" id="id9">Locating Plugins</a></li>
</ul>
</li>
<li><a class="reference internal" href="#environment-objects" id="id10"><code class="docutils literal"><span class="pre">Environment</span></code> Objects</a></li>
<li><a class="reference internal" href="#requirement-objects" id="id11"><code class="docutils literal"><span class="pre">Requirement</span></code> Objects</a><ul>
<li><a class="reference internal" href="#requirements-parsing" id="id12">Requirements Parsing</a></li>
<li><a class="reference internal" href="#requirement-methods-and-attributes" id="id13"><code class="docutils literal"><span class="pre">Requirement</span></code> Methods and Attributes</a></li>
</ul>
</li>
<li><a class="reference internal" href="#entry-points" id="id14">Entry Points</a><ul>
<li><a class="reference internal" href="#convenience-api" id="id15">Convenience API</a></li>
<li><a class="reference internal" href="#creating-and-parsing" id="id16">Creating and Parsing</a></li>
<li><a class="reference internal" href="#entrypoint-objects" id="id17"><code class="docutils literal"><span class="pre">EntryPoint</span></code> Objects</a></li>
</ul>
</li>
<li><a class="reference internal" href="#distribution-objects" id="id18"><code class="docutils literal"><span class="pre">Distribution</span></code> Objects</a><ul>
<li><a class="reference internal" href="#getting-or-creating-distributions" id="id19">Getting or Creating Distributions</a></li>
<li><a class="reference internal" href="#distribution-attributes" id="id20"><code class="docutils literal"><span class="pre">Distribution</span></code> Attributes</a></li>
<li><a class="reference internal" href="#distribution-methods" id="id21"><code class="docutils literal"><span class="pre">Distribution</span></code> Methods</a></li>
</ul>
</li>
<li><a class="reference internal" href="#resourcemanager-api" id="id22"><code class="docutils literal"><span class="pre">ResourceManager</span></code> API</a><ul>
<li><a class="reference internal" href="#basic-resource-access" id="id23">Basic Resource Access</a></li>
<li><a class="reference internal" href="#resource-extraction" id="id24">Resource Extraction</a></li>
<li><a class="reference internal" href="#provider-interface" id="id25">“Provider” Interface</a></li>
</ul>
</li>
<li><a class="reference internal" href="#metadata-api" id="id26">Metadata API</a><ul>
<li><a class="reference internal" href="#imetadataprovider-methods" id="id27"><code class="docutils literal"><span class="pre">IMetadataProvider</span></code> Methods</a></li>
</ul>
</li>
<li><a class="reference internal" href="#exceptions" id="id28">Exceptions</a></li>
<li><a class="reference internal" href="#supporting-custom-importers" id="id29">Supporting Custom Importers</a><ul>
<li><a class="reference internal" href="#iresourceprovider" id="id30">IResourceProvider</a></li>
<li><a class="reference internal" href="#built-in-resource-providers" id="id31">Built-in Resource Providers</a></li>
</ul>
</li>
<li><a class="reference internal" href="#utility-functions" id="id32">Utility Functions</a><ul>
<li><a class="reference internal" href="#parsing-utilities" id="id33">Parsing Utilities</a></li>
<li><a class="reference internal" href="#platform-utilities" id="id34">Platform Utilities</a></li>
<li><a class="reference internal" href="#pep-302-utilities" id="id35">PEP 302 Utilities</a></li>
<li><a class="reference internal" href="#file-path-utilities" id="id36">File/Path Utilities</a></li>
<li><a class="reference internal" href="#history" id="id37">History</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="overview">
<h2><a class="toc-backref" href="#id2">Overview</a><a class="headerlink" href="#overview" title="Permalink to this headline"></a></h2>
<p>The <code class="docutils literal"><span class="pre">pkg_resources</span></code> module provides runtime facilities for finding,
introspecting, activating and using installed Python distributions. Some
of the more advanced features (notably the support for parallel installation
of multiple versions) rely specifically on the “egg” format (either as a
zip archive or subdirectory), while others (such as plugin discovery) will
work correctly so long as “egg-info” metadata directories are available for
relevant distributions.</p>
<p>Eggs are a distribution format for Python modules, similar in concept to
Java’s “jars” or Ruby’s “gems”, or the “wheel” format defined in PEP 427.
However, unlike a pure distribution format, eggs can also be installed and
added directly to <code class="docutils literal"><span class="pre">sys.path</span></code> as an import location. When installed in
this way, eggs are <em>discoverable</em>, meaning that they carry metadata that
unambiguously identifies their contents and dependencies. This means that
an installed egg can be <em>automatically</em> found and added to <code class="docutils literal"><span class="pre">sys.path</span></code> in
response to simple requests of the form, “get me everything I need to use
docutils’ PDF support”. This feature allows mutually conflicting versions of
a distribution to co-exist in the same Python installation, with individual
applications activating the desired version at runtime by manipulating the
contents of <code class="docutils literal"><span class="pre">sys.path</span></code> (this differs from the virtual environment
approach, which involves creating isolated environments for each
application).</p>
<p>The following terms are needed in order to explain the capabilities offered
by this module:</p>
<dl class="docutils">
<dt>project</dt>
<dd>A library, framework, script, plugin, application, or collection of data
or other resources, or some combination thereof.  Projects are assumed to
have “relatively unique” names, e.g. names registered with PyPI.</dd>
<dt>release</dt>
<dd>A snapshot of a project at a particular point in time, denoted by a version
identifier.</dd>
<dt>distribution</dt>
<dd>A file or files that represent a particular release.</dd>
<dt>importable distribution</dt>
<dd>A file or directory that, if placed on <code class="docutils literal"><span class="pre">sys.path</span></code>, allows Python to
import any modules contained within it.</dd>
<dt>pluggable distribution</dt>
<dd>An importable distribution whose filename unambiguously identifies its
release (i.e. project and version), and whose contents unambiguously
specify what releases of other projects will satisfy its runtime
requirements.</dd>
<dt>extra</dt>
<dd>An “extra” is an optional feature of a release, that may impose additional
runtime requirements.  For example, if docutils PDF support required a
PDF support library to be present, docutils could define its PDF support as
an “extra”, and list what other project releases need to be available in
order to provide it.</dd>
<dt>environment</dt>
<dd>A collection of distributions potentially available for importing, but not
necessarily active.  More than one distribution (i.e. release version) for
a given project may be present in an environment.</dd>
<dt>working set</dt>
<dd>A collection of distributions actually available for importing, as on
<code class="docutils literal"><span class="pre">sys.path</span></code>.  At most one distribution (release version) of a given
project may be present in a working set, as otherwise there would be
ambiguity as to what to import.</dd>
<dt>eggs</dt>
<dd>Eggs are pluggable distributions in one of the three formats currently
supported by <code class="docutils literal"><span class="pre">pkg_resources</span></code>.  There are built eggs, development eggs,
and egg links.  Built eggs are directories or zipfiles whose name ends
with <code class="docutils literal"><span class="pre">.egg</span></code> and follows the egg naming conventions, and contain an
<code class="docutils literal"><span class="pre">EGG-INFO</span></code> subdirectory (zipped or otherwise).  Development eggs are
normal directories of Python code with one or more <code class="docutils literal"><span class="pre">ProjectName.egg-info</span></code>
subdirectories. The development egg format is also used to provide a
default version of a distribution that is available to software that
doesn’t use <code class="docutils literal"><span class="pre">pkg_resources</span></code> to request specific versions. Egg links
are <code class="docutils literal"><span class="pre">*.egg-link</span></code> files that contain the name of a built or
development egg, to support symbolic linking on platforms that do not
have native symbolic links (or where the symbolic link support is
limited).</dd>
</dl>
<p>(For more information about these terms and concepts, see also this
<a class="reference external" href="http://mail.python.org/pipermail/distutils-sig/2005-June/004652.html">architectural overview</a> of <code class="docutils literal"><span class="pre">pkg_resources</span></code> and Python Eggs in general.)</p>
</div>
<div class="section" id="api-reference">
<h2><a class="toc-backref" href="#id3">API Reference</a><a class="headerlink" href="#api-reference" title="Permalink to this headline"></a></h2>
<div class="section" id="namespace-package-support">
<h3><a class="toc-backref" href="#id4">Namespace Package Support</a><a class="headerlink" href="#namespace-package-support" title="Permalink to this headline"></a></h3>
<p>A namespace package is a package that only contains other packages and modules,
with no direct contents of its own.  Such packages can be split across
multiple, separately-packaged distributions.  They are normally used to split
up large packages produced by a single organization, such as in the <code class="docutils literal"><span class="pre">zope</span></code>
namespace package for Zope Corporation packages, and the <code class="docutils literal"><span class="pre">peak</span></code> namespace
package for the Python Enterprise Application Kit.</p>
<p>To create a namespace package, you list it in the <code class="docutils literal"><span class="pre">namespace_packages</span></code>
argument to <code class="docutils literal"><span class="pre">setup()</span></code>, in your project’s <code class="docutils literal"><span class="pre">setup.py</span></code>.  (See the
<span class="xref std std-ref">setuptools documentation on namespace packages</span> for
more information on this.)  Also, you must add a <code class="docutils literal"><span class="pre">declare_namespace()</span></code> call
in the package’s <code class="docutils literal"><span class="pre">__init__.py</span></code> file(s):</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">declare_namespace(name)</span></code></dt>
<dd>Declare that the dotted package name <cite>name</cite> is a “namespace package” whose
contained packages and modules may be spread across multiple distributions.
The named package’s <code class="docutils literal"><span class="pre">__path__</span></code> will be extended to include the
corresponding package in all distributions on <code class="docutils literal"><span class="pre">sys.path</span></code> that contain a
package of that name.  (More precisely, if an importer’s
<code class="docutils literal"><span class="pre">find_module(name)</span></code> returns a loader, then it will also be searched for
the package’s contents.)  Whenever a Distribution’s <code class="docutils literal"><span class="pre">activate()</span></code> method
is invoked, it checks for the presence of namespace packages and updates
their <code class="docutils literal"><span class="pre">__path__</span></code> contents accordingly.</dd>
</dl>
<p>Applications that manipulate namespace packages or directly alter <code class="docutils literal"><span class="pre">sys.path</span></code>
at runtime may also need to use this API function:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">fixup_namespace_packages(path_item)</span></code></dt>
<dd>Declare that <cite>path_item</cite> is a newly added item on <code class="docutils literal"><span class="pre">sys.path</span></code> that may
need to be used to update existing namespace packages.  Ordinarily, this is
called for you when an egg is automatically added to <code class="docutils literal"><span class="pre">sys.path</span></code>, but if
your application modifies <code class="docutils literal"><span class="pre">sys.path</span></code> to include locations that may
contain portions of a namespace package, you will need to call this
function to ensure they are added to the existing namespace packages.</dd>
</dl>
<p>Although by default <code class="docutils literal"><span class="pre">pkg_resources</span></code> only supports namespace packages for
filesystem and zip importers, you can extend its support to other “importers”
compatible with PEP 302 using the <code class="docutils literal"><span class="pre">register_namespace_handler()</span></code> function.
See the section below on <a class="reference internal" href="#supporting-custom-importers">Supporting Custom Importers</a> for details.</p>
</div>
<div class="section" id="workingset-objects">
<h3><a class="toc-backref" href="#id5"><code class="docutils literal"><span class="pre">WorkingSet</span></code> Objects</a><a class="headerlink" href="#workingset-objects" title="Permalink to this headline"></a></h3>
<p>The <code class="docutils literal"><span class="pre">WorkingSet</span></code> class provides access to a collection of “active”
distributions.  In general, there is only one meaningful <code class="docutils literal"><span class="pre">WorkingSet</span></code>
instance: the one that represents the distributions that are currently active
on <code class="docutils literal"><span class="pre">sys.path</span></code>.  This global instance is available under the name
<code class="docutils literal"><span class="pre">working_set</span></code> in the <code class="docutils literal"><span class="pre">pkg_resources</span></code> module.  However, specialized
tools may wish to manipulate working sets that don’t correspond to
<code class="docutils literal"><span class="pre">sys.path</span></code>, and therefore may wish to create other <code class="docutils literal"><span class="pre">WorkingSet</span></code> instances.</p>
<p>It’s important to note that the global <code class="docutils literal"><span class="pre">working_set</span></code> object is initialized
from <code class="docutils literal"><span class="pre">sys.path</span></code> when <code class="docutils literal"><span class="pre">pkg_resources</span></code> is first imported, but is only updated
if you do all future <code class="docutils literal"><span class="pre">sys.path</span></code> manipulation via <code class="docutils literal"><span class="pre">pkg_resources</span></code> APIs.  If
you manually modify <code class="docutils literal"><span class="pre">sys.path</span></code>, you must invoke the appropriate methods on
the <code class="docutils literal"><span class="pre">working_set</span></code> instance to keep it in sync.  Unfortunately, Python does
not provide any way to detect arbitrary changes to a list object like
<code class="docutils literal"><span class="pre">sys.path</span></code>, so <code class="docutils literal"><span class="pre">pkg_resources</span></code> cannot automatically update the
<code class="docutils literal"><span class="pre">working_set</span></code> based on changes to <code class="docutils literal"><span class="pre">sys.path</span></code>.</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">WorkingSet(entries=None)</span></code></dt>
<dd><p class="first">Create a <code class="docutils literal"><span class="pre">WorkingSet</span></code> from an iterable of path entries.  If <cite>entries</cite>
is not supplied, it defaults to the value of <code class="docutils literal"><span class="pre">sys.path</span></code> at the time
the constructor is called.</p>
<p class="last">Note that you will not normally construct <code class="docutils literal"><span class="pre">WorkingSet</span></code> instances
yourself, but instead you will implicitly or explicitly use the global
<code class="docutils literal"><span class="pre">working_set</span></code> instance.  For the most part, the <code class="docutils literal"><span class="pre">pkg_resources</span></code> API
is designed so that the <code class="docutils literal"><span class="pre">working_set</span></code> is used by default, such that you
don’t have to explicitly refer to it most of the time.</p>
</dd>
</dl>
<p>All distributions available directly on <code class="docutils literal"><span class="pre">sys.path</span></code> will be activated
automatically when <code class="docutils literal"><span class="pre">pkg_resources</span></code> is imported. This behaviour can cause
version conflicts for applications which require non-default versions of
those distributions. To handle this situation, <code class="docutils literal"><span class="pre">pkg_resources</span></code> checks for a
<code class="docutils literal"><span class="pre">__requires__</span></code> attribute in the <code class="docutils literal"><span class="pre">__main__</span></code> module when initializing the
default working set, and uses this to ensure a suitable version of each
affected distribution is activated. For example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">__requires__</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;CherryPy &lt; 3&quot;</span><span class="p">]</span> <span class="c1"># Must be set before pkg_resources import</span>
<span class="kn">import</span> <span class="nn">pkg_resources</span>
</pre></div>
</div>
<div class="section" id="basic-workingset-methods">
<h4><a class="toc-backref" href="#id6">Basic <code class="docutils literal"><span class="pre">WorkingSet</span></code> Methods</a><a class="headerlink" href="#basic-workingset-methods" title="Permalink to this headline"></a></h4>
<p>The following methods of <code class="docutils literal"><span class="pre">WorkingSet</span></code> objects are also available as module-
level functions in <code class="docutils literal"><span class="pre">pkg_resources</span></code> that apply to the default <code class="docutils literal"><span class="pre">working_set</span></code>
instance.  Thus, you can use e.g. <code class="docutils literal"><span class="pre">pkg_resources.require()</span></code> as an
abbreviation for <code class="docutils literal"><span class="pre">pkg_resources.working_set.require()</span></code>:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">require(*requirements)</span></code></dt>
<dd><p class="first">Ensure that distributions matching <cite>requirements</cite> are activated</p>
<p><cite>requirements</cite> must be a string or a (possibly-nested) sequence
thereof, specifying the distributions and versions required.  The
return value is a sequence of the distributions that needed to be
activated to fulfill the requirements; all relevant distributions are
included, even if they were already activated in this working set.</p>
<p>For the syntax of requirement specifiers, see the section below on
<a class="reference internal" href="#requirements-parsing">Requirements Parsing</a>.</p>
<p>In general, it should not be necessary for you to call this method
directly.  It’s intended more for use in quick-and-dirty scripting and
interactive interpreter hacking than for production use. If you’re creating
an actual library or application, it’s strongly recommended that you create
a “setup.py” script using <code class="docutils literal"><span class="pre">setuptools</span></code>, and declare all your requirements
there.  That way, tools like EasyInstall can automatically detect what
requirements your package has, and deal with them accordingly.</p>
<p class="last">Note that calling <code class="docutils literal"><span class="pre">require('SomePackage')</span></code> will not install
<code class="docutils literal"><span class="pre">SomePackage</span></code> if it isn’t already present.  If you need to do this, you
should use the <code class="docutils literal"><span class="pre">resolve()</span></code> method instead, which allows you to pass an
<code class="docutils literal"><span class="pre">installer</span></code> callback that will be invoked when a needed distribution
can’t be found on the local machine.  You can then have this callback
display a dialog, automatically download the needed distribution, or
whatever else is appropriate for your application. See the documentation
below on the <code class="docutils literal"><span class="pre">resolve()</span></code> method for more information, and also on the
<code class="docutils literal"><span class="pre">obtain()</span></code> method of <code class="docutils literal"><span class="pre">Environment</span></code> objects.</p>
</dd>
<dt><code class="docutils literal"><span class="pre">run_script(requires,</span> <span class="pre">script_name)</span></code></dt>
<dd><p class="first">Locate distribution specified by <cite>requires</cite> and run its <cite>script_name</cite>
script.  <cite>requires</cite> must be a string containing a requirement specifier.
(See <a class="reference internal" href="#requirements-parsing">Requirements Parsing</a> below for the syntax.)</p>
<p>The script, if found, will be executed in <em>the caller’s globals</em>.  That’s
because this method is intended to be called from wrapper scripts that
act as a proxy for the “real” scripts in a distribution.  A wrapper script
usually doesn’t need to do anything but invoke this function with the
correct arguments.</p>
<p class="last">If you need more control over the script execution environment, you
probably want to use the <code class="docutils literal"><span class="pre">run_script()</span></code> method of a <code class="docutils literal"><span class="pre">Distribution</span></code>
object’s <a class="reference internal" href="#metadata-api">Metadata API</a> instead.</p>
</dd>
<dt><code class="docutils literal"><span class="pre">iter_entry_points(group,</span> <span class="pre">name=None)</span></code></dt>
<dd><p class="first">Yield entry point objects from <cite>group</cite> matching <cite>name</cite></p>
<p>If <cite>name</cite> is None, yields all entry points in <cite>group</cite> from all
distributions in the working set, otherwise only ones matching both
<cite>group</cite> and <cite>name</cite> are yielded.  Entry points are yielded from the active
distributions in the order that the distributions appear in the working
set.  (For the global <code class="docutils literal"><span class="pre">working_set</span></code>, this should be the same as the order
that they are listed in <code class="docutils literal"><span class="pre">sys.path</span></code>.)  Note that within the entry points
advertised by an individual distribution, there is no particular ordering.</p>
<p class="last">Please see the section below on <a class="reference internal" href="#entry-points">Entry Points</a> for more information.</p>
</dd>
</dl>
</div>
<div class="section" id="workingset-methods-and-attributes">
<h4><a class="toc-backref" href="#id7"><code class="docutils literal"><span class="pre">WorkingSet</span></code> Methods and Attributes</a><a class="headerlink" href="#workingset-methods-and-attributes" title="Permalink to this headline"></a></h4>
<p>These methods are used to query or manipulate the contents of a specific
working set, so they must be explicitly invoked on a particular <code class="docutils literal"><span class="pre">WorkingSet</span></code>
instance:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">add_entry(entry)</span></code></dt>
<dd><p class="first">Add a path item to the <code class="docutils literal"><span class="pre">entries</span></code>, finding any distributions on it.  You
should use this when you add additional items to <code class="docutils literal"><span class="pre">sys.path</span></code> and you want
the global <code class="docutils literal"><span class="pre">working_set</span></code> to reflect the change.  This method is also
called by the <code class="docutils literal"><span class="pre">WorkingSet()</span></code> constructor during initialization.</p>
<p class="last">This method uses <code class="docutils literal"><span class="pre">find_distributions(entry,True)</span></code> to find distributions
corresponding to the path entry, and then <code class="docutils literal"><span class="pre">add()</span></code> them.  <cite>entry</cite> is
always appended to the <code class="docutils literal"><span class="pre">entries</span></code> attribute, even if it is already
present, however. (This is because <code class="docutils literal"><span class="pre">sys.path</span></code> can contain the same value
more than once, and the <code class="docutils literal"><span class="pre">entries</span></code> attribute should be able to reflect
this.)</p>
</dd>
<dt><code class="docutils literal"><span class="pre">__contains__(dist)</span></code></dt>
<dd>True if <cite>dist</cite> is active in this <code class="docutils literal"><span class="pre">WorkingSet</span></code>.  Note that only one
distribution for a given project can be active in a given <code class="docutils literal"><span class="pre">WorkingSet</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">__iter__()</span></code></dt>
<dd>Yield distributions for non-duplicate projects in the working set.
The yield order is the order in which the items’ path entries were
added to the working set.</dd>
<dt><code class="docutils literal"><span class="pre">find(req)</span></code></dt>
<dd>Find a distribution matching <cite>req</cite> (a <code class="docutils literal"><span class="pre">Requirement</span></code> instance).
If there is an active distribution for the requested project, this
returns it, as long as it meets the version requirement specified by
<cite>req</cite>.  But, if there is an active distribution for the project and it
does <em>not</em> meet the <cite>req</cite> requirement, <code class="docutils literal"><span class="pre">VersionConflict</span></code> is raised.
If there is no active distribution for the requested project, <code class="docutils literal"><span class="pre">None</span></code>
is returned.</dd>
<dt><code class="docutils literal"><span class="pre">resolve(requirements,</span> <span class="pre">env=None,</span> <span class="pre">installer=None)</span></code></dt>
<dd><p class="first">List all distributions needed to (recursively) meet <cite>requirements</cite></p>
<p class="last"><cite>requirements</cite> must be a sequence of <code class="docutils literal"><span class="pre">Requirement</span></code> objects.  <cite>env</cite>,
if supplied, should be an <code class="docutils literal"><span class="pre">Environment</span></code> instance.  If
not supplied, an <code class="docutils literal"><span class="pre">Environment</span></code> is created from the working set’s
<code class="docutils literal"><span class="pre">entries</span></code>.  <cite>installer</cite>, if supplied, will be invoked with each
requirement that cannot be met by an already-installed distribution; it
should return a <code class="docutils literal"><span class="pre">Distribution</span></code> or <code class="docutils literal"><span class="pre">None</span></code>.  (See the <code class="docutils literal"><span class="pre">obtain()</span></code> method
of <a class="reference internal" href="#environment-objects">Environment Objects</a>, below, for more information on the <cite>installer</cite>
argument.)</p>
</dd>
<dt><code class="docutils literal"><span class="pre">add(dist,</span> <span class="pre">entry=None)</span></code></dt>
<dd><p class="first">Add <cite>dist</cite> to working set, associated with <cite>entry</cite></p>
<p>If <cite>entry</cite> is unspecified, it defaults to <code class="docutils literal"><span class="pre">dist.location</span></code>.  On exit from
this routine, <cite>entry</cite> is added to the end of the working set’s <code class="docutils literal"><span class="pre">.entries</span></code>
(if it wasn’t already present).</p>
<p><cite>dist</cite> is only added to the working set if it’s for a project that
doesn’t already have a distribution active in the set.  If it’s
successfully added, any  callbacks registered with the <code class="docutils literal"><span class="pre">subscribe()</span></code>
method will be called.  (See <a class="reference internal" href="#receiving-change-notifications">Receiving Change Notifications</a>, below.)</p>
<p class="last">Note: <code class="docutils literal"><span class="pre">add()</span></code> is automatically called for you by the <code class="docutils literal"><span class="pre">require()</span></code>
method, so you don’t normally need to use this method directly.</p>
</dd>
<dt><code class="docutils literal"><span class="pre">entries</span></code></dt>
<dd>This attribute represents a “shadow” <code class="docutils literal"><span class="pre">sys.path</span></code>, primarily useful for
debugging.  If you are experiencing import problems, you should check
the global <code class="docutils literal"><span class="pre">working_set</span></code> object’s <code class="docutils literal"><span class="pre">entries</span></code> against <code class="docutils literal"><span class="pre">sys.path</span></code>, to
ensure that they match.  If they do not, then some part of your program
is manipulating <code class="docutils literal"><span class="pre">sys.path</span></code> without updating the <code class="docutils literal"><span class="pre">working_set</span></code>
accordingly.  IMPORTANT NOTE: do not directly manipulate this attribute!
Setting it equal to <code class="docutils literal"><span class="pre">sys.path</span></code> will not fix your problem, any more than
putting black tape over an “engine warning” light will fix your car!  If
this attribute is out of sync with <code class="docutils literal"><span class="pre">sys.path</span></code>, it’s merely an <em>indicator</em>
of the problem, not the cause of it.</dd>
</dl>
</div>
<div class="section" id="receiving-change-notifications">
<h4><a class="toc-backref" href="#id8">Receiving Change Notifications</a><a class="headerlink" href="#receiving-change-notifications" title="Permalink to this headline"></a></h4>
<p>Extensible applications and frameworks may need to receive notification when
a new distribution (such as a plug-in component) has been added to a working
set.  This is what the <code class="docutils literal"><span class="pre">subscribe()</span></code> method and <code class="docutils literal"><span class="pre">add_activation_listener()</span></code>
function are for.</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">subscribe(callback)</span></code></dt>
<dd><p class="first">Invoke <code class="docutils literal"><span class="pre">callback(distribution)</span></code> once for each active distribution that is
in the set now, or gets added later.  Because the callback is invoked for
already-active distributions, you do not need to loop over the working set
yourself to deal with the existing items; just register the callback and
be prepared for the fact that it will be called immediately by this method.</p>
<p class="last">Note that callbacks <em>must not</em> allow exceptions to propagate, or they will
interfere with the operation of other callbacks and possibly result in an
inconsistent working set state.  Callbacks should use a try/except block
to ignore, log, or otherwise process any errors, especially since the code
that caused the callback to be invoked is unlikely to be able to handle
the errors any better than the callback itself.</p>
</dd>
</dl>
<p><code class="docutils literal"><span class="pre">pkg_resources.add_activation_listener()</span></code> is an alternate spelling of
<code class="docutils literal"><span class="pre">pkg_resources.working_set.subscribe()</span></code>.</p>
</div>
<div class="section" id="locating-plugins">
<h4><a class="toc-backref" href="#id9">Locating Plugins</a><a class="headerlink" href="#locating-plugins" title="Permalink to this headline"></a></h4>
<p>Extensible applications will sometimes have a “plugin directory” or a set of
plugin directories, from which they want to load entry points or other
metadata.  The <code class="docutils literal"><span class="pre">find_plugins()</span></code> method allows you to do this, by scanning an
environment for the newest version of each project that can be safely loaded
without conflicts or missing requirements.</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">find_plugins(plugin_env,</span> <span class="pre">full_env=None,</span> <span class="pre">fallback=True)</span></code></dt>
<dd><p class="first">Scan <cite>plugin_env</cite> and identify which distributions could be added to this
working set without version conflicts or missing requirements.</p>
<p>Example usage:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">distributions</span><span class="p">,</span> <span class="n">errors</span> <span class="o">=</span> <span class="n">working_set</span><span class="o">.</span><span class="n">find_plugins</span><span class="p">(</span>
    <span class="n">Environment</span><span class="p">(</span><span class="n">plugin_dirlist</span><span class="p">)</span>
<span class="p">)</span>
<span class="nb">map</span><span class="p">(</span><span class="n">working_set</span><span class="o">.</span><span class="n">add</span><span class="p">,</span> <span class="n">distributions</span><span class="p">)</span>  <span class="c1"># add plugins+libs to sys.path</span>
<span class="nb">print</span> <span class="s2">&quot;Couldn&#39;t load&quot;</span><span class="p">,</span> <span class="n">errors</span>        <span class="c1"># display errors</span>
</pre></div>
</div>
<p>The <cite>plugin_env</cite> should be an <code class="docutils literal"><span class="pre">Environment</span></code> instance that contains only
distributions that are in the project’s “plugin directory” or directories.
The <cite>full_env</cite>, if supplied, should be an <code class="docutils literal"><span class="pre">Environment</span></code> instance that
contains all currently-available distributions.</p>
<p>If <cite>full_env</cite> is not supplied, one is created automatically from the
<code class="docutils literal"><span class="pre">WorkingSet</span></code> this method is called on, which will typically mean that
every directory on <code class="docutils literal"><span class="pre">sys.path</span></code> will be scanned for distributions.</p>
<p>This method returns a 2-tuple: (<cite>distributions</cite>, <cite>error_info</cite>), where
<cite>distributions</cite> is a list of the distributions found in <cite>plugin_env</cite> that
were loadable, along with any other distributions that are needed to resolve
their dependencies.  <cite>error_info</cite> is a dictionary mapping unloadable plugin
distributions to an exception instance describing the error that occurred.
Usually this will be a <code class="docutils literal"><span class="pre">DistributionNotFound</span></code> or <code class="docutils literal"><span class="pre">VersionConflict</span></code>
instance.</p>
<p>Most applications will use this method mainly on the master <code class="docutils literal"><span class="pre">working_set</span></code>
instance in <code class="docutils literal"><span class="pre">pkg_resources</span></code>, and then immediately add the returned
distributions to the working set so that they are available on sys.path.
This will make it possible to find any entry points, and allow any other
metadata tracking and hooks to be activated.</p>
<p>The resolution algorithm used by <code class="docutils literal"><span class="pre">find_plugins()</span></code> is as follows.  First,
the project names of the distributions present in <cite>plugin_env</cite> are sorted.
Then, each project’s eggs are tried in descending version order (i.e.,
newest version first).</p>
<p>An attempt is made to resolve each egg’s dependencies. If the attempt is
successful, the egg and its dependencies are added to the output list and to
a temporary copy of the working set.  The resolution process continues with
the next project name, and no older eggs for that project are tried.</p>
<p>If the resolution attempt fails, however, the error is added to the error
dictionary.  If the <cite>fallback</cite> flag is true, the next older version of the
plugin is tried, until a working version is found.  If false, the resolution
process continues with the next plugin project name.</p>
<p>Some applications may have stricter fallback requirements than others. For
example, an application that has a database schema or persistent objects
may not be able to safely downgrade a version of a package. Others may want
to ensure that a new plugin configuration is either 100% good or else
revert to a known-good configuration.  (That is, they may wish to revert to
a known configuration if the <cite>error_info</cite> return value is non-empty.)</p>
<p class="last">Note that this algorithm gives precedence to satisfying the dependencies of
alphabetically prior project names in case of version conflicts. If two
projects named “AaronsPlugin” and “ZekesPlugin” both need different versions
of “TomsLibrary”, then “AaronsPlugin” will win and “ZekesPlugin” will be
disabled due to version conflict.</p>
</dd>
</dl>
</div>
</div>
<div class="section" id="environment-objects">
<h3><a class="toc-backref" href="#id10"><code class="docutils literal"><span class="pre">Environment</span></code> Objects</a><a class="headerlink" href="#environment-objects" title="Permalink to this headline"></a></h3>
<p>An “environment” is a collection of <code class="docutils literal"><span class="pre">Distribution</span></code> objects, usually ones
that are present and potentially importable on the current platform.
<code class="docutils literal"><span class="pre">Environment</span></code> objects are used by <code class="docutils literal"><span class="pre">pkg_resources</span></code> to index available
distributions during dependency resolution.</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">Environment(search_path=None,</span> <span class="pre">platform=get_supported_platform(),</span> <span class="pre">python=PY_MAJOR)</span></code></dt>
<dd><p class="first">Create an environment snapshot by scanning <cite>search_path</cite> for distributions
compatible with <cite>platform</cite> and <cite>python</cite>.  <cite>search_path</cite> should be a
sequence of strings such as might be used on <code class="docutils literal"><span class="pre">sys.path</span></code>.  If a
<cite>search_path</cite> isn’t supplied, <code class="docutils literal"><span class="pre">sys.path</span></code> is used.</p>
<p><cite>platform</cite> is an optional string specifying the name of the platform
that platform-specific distributions must be compatible with.  If
unspecified, it defaults to the current platform.  <cite>python</cite> is an
optional string naming the desired version of Python (e.g. <code class="docutils literal"><span class="pre">'2.4'</span></code>);
it defaults to the currently-running version.</p>
<p>You may explicitly set <cite>platform</cite> (and/or <cite>python</cite>) to <code class="docutils literal"><span class="pre">None</span></code> if you
wish to include <em>all</em> distributions, not just those compatible with the
running platform or Python version.</p>
<p class="last">Note that <cite>search_path</cite> is scanned immediately for distributions, and the
resulting <code class="docutils literal"><span class="pre">Environment</span></code> is a snapshot of the found distributions.  It
is not automatically updated if the system’s state changes due to e.g.
installation or removal of distributions.</p>
</dd>
<dt><code class="docutils literal"><span class="pre">__getitem__(project_name)</span></code></dt>
<dd>Returns a list of distributions for the given project name, ordered
from newest to oldest version.  (And highest to lowest format precedence
for distributions that contain the same version of the project.)  If there
are no distributions for the project, returns an empty list.</dd>
<dt><code class="docutils literal"><span class="pre">__iter__()</span></code></dt>
<dd>Yield the unique project names of the distributions in this environment.
The yielded names are always in lower case.</dd>
<dt><code class="docutils literal"><span class="pre">add(dist)</span></code></dt>
<dd>Add <cite>dist</cite> to the environment if it matches the platform and python version
specified at creation time, and only if the distribution hasn’t already
been added. (i.e., adding the same distribution more than once is a no-op.)</dd>
<dt><code class="docutils literal"><span class="pre">remove(dist)</span></code></dt>
<dd>Remove <cite>dist</cite> from the environment.</dd>
<dt><code class="docutils literal"><span class="pre">can_add(dist)</span></code></dt>
<dd>Is distribution <cite>dist</cite> acceptable for this environment?  If it’s not
compatible with the <code class="docutils literal"><span class="pre">platform</span></code> and <code class="docutils literal"><span class="pre">python</span></code> version values specified
when the environment was created, a false value is returned.</dd>
<dt><code class="docutils literal"><span class="pre">__add__(dist_or_env)</span></code>  (<code class="docutils literal"><span class="pre">+</span></code> operator)</dt>
<dd>Add a distribution or environment to an <code class="docutils literal"><span class="pre">Environment</span></code> instance, returning
a <em>new</em> environment object that contains all the distributions previously
contained by both.  The new environment will have a <code class="docutils literal"><span class="pre">platform</span></code> and
<code class="docutils literal"><span class="pre">python</span></code> of <code class="docutils literal"><span class="pre">None</span></code>, meaning that it will not reject any distributions
from being added to it; it will simply accept whatever is added.  If you
want the added items to be filtered for platform and Python version, or
you want to add them to the <em>same</em> environment instance, you should use
in-place addition (<code class="docutils literal"><span class="pre">+=</span></code>) instead.</dd>
<dt><code class="docutils literal"><span class="pre">__iadd__(dist_or_env)</span></code>  (<code class="docutils literal"><span class="pre">+=</span></code> operator)</dt>
<dd>Add a distribution or environment to an <code class="docutils literal"><span class="pre">Environment</span></code> instance
<em>in-place</em>, updating the existing instance and returning it.  The
<code class="docutils literal"><span class="pre">platform</span></code> and <code class="docutils literal"><span class="pre">python</span></code> filter attributes take effect, so distributions
in the source that do not have a suitable platform string or Python version
are silently ignored.</dd>
<dt><code class="docutils literal"><span class="pre">best_match(req,</span> <span class="pre">working_set,</span> <span class="pre">installer=None)</span></code></dt>
<dd><p class="first">Find distribution best matching <cite>req</cite> and usable on <cite>working_set</cite></p>
<p class="last">This calls the <code class="docutils literal"><span class="pre">find(req)</span></code> method of the <cite>working_set</cite> to see if a
suitable distribution is already active.  (This may raise
<code class="docutils literal"><span class="pre">VersionConflict</span></code> if an unsuitable version of the project is already
active in the specified <cite>working_set</cite>.)  If a suitable distribution isn’t
active, this method returns the newest distribution in the environment
that meets the <code class="docutils literal"><span class="pre">Requirement</span></code> in <cite>req</cite>.  If no suitable distribution is
found, and <cite>installer</cite> is supplied, then the result of calling
the environment’s <code class="docutils literal"><span class="pre">obtain(req,</span> <span class="pre">installer)</span></code> method will be returned.</p>
</dd>
<dt><code class="docutils literal"><span class="pre">obtain(requirement,</span> <span class="pre">installer=None)</span></code></dt>
<dd>Obtain a distro that matches requirement (e.g. via download).  In the
base <code class="docutils literal"><span class="pre">Environment</span></code> class, this routine just returns
<code class="docutils literal"><span class="pre">installer(requirement)</span></code>, unless <cite>installer</cite> is None, in which case
None is returned instead.  This method is a hook that allows subclasses
to attempt other ways of obtaining a distribution before falling back
to the <cite>installer</cite> argument.</dd>
<dt><code class="docutils literal"><span class="pre">scan(search_path=None)</span></code></dt>
<dd><p class="first">Scan <cite>search_path</cite> for distributions usable on <cite>platform</cite></p>
<p class="last">Any distributions found are added to the environment.  <cite>search_path</cite> should
be a sequence of strings such as might be used on <code class="docutils literal"><span class="pre">sys.path</span></code>.  If not
supplied, <code class="docutils literal"><span class="pre">sys.path</span></code> is used.  Only distributions conforming to
the platform/python version defined at initialization are added.  This
method is a shortcut for using the <code class="docutils literal"><span class="pre">find_distributions()</span></code> function to
find the distributions from each item in <cite>search_path</cite>, and then calling
<code class="docutils literal"><span class="pre">add()</span></code> to add each one to the environment.</p>
</dd>
</dl>
</div>
<div class="section" id="requirement-objects">
<h3><a class="toc-backref" href="#id11"><code class="docutils literal"><span class="pre">Requirement</span></code> Objects</a><a class="headerlink" href="#requirement-objects" title="Permalink to this headline"></a></h3>
<p><code class="docutils literal"><span class="pre">Requirement</span></code> objects express what versions of a project are suitable for
some purpose.  These objects (or their string form) are used by various
<code class="docutils literal"><span class="pre">pkg_resources</span></code> APIs in order to find distributions that a script or
distribution needs.</p>
<div class="section" id="requirements-parsing">
<h4><a class="toc-backref" href="#id12">Requirements Parsing</a><a class="headerlink" href="#requirements-parsing" title="Permalink to this headline"></a></h4>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">parse_requirements(s)</span></code></dt>
<dd>Yield <code class="docutils literal"><span class="pre">Requirement</span></code> objects for a string or iterable of lines.  Each
requirement must start on a new line.  See below for syntax.</dd>
<dt><code class="docutils literal"><span class="pre">Requirement.parse(s)</span></code></dt>
<dd><p class="first">Create a <code class="docutils literal"><span class="pre">Requirement</span></code> object from a string or iterable of lines.  A
<code class="docutils literal"><span class="pre">ValueError</span></code> is raised if the string or lines do not contain a valid
requirement specifier, or if they contain more than one specifier.  (To
parse multiple specifiers from a string or iterable of strings, use
<code class="docutils literal"><span class="pre">parse_requirements()</span></code> instead.)</p>
<p>The syntax of a requirement specifier is defined in full in PEP 508.</p>
<p>Some examples of valid requirement specifiers:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">FooProject</span> <span class="o">&gt;=</span> <span class="mf">1.2</span>
<span class="n">Fizzy</span> <span class="p">[</span><span class="n">foo</span><span class="p">,</span> <span class="n">bar</span><span class="p">]</span>
<span class="n">PickyThing</span><span class="o">&lt;</span><span class="mf">1.6</span><span class="p">,</span><span class="o">&gt;</span><span class="mf">1.9</span><span class="p">,</span><span class="o">!=</span><span class="mf">1.9</span><span class="o">.</span><span class="mi">6</span><span class="p">,</span><span class="o">&lt;</span><span class="mf">2.0</span><span class="n">a0</span><span class="p">,</span><span class="o">==</span><span class="mf">2.4</span><span class="n">c1</span>
<span class="n">SomethingWhoseVersionIDontCareAbout</span>
<span class="n">SomethingWithMarker</span><span class="p">[</span><span class="n">foo</span><span class="p">]</span><span class="o">&gt;</span><span class="mf">1.0</span><span class="p">;</span><span class="n">python_version</span><span class="o">&lt;</span><span class="s2">&quot;2.7&quot;</span>
</pre></div>
</div>
<p>The project name is the only required portion of a requirement string, and
if it’s the only thing supplied, the requirement will accept any version
of that project.</p>
<p>The “extras” in a requirement are used to request optional features of a
project, that may require additional project distributions in order to
function.  For example, if the hypothetical “Report-O-Rama” project offered
optional PDF support, it might require an additional library in order to
provide that support.  Thus, a project needing Report-O-Rama’s PDF features
could use a requirement of <code class="docutils literal"><span class="pre">Report-O-Rama[PDF]</span></code> to request installation
or activation of both Report-O-Rama and any libraries it needs in order to
provide PDF support.  For example, you could use:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">easy_install</span><span class="o">.</span><span class="n">py</span> <span class="n">Report</span><span class="o">-</span><span class="n">O</span><span class="o">-</span><span class="n">Rama</span><span class="p">[</span><span class="n">PDF</span><span class="p">]</span>
</pre></div>
</div>
<p>To install the necessary packages using the EasyInstall program, or call
<code class="docutils literal"><span class="pre">pkg_resources.require('Report-O-Rama[PDF]')</span></code> to add the necessary
distributions to sys.path at runtime.</p>
<p class="last">The “markers” in a requirement are used to specify when a requirement
should be installed – the requirement will be installed if the marker
evaluates as true in the current environment. For example, specifying
<code class="docutils literal"><span class="pre">argparse;python_version&lt;&quot;3.0&quot;</span></code> will not install in an Python 3
environment, but will in a Python 2 environment.</p>
</dd>
</dl>
</div>
<div class="section" id="requirement-methods-and-attributes">
<h4><a class="toc-backref" href="#id13"><code class="docutils literal"><span class="pre">Requirement</span></code> Methods and Attributes</a><a class="headerlink" href="#requirement-methods-and-attributes" title="Permalink to this headline"></a></h4>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">__contains__(dist_or_version)</span></code></dt>
<dd><p class="first">Return true if <cite>dist_or_version</cite> fits the criteria for this requirement.
If <cite>dist_or_version</cite> is a <code class="docutils literal"><span class="pre">Distribution</span></code> object, its project name must
match the requirement’s project name, and its version must meet the
requirement’s version criteria.  If <cite>dist_or_version</cite> is a string, it is
parsed using the <code class="docutils literal"><span class="pre">parse_version()</span></code> utility function.  Otherwise, it is
assumed to be an already-parsed version.</p>
<p class="last">The <code class="docutils literal"><span class="pre">Requirement</span></code> object’s version specifiers (<code class="docutils literal"><span class="pre">.specs</span></code>) are internally
sorted into ascending version order, and used to establish what ranges of
versions are acceptable.  Adjacent redundant conditions are effectively
consolidated (e.g. <code class="docutils literal"><span class="pre">&quot;&gt;1,</span> <span class="pre">&gt;2&quot;</span></code> produces the same results as <code class="docutils literal"><span class="pre">&quot;&gt;2&quot;</span></code>, and
<code class="docutils literal"><span class="pre">&quot;&lt;2,&lt;3&quot;</span></code> produces the same results as <code class="docutils literal"><span class="pre">&quot;&lt;2&quot;</span></code>). <code class="docutils literal"><span class="pre">&quot;!=&quot;</span></code> versions are
excised from the ranges they fall within.  The version being tested for
acceptability is then checked for membership in the resulting ranges.</p>
</dd>
<dt><code class="docutils literal"><span class="pre">__eq__(other_requirement)</span></code></dt>
<dd>A requirement compares equal to another requirement if they have
case-insensitively equal project names, version specifiers, and “extras”.
(The order that extras and version specifiers are in is also ignored.)
Equal requirements also have equal hashes, so that requirements can be
used in sets or as dictionary keys.</dd>
<dt><code class="docutils literal"><span class="pre">__str__()</span></code></dt>
<dd>The string form of a <code class="docutils literal"><span class="pre">Requirement</span></code> is a string that, if passed to
<code class="docutils literal"><span class="pre">Requirement.parse()</span></code>, would return an equal <code class="docutils literal"><span class="pre">Requirement</span></code> object.</dd>
<dt><code class="docutils literal"><span class="pre">project_name</span></code></dt>
<dd>The name of the required project</dd>
<dt><code class="docutils literal"><span class="pre">key</span></code></dt>
<dd>An all-lowercase version of the <code class="docutils literal"><span class="pre">project_name</span></code>, useful for comparison
or indexing.</dd>
<dt><code class="docutils literal"><span class="pre">extras</span></code></dt>
<dd>A tuple of names of “extras” that this requirement calls for.  (These will
be all-lowercase and normalized using the <code class="docutils literal"><span class="pre">safe_extra()</span></code> parsing utility
function, so they may not exactly equal the extras the requirement was
created with.)</dd>
<dt><code class="docutils literal"><span class="pre">specs</span></code></dt>
<dd>A list of <code class="docutils literal"><span class="pre">(op,version)</span></code> tuples, sorted in ascending parsed-version
order.  The <cite>op</cite> in each tuple is a comparison operator, represented as
a string.  The <cite>version</cite> is the (unparsed) version number.</dd>
<dt><code class="docutils literal"><span class="pre">marker</span></code></dt>
<dd>An instance of <code class="docutils literal"><span class="pre">packaging.markers.Marker</span></code> that allows evaluation
against the current environment. May be None if no marker specified.</dd>
<dt><code class="docutils literal"><span class="pre">url</span></code></dt>
<dd>The location to download the requirement from if specified.</dd>
</dl>
</div>
</div>
<div class="section" id="entry-points">
<h3><a class="toc-backref" href="#id14">Entry Points</a><a class="headerlink" href="#entry-points" title="Permalink to this headline"></a></h3>
<p>Entry points are a simple way for distributions to “advertise” Python objects
(such as functions or classes) for use by other distributions.  Extensible
applications and frameworks can search for entry points with a particular name
or group, either from a specific distribution or from all active distributions
on sys.path, and then inspect or load the advertised objects at will.</p>
<p>Entry points belong to “groups” which are named with a dotted name similar to
a Python package or module name.  For example, the <code class="docutils literal"><span class="pre">setuptools</span></code> package uses
an entry point named <code class="docutils literal"><span class="pre">distutils.commands</span></code> in order to find commands defined
by distutils extensions.  <code class="docutils literal"><span class="pre">setuptools</span></code> treats the names of entry points
defined in that group as the acceptable commands for a setup script.</p>
<p>In a similar way, other packages can define their own entry point groups,
either using dynamic names within the group (like <code class="docutils literal"><span class="pre">distutils.commands</span></code>), or
possibly using predefined names within the group.  For example, a blogging
framework that offers various pre- or post-publishing hooks might define an
entry point group and look for entry points named “pre_process” and
“post_process” within that group.</p>
<p>To advertise an entry point, a project needs to use <code class="docutils literal"><span class="pre">setuptools</span></code> and provide
an <code class="docutils literal"><span class="pre">entry_points</span></code> argument to <code class="docutils literal"><span class="pre">setup()</span></code> in its setup script, so that the
entry points will be included in the distribution’s metadata.  For more
details, see the <code class="docutils literal"><span class="pre">setuptools</span></code> documentation.  (XXX link here to setuptools)</p>
<p>Each project distribution can advertise at most one entry point of a given
name within the same entry point group.  For example, a distutils extension
could advertise two different <code class="docutils literal"><span class="pre">distutils.commands</span></code> entry points, as long as
they had different names.  However, there is nothing that prevents <em>different</em>
projects from advertising entry points of the same name in the same group.  In
some cases, this is a desirable thing, since the application or framework that
uses the entry points may be calling them as hooks, or in some other way
combining them.  It is up to the application or framework to decide what to do
if multiple distributions advertise an entry point; some possibilities include
using both entry points, displaying an error message, using the first one found
in sys.path order, etc.</p>
<div class="section" id="convenience-api">
<h4><a class="toc-backref" href="#id15">Convenience API</a><a class="headerlink" href="#convenience-api" title="Permalink to this headline"></a></h4>
<p>In the following functions, the <cite>dist</cite> argument can be a <code class="docutils literal"><span class="pre">Distribution</span></code>
instance, a <code class="docutils literal"><span class="pre">Requirement</span></code> instance, or a string specifying a requirement
(i.e. project name, version, etc.).  If the argument is a string or
<code class="docutils literal"><span class="pre">Requirement</span></code>, the specified distribution is located (and added to sys.path
if not already present).  An error will be raised if a matching distribution is
not available.</p>
<p>The <cite>group</cite> argument should be a string containing a dotted identifier,
identifying an entry point group.  If you are defining an entry point group,
you should include some portion of your package’s name in the group name so as
to avoid collision with other packages’ entry point groups.</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">load_entry_point(dist,</span> <span class="pre">group,</span> <span class="pre">name)</span></code></dt>
<dd>Load the named entry point from the specified distribution, or raise
<code class="docutils literal"><span class="pre">ImportError</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">get_entry_info(dist,</span> <span class="pre">group,</span> <span class="pre">name)</span></code></dt>
<dd>Return an <code class="docutils literal"><span class="pre">EntryPoint</span></code> object for the given <cite>group</cite> and <cite>name</cite> from
the specified distribution.  Returns <code class="docutils literal"><span class="pre">None</span></code> if the distribution has not
advertised a matching entry point.</dd>
<dt><code class="docutils literal"><span class="pre">get_entry_map(dist,</span> <span class="pre">group=None)</span></code></dt>
<dd>Return the distribution’s entry point map for <cite>group</cite>, or the full entry
map for the distribution.  This function always returns a dictionary,
even if the distribution advertises no entry points.  If <cite>group</cite> is given,
the dictionary maps entry point names to the corresponding <code class="docutils literal"><span class="pre">EntryPoint</span></code>
object.  If <cite>group</cite> is None, the dictionary maps group names to
dictionaries that then map entry point names to the corresponding
<code class="docutils literal"><span class="pre">EntryPoint</span></code> instance in that group.</dd>
<dt><code class="docutils literal"><span class="pre">iter_entry_points(group,</span> <span class="pre">name=None)</span></code></dt>
<dd><p class="first">Yield entry point objects from <cite>group</cite> matching <cite>name</cite>.</p>
<p>If <cite>name</cite> is None, yields all entry points in <cite>group</cite> from all
distributions in the working set on sys.path, otherwise only ones matching
both <cite>group</cite> and <cite>name</cite> are yielded.  Entry points are yielded from
the active distributions in the order that the distributions appear on
sys.path.  (Within entry points for a particular distribution, however,
there is no particular ordering.)</p>
<p class="last">(This API is actually a method of the global <code class="docutils literal"><span class="pre">working_set</span></code> object; see
the section above on <a class="reference internal" href="#basic-workingset-methods">Basic WorkingSet Methods</a> for more information.)</p>
</dd>
</dl>
</div>
<div class="section" id="creating-and-parsing">
<h4><a class="toc-backref" href="#id16">Creating and Parsing</a><a class="headerlink" href="#creating-and-parsing" title="Permalink to this headline"></a></h4>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">EntryPoint(name,</span> <span class="pre">module_name,</span> <span class="pre">attrs=(),</span> <span class="pre">extras=(),</span> <span class="pre">dist=None)</span></code></dt>
<dd><p class="first">Create an <code class="docutils literal"><span class="pre">EntryPoint</span></code> instance.  <cite>name</cite> is the entry point name.  The
<cite>module_name</cite> is the (dotted) name of the module containing the advertised
object.  <cite>attrs</cite> is an optional tuple of names to look up from the
module to obtain the advertised object.  For example, an <cite>attrs</cite> of
<code class="docutils literal"><span class="pre">(&quot;foo&quot;,&quot;bar&quot;)</span></code> and a <cite>module_name</cite> of <code class="docutils literal"><span class="pre">&quot;baz&quot;</span></code> would mean that the
advertised object could be obtained by the following code:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">baz</span>
<span class="n">advertised_object</span> <span class="o">=</span> <span class="n">baz</span><span class="o">.</span><span class="n">foo</span><span class="o">.</span><span class="n">bar</span>
</pre></div>
</div>
<p class="last">The <cite>extras</cite> are an optional tuple of “extra feature” names that the
distribution needs in order to provide this entry point.  When the
entry point is loaded, these extra features are looked up in the <cite>dist</cite>
argument to find out what other distributions may need to be activated
on sys.path; see the <code class="docutils literal"><span class="pre">load()</span></code> method for more details.  The <cite>extras</cite>
argument is only meaningful if <cite>dist</cite> is specified.  <cite>dist</cite> must be
a <code class="docutils literal"><span class="pre">Distribution</span></code> instance.</p>
</dd>
<dt><code class="docutils literal"><span class="pre">EntryPoint.parse(src,</span> <span class="pre">dist=None)</span></code> (classmethod)</dt>
<dd><p class="first">Parse a single entry point from string <cite>src</cite></p>
<p>Entry point syntax follows the form:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">name</span> <span class="o">=</span> <span class="n">some</span><span class="o">.</span><span class="n">module</span><span class="p">:</span><span class="n">some</span><span class="o">.</span><span class="n">attr</span> <span class="p">[</span><span class="n">extra1</span><span class="p">,</span><span class="n">extra2</span><span class="p">]</span>
</pre></div>
</div>
<p class="last">The entry name and module name are required, but the <code class="docutils literal"><span class="pre">:attrs</span></code> and
<code class="docutils literal"><span class="pre">[extras]</span></code> parts are optional, as is the whitespace shown between
some of the items.  The <cite>dist</cite> argument is passed through to the
<code class="docutils literal"><span class="pre">EntryPoint()</span></code> constructor, along with the other values parsed from
<cite>src</cite>.</p>
</dd>
<dt><code class="docutils literal"><span class="pre">EntryPoint.parse_group(group,</span> <span class="pre">lines,</span> <span class="pre">dist=None)</span></code> (classmethod)</dt>
<dd>Parse <cite>lines</cite> (a string or sequence of lines) to create a dictionary
mapping entry point names to <code class="docutils literal"><span class="pre">EntryPoint</span></code> objects.  <code class="docutils literal"><span class="pre">ValueError</span></code> is
raised if entry point names are duplicated, if <cite>group</cite> is not a valid
entry point group name, or if there are any syntax errors.  (Note: the
<cite>group</cite> parameter is used only for validation and to create more
informative error messages.)  If <cite>dist</cite> is provided, it will be used to
set the <code class="docutils literal"><span class="pre">dist</span></code> attribute of the created <code class="docutils literal"><span class="pre">EntryPoint</span></code> objects.</dd>
<dt><code class="docutils literal"><span class="pre">EntryPoint.parse_map(data,</span> <span class="pre">dist=None)</span></code> (classmethod)</dt>
<dd>Parse <cite>data</cite> into a dictionary mapping group names to dictionaries mapping
entry point names to <code class="docutils literal"><span class="pre">EntryPoint</span></code> objects.  If <cite>data</cite> is a dictionary,
then the keys are used as group names and the values are passed to
<code class="docutils literal"><span class="pre">parse_group()</span></code> as the <cite>lines</cite> argument.  If <cite>data</cite> is a string or
sequence of lines, it is first split into .ini-style sections (using
the <code class="docutils literal"><span class="pre">split_sections()</span></code> utility function) and the section names are used
as group names.  In either case, the <cite>dist</cite> argument is passed through to
<code class="docutils literal"><span class="pre">parse_group()</span></code> so that the entry points will be linked to the specified
distribution.</dd>
</dl>
</div>
<div class="section" id="entrypoint-objects">
<h4><a class="toc-backref" href="#id17"><code class="docutils literal"><span class="pre">EntryPoint</span></code> Objects</a><a class="headerlink" href="#entrypoint-objects" title="Permalink to this headline"></a></h4>
<p>For simple introspection, <code class="docutils literal"><span class="pre">EntryPoint</span></code> objects have attributes that
correspond exactly to the constructor argument names: <code class="docutils literal"><span class="pre">name</span></code>,
<code class="docutils literal"><span class="pre">module_name</span></code>, <code class="docutils literal"><span class="pre">attrs</span></code>, <code class="docutils literal"><span class="pre">extras</span></code>, and <code class="docutils literal"><span class="pre">dist</span></code> are all available.  In
addition, the following methods are provided:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">load()</span></code></dt>
<dd>Load the entry point, returning the advertised Python object.  Effectively
calls <code class="docutils literal"><span class="pre">self.require()</span></code> then returns <code class="docutils literal"><span class="pre">self.resolve()</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">require(env=None,</span> <span class="pre">installer=None)</span></code></dt>
<dd>Ensure that any “extras” needed by the entry point are available on
sys.path.  <code class="docutils literal"><span class="pre">UnknownExtra</span></code> is raised if the <code class="docutils literal"><span class="pre">EntryPoint</span></code> has <code class="docutils literal"><span class="pre">extras</span></code>,
but no <code class="docutils literal"><span class="pre">dist</span></code>, or if the named extras are not defined by the
distribution.  If <cite>env</cite> is supplied, it must be an <code class="docutils literal"><span class="pre">Environment</span></code>, and it
will be used to search for needed distributions if they are not already
present on sys.path.  If <cite>installer</cite> is supplied, it must be a callable
taking a <code class="docutils literal"><span class="pre">Requirement</span></code> instance and returning a matching importable
<code class="docutils literal"><span class="pre">Distribution</span></code> instance or None.</dd>
<dt><code class="docutils literal"><span class="pre">resolve()</span></code></dt>
<dd>Resolve the entry point from its module and attrs, returning the advertised
Python object. Raises <code class="docutils literal"><span class="pre">ImportError</span></code> if it cannot be obtained.</dd>
<dt><code class="docutils literal"><span class="pre">__str__()</span></code></dt>
<dd>The string form of an <code class="docutils literal"><span class="pre">EntryPoint</span></code> is a string that could be passed to
<code class="docutils literal"><span class="pre">EntryPoint.parse()</span></code> to produce an equivalent <code class="docutils literal"><span class="pre">EntryPoint</span></code>.</dd>
</dl>
</div>
</div>
<div class="section" id="distribution-objects">
<h3><a class="toc-backref" href="#id18"><code class="docutils literal"><span class="pre">Distribution</span></code> Objects</a><a class="headerlink" href="#distribution-objects" title="Permalink to this headline"></a></h3>
<p><code class="docutils literal"><span class="pre">Distribution</span></code> objects represent collections of Python code that may or may
not be importable, and may or may not have metadata and resources associated
with them.  Their metadata may include information such as what other projects
the distribution depends on, what entry points the distribution advertises, and
so on.</p>
<div class="section" id="getting-or-creating-distributions">
<h4><a class="toc-backref" href="#id19">Getting or Creating Distributions</a><a class="headerlink" href="#getting-or-creating-distributions" title="Permalink to this headline"></a></h4>
<p>Most commonly, you’ll obtain <code class="docutils literal"><span class="pre">Distribution</span></code> objects from a <code class="docutils literal"><span class="pre">WorkingSet</span></code> or
an <code class="docutils literal"><span class="pre">Environment</span></code>.  (See the sections above on <a class="reference internal" href="#workingset-objects">WorkingSet Objects</a> and
<a class="reference internal" href="#environment-objects">Environment Objects</a>, which are containers for active distributions and
available distributions, respectively.)  You can also obtain <code class="docutils literal"><span class="pre">Distribution</span></code>
objects from one of these high-level APIs:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">find_distributions(path_item,</span> <span class="pre">only=False)</span></code></dt>
<dd>Yield distributions accessible via <cite>path_item</cite>.  If <cite>only</cite> is true, yield
only distributions whose <code class="docutils literal"><span class="pre">location</span></code> is equal to <cite>path_item</cite>.  In other
words, if <cite>only</cite> is true, this yields any distributions that would be
importable if <cite>path_item</cite> were on <code class="docutils literal"><span class="pre">sys.path</span></code>.  If <cite>only</cite> is false, this
also yields distributions that are “in” or “under” <cite>path_item</cite>, but would
not be importable unless their locations were also added to <code class="docutils literal"><span class="pre">sys.path</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">get_distribution(dist_spec)</span></code></dt>
<dd>Return a <code class="docutils literal"><span class="pre">Distribution</span></code> object for a given <code class="docutils literal"><span class="pre">Requirement</span></code> or string.
If <cite>dist_spec</cite> is already a <code class="docutils literal"><span class="pre">Distribution</span></code> instance, it is returned.
If it is a <code class="docutils literal"><span class="pre">Requirement</span></code> object or a string that can be parsed into one,
it is used to locate and activate a matching distribution, which is then
returned.</dd>
</dl>
<p>However, if you’re creating specialized tools for working with distributions,
or creating a new distribution format, you may also need to create
<code class="docutils literal"><span class="pre">Distribution</span></code> objects directly, using one of the three constructors below.</p>
<p>These constructors all take an optional <cite>metadata</cite> argument, which is used to
access any resources or metadata associated with the distribution.  <cite>metadata</cite>
must be an object that implements the <code class="docutils literal"><span class="pre">IResourceProvider</span></code> interface, or None.
If it is None, an <code class="docutils literal"><span class="pre">EmptyProvider</span></code> is used instead.  <code class="docutils literal"><span class="pre">Distribution</span></code> objects
implement both the <a class="reference internal" href="#iresourceprovider">IResourceProvider</a> and <a class="reference internal" href="#imetadataprovider-methods">IMetadataProvider Methods</a> by
delegating them to the <cite>metadata</cite> object.</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">Distribution.from_location(location,</span> <span class="pre">basename,</span> <span class="pre">metadata=None,</span> <span class="pre">**kw)</span></code> (classmethod)</dt>
<dd>Create a distribution for <cite>location</cite>, which must be a string such as a
URL, filename, or other string that might be used on <code class="docutils literal"><span class="pre">sys.path</span></code>.
<cite>basename</cite> is a string naming the distribution, like <code class="docutils literal"><span class="pre">Foo-1.2-py2.4.egg</span></code>.
If <cite>basename</cite> ends with <code class="docutils literal"><span class="pre">.egg</span></code>, then the project’s name, version, python
version and platform are extracted from the filename and used to set those
properties of the created distribution.  Any additional keyword arguments
are forwarded to the <code class="docutils literal"><span class="pre">Distribution()</span></code> constructor.</dd>
<dt><code class="docutils literal"><span class="pre">Distribution.from_filename(filename,</span> <span class="pre">metadata=None**kw)</span></code> (classmethod)</dt>
<dd>Create a distribution by parsing a local filename.  This is a shorter way
of saying  <code class="docutils literal"><span class="pre">Distribution.from_location(normalize_path(filename),</span>
<span class="pre">os.path.basename(filename),</span> <span class="pre">metadata)</span></code>.  In other words, it creates a
distribution whose location is the normalize form of the filename, parsing
name and version information from the base portion of the filename.  Any
additional keyword arguments are forwarded to the <code class="docutils literal"><span class="pre">Distribution()</span></code>
constructor.</dd>
<dt><code class="docutils literal"><span class="pre">Distribution(location,metadata,project_name,version,py_version,platform,precedence)</span></code></dt>
<dd>Create a distribution by setting its properties.  All arguments are
optional and default to None, except for <cite>py_version</cite> (which defaults to
the current Python version) and <cite>precedence</cite> (which defaults to
<code class="docutils literal"><span class="pre">EGG_DIST</span></code>; for more details see <code class="docutils literal"><span class="pre">precedence</span></code> under <a class="reference internal" href="#distribution-attributes">Distribution
Attributes</a> below).  Note that it’s usually easier to use the
<code class="docutils literal"><span class="pre">from_filename()</span></code> or <code class="docutils literal"><span class="pre">from_location()</span></code> constructors than to specify
all these arguments individually.</dd>
</dl>
</div>
<div class="section" id="distribution-attributes">
<h4><a class="toc-backref" href="#id20"><code class="docutils literal"><span class="pre">Distribution</span></code> Attributes</a><a class="headerlink" href="#distribution-attributes" title="Permalink to this headline"></a></h4>
<dl class="docutils">
<dt>location</dt>
<dd>A string indicating the distribution’s location.  For an importable
distribution, this is the string that would be added to <code class="docutils literal"><span class="pre">sys.path</span></code> to
make it actively importable.  For non-importable distributions, this is
simply a filename, URL, or other way of locating the distribution.</dd>
<dt>project_name</dt>
<dd>A string, naming the project that this distribution is for.  Project names
are defined by a project’s setup script, and they are used to identify
projects on PyPI.  When a <code class="docutils literal"><span class="pre">Distribution</span></code> is constructed, the
<cite>project_name</cite> argument is passed through the <code class="docutils literal"><span class="pre">safe_name()</span></code> utility
function to filter out any unacceptable characters.</dd>
<dt>key</dt>
<dd><code class="docutils literal"><span class="pre">dist.key</span></code> is short for <code class="docutils literal"><span class="pre">dist.project_name.lower()</span></code>.  It’s used for
case-insensitive comparison and indexing of distributions by project name.</dd>
<dt>extras</dt>
<dd>A list of strings, giving the names of extra features defined by the
project’s dependency list (the <code class="docutils literal"><span class="pre">extras_require</span></code> argument specified in
the project’s setup script).</dd>
<dt>version</dt>
<dd>A string denoting what release of the project this distribution contains.
When a <code class="docutils literal"><span class="pre">Distribution</span></code> is constructed, the <cite>version</cite> argument is passed
through the <code class="docutils literal"><span class="pre">safe_version()</span></code> utility function to filter out any
unacceptable characters.  If no <cite>version</cite> is specified at construction
time, then attempting to access this attribute later will cause the
<code class="docutils literal"><span class="pre">Distribution</span></code> to try to discover its version by reading its <code class="docutils literal"><span class="pre">PKG-INFO</span></code>
metadata file.  If <code class="docutils literal"><span class="pre">PKG-INFO</span></code> is unavailable or can’t be parsed,
<code class="docutils literal"><span class="pre">ValueError</span></code> is raised.</dd>
<dt>parsed_version</dt>
<dd>The <code class="docutils literal"><span class="pre">parsed_version</span></code> is an object representing a “parsed” form of the
distribution’s <code class="docutils literal"><span class="pre">version</span></code>.  <code class="docutils literal"><span class="pre">dist.parsed_version</span></code> is a shortcut for
calling <code class="docutils literal"><span class="pre">parse_version(dist.version)</span></code>.  It is used to compare or sort
distributions by version.  (See the <a class="reference internal" href="#parsing-utilities">Parsing Utilities</a> section below for
more information on the <code class="docutils literal"><span class="pre">parse_version()</span></code> function.)  Note that accessing
<code class="docutils literal"><span class="pre">parsed_version</span></code> may result in a <code class="docutils literal"><span class="pre">ValueError</span></code> if the <code class="docutils literal"><span class="pre">Distribution</span></code>
was constructed without a <cite>version</cite> and without <cite>metadata</cite> capable of
supplying the missing version info.</dd>
<dt>py_version</dt>
<dd>The major/minor Python version the distribution supports, as a string.
For example, “2.7” or “3.4”.  The default is the current version of Python.</dd>
<dt>platform</dt>
<dd>A string representing the platform the distribution is intended for, or
<code class="docutils literal"><span class="pre">None</span></code> if the distribution is “pure Python” and therefore cross-platform.
See <a class="reference internal" href="#platform-utilities">Platform Utilities</a> below for more information on platform strings.</dd>
<dt>precedence</dt>
<dd>A distribution’s <code class="docutils literal"><span class="pre">precedence</span></code> is used to determine the relative order of
two distributions that have the same <code class="docutils literal"><span class="pre">project_name</span></code> and
<code class="docutils literal"><span class="pre">parsed_version</span></code>.  The default precedence is <code class="docutils literal"><span class="pre">pkg_resources.EGG_DIST</span></code>,
which is the highest (i.e. most preferred) precedence.  The full list
of predefined precedences, from most preferred to least preferred, is:
<code class="docutils literal"><span class="pre">EGG_DIST</span></code>, <code class="docutils literal"><span class="pre">BINARY_DIST</span></code>, <code class="docutils literal"><span class="pre">SOURCE_DIST</span></code>, <code class="docutils literal"><span class="pre">CHECKOUT_DIST</span></code>, and
<code class="docutils literal"><span class="pre">DEVELOP_DIST</span></code>.  Normally, precedences other than <code class="docutils literal"><span class="pre">EGG_DIST</span></code> are used
only by the <code class="docutils literal"><span class="pre">setuptools.package_index</span></code> module, when sorting distributions
found in a package index to determine their suitability for installation.
“System” and “Development” eggs (i.e., ones that use the <code class="docutils literal"><span class="pre">.egg-info</span></code>
format), however, are automatically given a precedence of <code class="docutils literal"><span class="pre">DEVELOP_DIST</span></code>.</dd>
</dl>
</div>
<div class="section" id="distribution-methods">
<h4><a class="toc-backref" href="#id21"><code class="docutils literal"><span class="pre">Distribution</span></code> Methods</a><a class="headerlink" href="#distribution-methods" title="Permalink to this headline"></a></h4>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">activate(path=None)</span></code></dt>
<dd><p class="first">Ensure distribution is importable on <cite>path</cite>.  If <cite>path</cite> is None,
<code class="docutils literal"><span class="pre">sys.path</span></code> is used instead.  This ensures that the distribution’s
<code class="docutils literal"><span class="pre">location</span></code> is in the <cite>path</cite> list, and it also performs any necessary
namespace package fixups or declarations.  (That is, if the distribution
contains namespace packages, this method ensures that they are declared,
and that the distribution’s contents for those namespace packages are
merged with the contents provided by any other active distributions.  See
the section above on <a class="reference internal" href="#namespace-package-support">Namespace Package Support</a> for more information.)</p>
<p class="last"><code class="docutils literal"><span class="pre">pkg_resources</span></code> adds a notification callback to the global <code class="docutils literal"><span class="pre">working_set</span></code>
that ensures this method is called whenever a distribution is added to it.
Therefore, you should not normally need to explicitly call this method.
(Note that this means that namespace packages on <code class="docutils literal"><span class="pre">sys.path</span></code> are always
imported as soon as <code class="docutils literal"><span class="pre">pkg_resources</span></code> is, which is another reason why
namespace packages should not contain any code or import statements.)</p>
</dd>
<dt><code class="docutils literal"><span class="pre">as_requirement()</span></code></dt>
<dd>Return a <code class="docutils literal"><span class="pre">Requirement</span></code> instance that matches this distribution’s project
name and version.</dd>
<dt><code class="docutils literal"><span class="pre">requires(extras=())</span></code></dt>
<dd>List the <code class="docutils literal"><span class="pre">Requirement</span></code> objects that specify this distribution’s
dependencies.  If <cite>extras</cite> is specified, it should be a sequence of names
of “extras” defined by the distribution, and the list returned will then
include any dependencies needed to support the named “extras”.</dd>
<dt><code class="docutils literal"><span class="pre">clone(**kw)</span></code></dt>
<dd>Create a copy of the distribution.  Any supplied keyword arguments override
the corresponding argument to the <code class="docutils literal"><span class="pre">Distribution()</span></code> constructor, allowing
you to change some of the copied distribution’s attributes.</dd>
<dt><code class="docutils literal"><span class="pre">egg_name()</span></code></dt>
<dd>Return what this distribution’s standard filename should be, not including
the “.egg” extension.  For example, a distribution for project “Foo”
version 1.2 that runs on Python 2.3 for Windows would have an <code class="docutils literal"><span class="pre">egg_name()</span></code>
of <code class="docutils literal"><span class="pre">Foo-1.2-py2.3-win32</span></code>.  Any dashes in the name or version are
converted to underscores.  (<code class="docutils literal"><span class="pre">Distribution.from_location()</span></code> will convert
them back when parsing a “.egg” file name.)</dd>
<dt><code class="docutils literal"><span class="pre">__cmp__(other)</span></code>, <code class="docutils literal"><span class="pre">__hash__()</span></code></dt>
<dd>Distribution objects are hashed and compared on the basis of their parsed
version and precedence, followed by their key (lowercase project name),
location, Python version, and platform.</dd>
</dl>
<p>The following methods are used to access <code class="docutils literal"><span class="pre">EntryPoint</span></code> objects advertised
by the distribution.  See the section above on <a class="reference internal" href="#entry-points">Entry Points</a> for more
detailed information about these operations:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">get_entry_info(group,</span> <span class="pre">name)</span></code></dt>
<dd>Return the <code class="docutils literal"><span class="pre">EntryPoint</span></code> object for <cite>group</cite> and <cite>name</cite>, or None if no
such point is advertised by this distribution.</dd>
<dt><code class="docutils literal"><span class="pre">get_entry_map(group=None)</span></code></dt>
<dd>Return the entry point map for <cite>group</cite>.  If <cite>group</cite> is None, return
a dictionary mapping group names to entry point maps for all groups.
(An entry point map is a dictionary of entry point names to <code class="docutils literal"><span class="pre">EntryPoint</span></code>
objects.)</dd>
<dt><code class="docutils literal"><span class="pre">load_entry_point(group,</span> <span class="pre">name)</span></code></dt>
<dd>Short for <code class="docutils literal"><span class="pre">get_entry_info(group,</span> <span class="pre">name).load()</span></code>.  Returns the object
advertised by the named entry point, or raises <code class="docutils literal"><span class="pre">ImportError</span></code> if
the entry point isn’t advertised by this distribution, or there is some
other import problem.</dd>
</dl>
<p>In addition to the above methods, <code class="docutils literal"><span class="pre">Distribution</span></code> objects also implement all
of the <a class="reference internal" href="#iresourceprovider">IResourceProvider</a> and <a class="reference internal" href="#imetadataprovider-methods">IMetadataProvider Methods</a> (which are
documented in later sections):</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">has_metadata(name)</span></code></li>
<li><code class="docutils literal"><span class="pre">metadata_isdir(name)</span></code></li>
<li><code class="docutils literal"><span class="pre">metadata_listdir(name)</span></code></li>
<li><code class="docutils literal"><span class="pre">get_metadata(name)</span></code></li>
<li><code class="docutils literal"><span class="pre">get_metadata_lines(name)</span></code></li>
<li><code class="docutils literal"><span class="pre">run_script(script_name,</span> <span class="pre">namespace)</span></code></li>
<li><code class="docutils literal"><span class="pre">get_resource_filename(manager,</span> <span class="pre">resource_name)</span></code></li>
<li><code class="docutils literal"><span class="pre">get_resource_stream(manager,</span> <span class="pre">resource_name)</span></code></li>
<li><code class="docutils literal"><span class="pre">get_resource_string(manager,</span> <span class="pre">resource_name)</span></code></li>
<li><code class="docutils literal"><span class="pre">has_resource(resource_name)</span></code></li>
<li><code class="docutils literal"><span class="pre">resource_isdir(resource_name)</span></code></li>
<li><code class="docutils literal"><span class="pre">resource_listdir(resource_name)</span></code></li>
</ul>
<p>If the distribution was created with a <cite>metadata</cite> argument, these resource and
metadata access methods are all delegated to that <cite>metadata</cite> provider.
Otherwise, they are delegated to an <code class="docutils literal"><span class="pre">EmptyProvider</span></code>, so that the distribution
will appear to have no resources or metadata.  This delegation approach is used
so that supporting custom importers or new distribution formats can be done
simply by creating an appropriate <a class="reference internal" href="#iresourceprovider">IResourceProvider</a> implementation; see the
section below on <a class="reference internal" href="#supporting-custom-importers">Supporting Custom Importers</a> for more details.</p>
</div>
</div>
<div class="section" id="resourcemanager-api">
<h3><a class="toc-backref" href="#id22"><code class="docutils literal"><span class="pre">ResourceManager</span></code> API</a><a class="headerlink" href="#resourcemanager-api" title="Permalink to this headline"></a></h3>
<p>The <code class="docutils literal"><span class="pre">ResourceManager</span></code> class provides uniform access to package resources,
whether those resources exist as files and directories or are compressed in
an archive of some kind.</p>
<p>Normally, you do not need to create or explicitly manage <code class="docutils literal"><span class="pre">ResourceManager</span></code>
instances, as the <code class="docutils literal"><span class="pre">pkg_resources</span></code> module creates a global instance for you,
and makes most of its methods available as top-level names in the
<code class="docutils literal"><span class="pre">pkg_resources</span></code> module namespace.  So, for example, this code actually
calls the <code class="docutils literal"><span class="pre">resource_string()</span></code> method of the global <code class="docutils literal"><span class="pre">ResourceManager</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">pkg_resources</span>
<span class="n">my_data</span> <span class="o">=</span> <span class="n">pkg_resources</span><span class="o">.</span><span class="n">resource_string</span><span class="p">(</span><span class="vm">__name__</span><span class="p">,</span> <span class="s2">&quot;foo.dat&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>Thus, you can use the APIs below without needing an explicit
<code class="docutils literal"><span class="pre">ResourceManager</span></code> instance; just import and use them as needed.</p>
<div class="section" id="basic-resource-access">
<h4><a class="toc-backref" href="#id23">Basic Resource Access</a><a class="headerlink" href="#basic-resource-access" title="Permalink to this headline"></a></h4>
<p>In the following methods, the <cite>package_or_requirement</cite> argument may be either
a Python package/module name (e.g. <code class="docutils literal"><span class="pre">foo.bar</span></code>) or a <code class="docutils literal"><span class="pre">Requirement</span></code> instance.
If it is a package or module name, the named module or package must be
importable (i.e., be in a distribution or directory on <code class="docutils literal"><span class="pre">sys.path</span></code>), and the
<cite>resource_name</cite> argument is interpreted relative to the named package.  (Note
that if a module name is used, then the resource name is relative to the
package immediately containing the named module.  Also, you should not use use
a namespace package name, because a namespace package can be spread across
multiple distributions, and is therefore ambiguous as to which distribution
should be searched for the resource.)</p>
<p>If it is a <code class="docutils literal"><span class="pre">Requirement</span></code>, then the requirement is automatically resolved
(searching the current <code class="docutils literal"><span class="pre">Environment</span></code> if necessary) and a matching
distribution is added to the <code class="docutils literal"><span class="pre">WorkingSet</span></code> and <code class="docutils literal"><span class="pre">sys.path</span></code> if one was not
already present.  (Unless the <code class="docutils literal"><span class="pre">Requirement</span></code> can’t be satisfied, in which
case an exception is raised.)  The <cite>resource_name</cite> argument is then interpreted
relative to the root of the identified distribution; i.e. its first path
segment will be treated as a peer of the top-level modules or packages in the
distribution.</p>
<p>Note that resource names must be <code class="docutils literal"><span class="pre">/</span></code>-separated paths and cannot be absolute
(i.e. no leading <code class="docutils literal"><span class="pre">/</span></code>) or contain relative names like <code class="docutils literal"><span class="pre">&quot;..&quot;</span></code>.  Do <em>not</em> use
<code class="docutils literal"><span class="pre">os.path</span></code> routines to manipulate resource paths, as they are <em>not</em> filesystem
paths.</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">resource_exists(package_or_requirement,</span> <span class="pre">resource_name)</span></code></dt>
<dd>Does the named resource exist?  Return <code class="docutils literal"><span class="pre">True</span></code> or <code class="docutils literal"><span class="pre">False</span></code> accordingly.</dd>
<dt><code class="docutils literal"><span class="pre">resource_stream(package_or_requirement,</span> <span class="pre">resource_name)</span></code></dt>
<dd>Return a readable file-like object for the specified resource; it may be
an actual file, a <code class="docutils literal"><span class="pre">StringIO</span></code>, or some similar object.  The stream is
in “binary mode”, in the sense that whatever bytes are in the resource
will be read as-is.</dd>
<dt><code class="docutils literal"><span class="pre">resource_string(package_or_requirement,</span> <span class="pre">resource_name)</span></code></dt>
<dd>Return the specified resource as a string.  The resource is read in
binary fashion, such that the returned string contains exactly the bytes
that are stored in the resource.</dd>
<dt><code class="docutils literal"><span class="pre">resource_isdir(package_or_requirement,</span> <span class="pre">resource_name)</span></code></dt>
<dd>Is the named resource a directory?  Return <code class="docutils literal"><span class="pre">True</span></code> or <code class="docutils literal"><span class="pre">False</span></code>
accordingly.</dd>
<dt><code class="docutils literal"><span class="pre">resource_listdir(package_or_requirement,</span> <span class="pre">resource_name)</span></code></dt>
<dd>List the contents of the named resource directory, just like <code class="docutils literal"><span class="pre">os.listdir</span></code>
except that it works even if the resource is in a zipfile.</dd>
</dl>
<p>Note that only <code class="docutils literal"><span class="pre">resource_exists()</span></code> and <code class="docutils literal"><span class="pre">resource_isdir()</span></code> are insensitive
as to the resource type.  You cannot use <code class="docutils literal"><span class="pre">resource_listdir()</span></code> on a file
resource, and you can’t use <code class="docutils literal"><span class="pre">resource_string()</span></code> or <code class="docutils literal"><span class="pre">resource_stream()</span></code> on
directory resources.  Using an inappropriate method for the resource type may
result in an exception or undefined behavior, depending on the platform and
distribution format involved.</p>
</div>
<div class="section" id="resource-extraction">
<h4><a class="toc-backref" href="#id24">Resource Extraction</a><a class="headerlink" href="#resource-extraction" title="Permalink to this headline"></a></h4>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">resource_filename(package_or_requirement,</span> <span class="pre">resource_name)</span></code></dt>
<dd><p class="first">Sometimes, it is not sufficient to access a resource in string or stream
form, and a true filesystem filename is needed.  In such cases, you can
use this method (or module-level function) to obtain a filename for a
resource.  If the resource is in an archive distribution (such as a zipped
egg), it will be extracted to a cache directory, and the filename within
the cache will be returned.  If the named resource is a directory, then
all resources within that directory (including subdirectories) are also
extracted.  If the named resource is a C extension or “eager resource”
(see the <code class="docutils literal"><span class="pre">setuptools</span></code> documentation for details), then all C extensions
and eager resources are extracted at the same time.</p>
<p class="last">Archived resources are extracted to a cache location that can be managed by
the following two methods:</p>
</dd>
<dt><code class="docutils literal"><span class="pre">set_extraction_path(path)</span></code></dt>
<dd><p class="first">Set the base path where resources will be extracted to, if needed.</p>
<p>If you do not call this routine before any extractions take place, the
path defaults to the return value of <code class="docutils literal"><span class="pre">get_default_cache()</span></code>.  (Which is
based on the <code class="docutils literal"><span class="pre">PYTHON_EGG_CACHE</span></code> environment variable, with various
platform-specific fallbacks.  See that routine’s documentation for more
details.)</p>
<p>Resources are extracted to subdirectories of this path based upon
information given by the resource provider.  You may set this to a
temporary directory, but then you must call <code class="docutils literal"><span class="pre">cleanup_resources()</span></code> to
delete the extracted files when done.  There is no guarantee that
<code class="docutils literal"><span class="pre">cleanup_resources()</span></code> will be able to remove all extracted files.  (On
Windows, for example, you can’t unlink .pyd or .dll files that are still
in use.)</p>
<p class="last">Note that you may not change the extraction path for a given resource
manager once resources have been extracted, unless you first call
<code class="docutils literal"><span class="pre">cleanup_resources()</span></code>.</p>
</dd>
<dt><code class="docutils literal"><span class="pre">cleanup_resources(force=False)</span></code></dt>
<dd>Delete all extracted resource files and directories, returning a list
of the file and directory names that could not be successfully removed.
This function does not have any concurrency protection, so it should
generally only be called when the extraction path is a temporary
directory exclusive to a single process.  This method is not
automatically called; you must call it explicitly or register it as an
<code class="docutils literal"><span class="pre">atexit</span></code> function if you wish to ensure cleanup of a temporary
directory used for extractions.</dd>
</dl>
</div>
<div class="section" id="provider-interface">
<h4><a class="toc-backref" href="#id25">“Provider” Interface</a><a class="headerlink" href="#provider-interface" title="Permalink to this headline"></a></h4>
<p>If you are implementing an <code class="docutils literal"><span class="pre">IResourceProvider</span></code> and/or <code class="docutils literal"><span class="pre">IMetadataProvider</span></code>
for a new distribution archive format, you may need to use the following
<code class="docutils literal"><span class="pre">IResourceManager</span></code> methods to co-ordinate extraction of resources to the
filesystem.  If you’re not implementing an archive format, however, you have
no need to use these methods.  Unlike the other methods listed above, they are
<em>not</em> available as top-level functions tied to the global <code class="docutils literal"><span class="pre">ResourceManager</span></code>;
you must therefore have an explicit <code class="docutils literal"><span class="pre">ResourceManager</span></code> instance to use them.</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">get_cache_path(archive_name,</span> <span class="pre">names=())</span></code></dt>
<dd><p class="first">Return absolute location in cache for <cite>archive_name</cite> and <cite>names</cite></p>
<p>The parent directory of the resulting path will be created if it does
not already exist.  <cite>archive_name</cite> should be the base filename of the
enclosing egg (which may not be the name of the enclosing zipfile!),
including its “.egg” extension.  <cite>names</cite>, if provided, should be a
sequence of path name parts “under” the egg’s extraction location.</p>
<p class="last">This method should only be called by resource providers that need to
obtain an extraction location, and only for names they intend to
extract, as it tracks the generated names for possible cleanup later.</p>
</dd>
<dt><code class="docutils literal"><span class="pre">extraction_error()</span></code></dt>
<dd>Raise an <code class="docutils literal"><span class="pre">ExtractionError</span></code> describing the active exception as interfering
with the extraction process.  You should call this if you encounter any
OS errors extracting the file to the cache path; it will format the
operating system exception for you, and add other information to the
<code class="docutils literal"><span class="pre">ExtractionError</span></code> instance that may be needed by programs that want to
wrap or handle extraction errors themselves.</dd>
<dt><code class="docutils literal"><span class="pre">postprocess(tempname,</span> <span class="pre">filename)</span></code></dt>
<dd><p class="first">Perform any platform-specific postprocessing of <cite>tempname</cite>.
Resource providers should call this method ONLY after successfully
extracting a compressed resource.  They must NOT call it on resources
that are already in the filesystem.</p>
<p class="last"><cite>tempname</cite> is the current (temporary) name of the file, and <cite>filename</cite>
is the name it will be renamed to by the caller after this routine
returns.</p>
</dd>
</dl>
</div>
</div>
<div class="section" id="metadata-api">
<h3><a class="toc-backref" href="#id26">Metadata API</a><a class="headerlink" href="#metadata-api" title="Permalink to this headline"></a></h3>
<p>The metadata API is used to access metadata resources bundled in a pluggable
distribution.  Metadata resources are virtual files or directories containing
information about the distribution, such as might be used by an extensible
application or framework to connect “plugins”.  Like other kinds of resources,
metadata resource names are <code class="docutils literal"><span class="pre">/</span></code>-separated and should not contain <code class="docutils literal"><span class="pre">..</span></code> or
begin with a <code class="docutils literal"><span class="pre">/</span></code>.  You should not use <code class="docutils literal"><span class="pre">os.path</span></code> routines to manipulate
resource paths.</p>
<p>The metadata API is provided by objects implementing the <code class="docutils literal"><span class="pre">IMetadataProvider</span></code>
or <code class="docutils literal"><span class="pre">IResourceProvider</span></code> interfaces.  <code class="docutils literal"><span class="pre">Distribution</span></code> objects implement this
interface, as do objects returned by the <code class="docutils literal"><span class="pre">get_provider()</span></code> function:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">get_provider(package_or_requirement)</span></code></dt>
<dd><p class="first">If a package name is supplied, return an <code class="docutils literal"><span class="pre">IResourceProvider</span></code> for the
package.  If a <code class="docutils literal"><span class="pre">Requirement</span></code> is supplied, resolve it by returning a
<code class="docutils literal"><span class="pre">Distribution</span></code> from the current working set (searching the current
<code class="docutils literal"><span class="pre">Environment</span></code> if necessary and adding the newly found <code class="docutils literal"><span class="pre">Distribution</span></code>
to the working set).  If the named package can’t be imported, or the
<code class="docutils literal"><span class="pre">Requirement</span></code> can’t be satisfied, an exception is raised.</p>
<p class="last">NOTE: if you use a package name rather than a <code class="docutils literal"><span class="pre">Requirement</span></code>, the object
you get back may not be a pluggable distribution, depending on the method
by which the package was installed.  In particular, “development” packages
and “single-version externally-managed” packages do not have any way to
map from a package name to the corresponding project’s metadata.  Do not
write code that passes a package name to <code class="docutils literal"><span class="pre">get_provider()</span></code> and then tries
to retrieve project metadata from the returned object.  It may appear to
work when the named package is in an <code class="docutils literal"><span class="pre">.egg</span></code> file or directory, but
it will fail in other installation scenarios.  If you want project
metadata, you need to ask for a <em>project</em>, not a package.</p>
</dd>
</dl>
<div class="section" id="imetadataprovider-methods">
<h4><a class="toc-backref" href="#id27"><code class="docutils literal"><span class="pre">IMetadataProvider</span></code> Methods</a><a class="headerlink" href="#imetadataprovider-methods" title="Permalink to this headline"></a></h4>
<p>The methods provided by objects (such as <code class="docutils literal"><span class="pre">Distribution</span></code> instances) that
implement the <code class="docutils literal"><span class="pre">IMetadataProvider</span></code> or <code class="docutils literal"><span class="pre">IResourceProvider</span></code> interfaces are:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">has_metadata(name)</span></code></dt>
<dd>Does the named metadata resource exist?</dd>
<dt><code class="docutils literal"><span class="pre">metadata_isdir(name)</span></code></dt>
<dd>Is the named metadata resource a directory?</dd>
<dt><code class="docutils literal"><span class="pre">metadata_listdir(name)</span></code></dt>
<dd>List of metadata names in the directory (like <code class="docutils literal"><span class="pre">os.listdir()</span></code>)</dd>
<dt><code class="docutils literal"><span class="pre">get_metadata(name)</span></code></dt>
<dd>Return the named metadata resource as a string.  The data is read in binary
mode; i.e., the exact bytes of the resource file are returned.</dd>
<dt><code class="docutils literal"><span class="pre">get_metadata_lines(name)</span></code></dt>
<dd>Yield named metadata resource as list of non-blank non-comment lines.  This
is short for calling <code class="docutils literal"><span class="pre">yield_lines(provider.get_metadata(name))</span></code>.  See the
section on <a class="reference internal" href="#yield-lines">yield_lines()</a> below for more information on the syntax it
recognizes.</dd>
<dt><code class="docutils literal"><span class="pre">run_script(script_name,</span> <span class="pre">namespace)</span></code></dt>
<dd>Execute the named script in the supplied namespace dictionary.  Raises
<code class="docutils literal"><span class="pre">ResolutionError</span></code> if there is no script by that name in the <code class="docutils literal"><span class="pre">scripts</span></code>
metadata directory.  <cite>namespace</cite> should be a Python dictionary, usually
a module dictionary if the script is being run as a module.</dd>
</dl>
</div>
</div>
<div class="section" id="exceptions">
<h3><a class="toc-backref" href="#id28">Exceptions</a><a class="headerlink" href="#exceptions" title="Permalink to this headline"></a></h3>
<p><code class="docutils literal"><span class="pre">pkg_resources</span></code> provides a simple exception hierarchy for problems that may
occur when processing requests to locate and activate packages:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">ResolutionError</span>
    <span class="n">DistributionNotFound</span>
    <span class="n">VersionConflict</span>
    <span class="n">UnknownExtra</span>

<span class="n">ExtractionError</span>
</pre></div>
</div>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">ResolutionError</span></code></dt>
<dd>This class is used as a base class for the other three exceptions, so that
you can catch all of them with a single “except” clause.  It is also raised
directly for miscellaneous requirement-resolution problems like trying to
run a script that doesn’t exist in the distribution it was requested from.</dd>
<dt><code class="docutils literal"><span class="pre">DistributionNotFound</span></code></dt>
<dd>A distribution needed to fulfill a requirement could not be found.</dd>
<dt><code class="docutils literal"><span class="pre">VersionConflict</span></code></dt>
<dd>The requested version of a project conflicts with an already-activated
version of the same project.</dd>
<dt><code class="docutils literal"><span class="pre">UnknownExtra</span></code></dt>
<dd>One of the “extras” requested was not recognized by the distribution it
was requested from.</dd>
<dt><code class="docutils literal"><span class="pre">ExtractionError</span></code></dt>
<dd><p class="first">A problem occurred extracting a resource to the Python Egg cache.  The
following attributes are available on instances of this exception:</p>
<dl class="last docutils">
<dt>manager</dt>
<dd>The resource manager that raised this exception</dd>
<dt>cache_path</dt>
<dd>The base directory for resource extraction</dd>
<dt>original_error</dt>
<dd>The exception instance that caused extraction to fail</dd>
</dl>
</dd>
</dl>
</div>
<div class="section" id="supporting-custom-importers">
<h3><a class="toc-backref" href="#id29">Supporting Custom Importers</a><a class="headerlink" href="#supporting-custom-importers" title="Permalink to this headline"></a></h3>
<p>By default, <code class="docutils literal"><span class="pre">pkg_resources</span></code> supports normal filesystem imports, and
<code class="docutils literal"><span class="pre">zipimport</span></code> importers.  If you wish to use the <code class="docutils literal"><span class="pre">pkg_resources</span></code> features
with other (PEP 302-compatible) importers or module loaders, you may need to
register various handlers and support functions using these APIs:</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">register_finder(importer_type,</span> <span class="pre">distribution_finder)</span></code></dt>
<dd><p class="first">Register <cite>distribution_finder</cite> to find distributions in <code class="docutils literal"><span class="pre">sys.path</span></code> items.
<cite>importer_type</cite> is the type or class of a PEP 302 “Importer” (<code class="docutils literal"><span class="pre">sys.path</span></code>
item handler), and <cite>distribution_finder</cite> is a callable that, when passed a
path item, the importer instance, and an <cite>only</cite> flag, yields
<code class="docutils literal"><span class="pre">Distribution</span></code> instances found under that path item.  (The <cite>only</cite> flag,
if true, means the finder should yield only <code class="docutils literal"><span class="pre">Distribution</span></code> objects whose
<code class="docutils literal"><span class="pre">location</span></code> is equal to the path item provided.)</p>
<p class="last">See the source of the <code class="docutils literal"><span class="pre">pkg_resources.find_on_path</span></code> function for an
example finder function.</p>
</dd>
<dt><code class="docutils literal"><span class="pre">register_loader_type(loader_type,</span> <span class="pre">provider_factory)</span></code></dt>
<dd>Register <cite>provider_factory</cite> to make <code class="docutils literal"><span class="pre">IResourceProvider</span></code> objects for
<cite>loader_type</cite>.  <cite>loader_type</cite> is the type or class of a PEP 302
<code class="docutils literal"><span class="pre">module.__loader__</span></code>, and <cite>provider_factory</cite> is a function that, when
passed a module object, returns an <a class="reference internal" href="#iresourceprovider">IResourceProvider</a> for that module,
allowing it to be used with the <a class="reference internal" href="#resourcemanager-api">ResourceManager API</a>.</dd>
<dt><code class="docutils literal"><span class="pre">register_namespace_handler(importer_type,</span> <span class="pre">namespace_handler)</span></code></dt>
<dd><p class="first">Register <cite>namespace_handler</cite> to declare namespace packages for the given
<cite>importer_type</cite>.  <cite>importer_type</cite> is the type or class of a PEP 302
“importer” (sys.path item handler), and <cite>namespace_handler</cite> is a callable
with a signature like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">namespace_handler</span><span class="p">(</span><span class="n">importer</span><span class="p">,</span> <span class="n">path_entry</span><span class="p">,</span> <span class="n">moduleName</span><span class="p">,</span> <span class="n">module</span><span class="p">):</span>
    <span class="c1"># return a path_entry to use for child packages</span>
</pre></div>
</div>
<p>Namespace handlers are only called if the relevant importer object has
already agreed that it can handle the relevant path item.  The handler
should only return a subpath if the module <code class="docutils literal"><span class="pre">__path__</span></code> does not already
contain an equivalent subpath.  Otherwise, it should return None.</p>
<p class="last">For an example namespace handler, see the source of the
<code class="docutils literal"><span class="pre">pkg_resources.file_ns_handler</span></code> function, which is used for both zipfile
importing and regular importing.</p>
</dd>
</dl>
<div class="section" id="iresourceprovider">
<h4><a class="toc-backref" href="#id30">IResourceProvider</a><a class="headerlink" href="#iresourceprovider" title="Permalink to this headline"></a></h4>
<p><code class="docutils literal"><span class="pre">IResourceProvider</span></code> is an abstract class that documents what methods are
required of objects returned by a <cite>provider_factory</cite> registered with
<code class="docutils literal"><span class="pre">register_loader_type()</span></code>.  <code class="docutils literal"><span class="pre">IResourceProvider</span></code> is a subclass of
<code class="docutils literal"><span class="pre">IMetadataProvider</span></code>, so objects that implement this interface must also
implement all of the <a class="reference internal" href="#imetadataprovider-methods">IMetadataProvider Methods</a> as well as the methods
shown here.  The <cite>manager</cite> argument to the methods below must be an object
that supports the full <a class="reference internal" href="#resourcemanager-api">ResourceManager API</a> documented above.</p>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">get_resource_filename(manager,</span> <span class="pre">resource_name)</span></code></dt>
<dd>Return a true filesystem path for <cite>resource_name</cite>, coordinating the
extraction with <cite>manager</cite>, if the resource must be unpacked to the
filesystem.</dd>
<dt><code class="docutils literal"><span class="pre">get_resource_stream(manager,</span> <span class="pre">resource_name)</span></code></dt>
<dd>Return a readable file-like object for <cite>resource_name</cite>.</dd>
<dt><code class="docutils literal"><span class="pre">get_resource_string(manager,</span> <span class="pre">resource_name)</span></code></dt>
<dd>Return a string containing the contents of <cite>resource_name</cite>.</dd>
<dt><code class="docutils literal"><span class="pre">has_resource(resource_name)</span></code></dt>
<dd>Does the package contain the named resource?</dd>
<dt><code class="docutils literal"><span class="pre">resource_isdir(resource_name)</span></code></dt>
<dd>Is the named resource a directory?  Return a false value if the resource
does not exist or is not a directory.</dd>
<dt><code class="docutils literal"><span class="pre">resource_listdir(resource_name)</span></code></dt>
<dd>Return a list of the contents of the resource directory, ala
<code class="docutils literal"><span class="pre">os.listdir()</span></code>.  Requesting the contents of a non-existent directory may
raise an exception.</dd>
</dl>
<p>Note, by the way, that your provider classes need not (and should not) subclass
<code class="docutils literal"><span class="pre">IResourceProvider</span></code> or <code class="docutils literal"><span class="pre">IMetadataProvider</span></code>!  These classes exist solely
for documentation purposes and do not provide any useful implementation code.
You may instead wish to subclass one of the <a class="reference internal" href="#built-in-resource-providers">built-in resource providers</a>.</p>
</div>
<div class="section" id="built-in-resource-providers">
<h4><a class="toc-backref" href="#id31">Built-in Resource Providers</a><a class="headerlink" href="#built-in-resource-providers" title="Permalink to this headline"></a></h4>
<p><code class="docutils literal"><span class="pre">pkg_resources</span></code> includes several provider classes that are automatically used
where appropriate.  Their inheritance tree looks like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">NullProvider</span>
    <span class="n">EggProvider</span>
        <span class="n">DefaultProvider</span>
            <span class="n">PathMetadata</span>
        <span class="n">ZipProvider</span>
            <span class="n">EggMetadata</span>
    <span class="n">EmptyProvider</span>
        <span class="n">FileMetadata</span>
</pre></div>
</div>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">NullProvider</span></code></dt>
<dd>This provider class is just an abstract base that provides for common
provider behaviors (such as running scripts), given a definition for just
a few abstract methods.</dd>
<dt><code class="docutils literal"><span class="pre">EggProvider</span></code></dt>
<dd>This provider class adds in some egg-specific features that are common
to zipped and unzipped eggs.</dd>
<dt><code class="docutils literal"><span class="pre">DefaultProvider</span></code></dt>
<dd>This provider class is used for unpacked eggs and “plain old Python”
filesystem modules.</dd>
<dt><code class="docutils literal"><span class="pre">ZipProvider</span></code></dt>
<dd>This provider class is used for all zipped modules, whether they are eggs
or not.</dd>
<dt><code class="docutils literal"><span class="pre">EmptyProvider</span></code></dt>
<dd>This provider class always returns answers consistent with a provider that
has no metadata or resources.  <code class="docutils literal"><span class="pre">Distribution</span></code> objects created without
a <code class="docutils literal"><span class="pre">metadata</span></code> argument use an instance of this provider class instead.
Since all <code class="docutils literal"><span class="pre">EmptyProvider</span></code> instances are equivalent, there is no need
to have more than one instance.  <code class="docutils literal"><span class="pre">pkg_resources</span></code> therefore creates a
global instance of this class under the name <code class="docutils literal"><span class="pre">empty_provider</span></code>, and you
may use it if you have need of an <code class="docutils literal"><span class="pre">EmptyProvider</span></code> instance.</dd>
<dt><code class="docutils literal"><span class="pre">PathMetadata(path,</span> <span class="pre">egg_info)</span></code></dt>
<dd>Create an <code class="docutils literal"><span class="pre">IResourceProvider</span></code> for a filesystem-based distribution, where
<cite>path</cite> is the filesystem location of the importable modules, and <cite>egg_info</cite>
is the filesystem location of the distribution’s metadata directory.
<cite>egg_info</cite> should usually be the <code class="docutils literal"><span class="pre">EGG-INFO</span></code> subdirectory of <cite>path</cite> for an
“unpacked egg”, and a <code class="docutils literal"><span class="pre">ProjectName.egg-info</span></code> subdirectory of <cite>path</cite> for
a “development egg”.  However, other uses are possible for custom purposes.</dd>
<dt><code class="docutils literal"><span class="pre">EggMetadata(zipimporter)</span></code></dt>
<dd>Create an <code class="docutils literal"><span class="pre">IResourceProvider</span></code> for a zipfile-based distribution.  The
<cite>zipimporter</cite> should be a <code class="docutils literal"><span class="pre">zipimport.zipimporter</span></code> instance, and may
represent a “basket” (a zipfile containing multiple “.egg” subdirectories)
a specific egg <em>within</em> a basket, or a zipfile egg (where the zipfile
itself is a “.egg”).  It can also be a combination, such as a zipfile egg
that also contains other eggs.</dd>
<dt><code class="docutils literal"><span class="pre">FileMetadata(path_to_pkg_info)</span></code></dt>
<dd>Create an <code class="docutils literal"><span class="pre">IResourceProvider</span></code> that provides exactly one metadata
resource: <code class="docutils literal"><span class="pre">PKG-INFO</span></code>.  The supplied path should be a distutils PKG-INFO
file.  This is basically the same as an <code class="docutils literal"><span class="pre">EmptyProvider</span></code>, except that
requests for <code class="docutils literal"><span class="pre">PKG-INFO</span></code> will be answered using the contents of the
designated file.  (This provider is used to wrap <code class="docutils literal"><span class="pre">.egg-info</span></code> files
installed by vendor-supplied system packages.)</dd>
</dl>
</div>
</div>
<div class="section" id="utility-functions">
<h3><a class="toc-backref" href="#id32">Utility Functions</a><a class="headerlink" href="#utility-functions" title="Permalink to this headline"></a></h3>
<p>In addition to its high-level APIs, <code class="docutils literal"><span class="pre">pkg_resources</span></code> also includes several
generally-useful utility routines.  These routines are used to implement the
high-level APIs, but can also be quite useful by themselves.</p>
<div class="section" id="parsing-utilities">
<h4><a class="toc-backref" href="#id33">Parsing Utilities</a><a class="headerlink" href="#parsing-utilities" title="Permalink to this headline"></a></h4>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">parse_version(version)</span></code></dt>
<dd>Parsed a project’s version string as defined by PEP 440. The returned
value will be an object that represents the version. These objects may
be compared to each other and sorted. The sorting algorithm is as defined
by PEP 440 with the addition that any version which is not a valid PEP 440
version will be considered less than any valid PEP 440 version and the
invalid versions will continue sorting using the original algorithm.</dd>
</dl>
<dl class="docutils" id="yield-lines">
<dt><code class="docutils literal"><span class="pre">yield_lines(strs)</span></code></dt>
<dd><p class="first">Yield non-empty/non-comment lines from a string/unicode or a possibly-
nested sequence thereof.  If <cite>strs</cite> is an instance of <code class="docutils literal"><span class="pre">basestring</span></code>, it
is split into lines, and each non-blank, non-comment line is yielded after
stripping leading and trailing whitespace.  (Lines whose first non-blank
character is <code class="docutils literal"><span class="pre">#</span></code> are considered comment lines.)</p>
<p>If <cite>strs</cite> is not an instance of <code class="docutils literal"><span class="pre">basestring</span></code>, it is iterated over, and
each item is passed recursively to <code class="docutils literal"><span class="pre">yield_lines()</span></code>, so that an arbitrarily
nested sequence of strings, or sequences of sequences of strings can be
flattened out to the lines contained therein.  So for example, passing
a file object or a list of strings to <code class="docutils literal"><span class="pre">yield_lines</span></code> will both work.
(Note that between each string in a sequence of strings there is assumed to
be an implicit line break, so lines cannot bridge two strings in a
sequence.)</p>
<p class="last">This routine is used extensively by <code class="docutils literal"><span class="pre">pkg_resources</span></code> to parse metadata
and file formats of various kinds, and most other <code class="docutils literal"><span class="pre">pkg_resources</span></code>
parsing functions that yield multiple values will use it to break up their
input.  However, this routine is idempotent, so calling <code class="docutils literal"><span class="pre">yield_lines()</span></code>
on the output of another call to <code class="docutils literal"><span class="pre">yield_lines()</span></code> is completely harmless.</p>
</dd>
<dt><code class="docutils literal"><span class="pre">split_sections(strs)</span></code></dt>
<dd><p class="first">Split a string (or possibly-nested iterable thereof), yielding <code class="docutils literal"><span class="pre">(section,</span>
<span class="pre">content)</span></code> pairs found using an <code class="docutils literal"><span class="pre">.ini</span></code>-like syntax.  Each <code class="docutils literal"><span class="pre">section</span></code> is
a whitespace-stripped version of the section name (“<code class="docutils literal"><span class="pre">[section]</span></code>”)
and each <code class="docutils literal"><span class="pre">content</span></code> is a list of stripped lines excluding blank lines and
comment-only lines.  If there are any non-blank, non-comment lines before
the first section header, they’re yielded in a first <code class="docutils literal"><span class="pre">section</span></code> of
<code class="docutils literal"><span class="pre">None</span></code>.</p>
<p>This routine uses <code class="docutils literal"><span class="pre">yield_lines()</span></code> as its front end, so you can pass in
anything that <code class="docutils literal"><span class="pre">yield_lines()</span></code> accepts, such as an open text file, string,
or sequence of strings.  <code class="docutils literal"><span class="pre">ValueError</span></code> is raised if a malformed section
header is found (i.e. a line starting with <code class="docutils literal"><span class="pre">[</span></code> but not ending with
<code class="docutils literal"><span class="pre">]</span></code>).</p>
<p class="last">Note that this simplistic parser assumes that any line whose first nonblank
character is <code class="docutils literal"><span class="pre">[</span></code> is a section heading, so it can’t support .ini format
variations that allow <code class="docutils literal"><span class="pre">[</span></code> as the first nonblank character on other lines.</p>
</dd>
<dt><code class="docutils literal"><span class="pre">safe_name(name)</span></code></dt>
<dd>Return a “safe” form of a project’s name, suitable for use in a
<code class="docutils literal"><span class="pre">Requirement</span></code> string, as a distribution name, or a PyPI project name.
All non-alphanumeric runs are condensed to single “-” characters, such that
a name like “The $$$ Tree” becomes “The-Tree”.  Note that if you are
generating a filename from this value you should combine it with a call to
<code class="docutils literal"><span class="pre">to_filename()</span></code> so all dashes (“-“) are replaced by underscores (“_”).
See <code class="docutils literal"><span class="pre">to_filename()</span></code>.</dd>
<dt><code class="docutils literal"><span class="pre">safe_version(version)</span></code></dt>
<dd>This will return the normalized form of any PEP 440 version, if the version
string is not PEP 440 compatible than it is similar to <code class="docutils literal"><span class="pre">safe_name()</span></code>
except that spaces in the input become dots, and dots are allowed to exist
in the output.  As with <code class="docutils literal"><span class="pre">safe_name()</span></code>, if you are generating a filename
from this you should replace any “-” characters in the output with
underscores.</dd>
<dt><code class="docutils literal"><span class="pre">safe_extra(extra)</span></code></dt>
<dd>Return a “safe” form of an extra’s name, suitable for use in a requirement
string or a setup script’s <code class="docutils literal"><span class="pre">extras_require</span></code> keyword.  This routine is
similar to <code class="docutils literal"><span class="pre">safe_name()</span></code> except that non-alphanumeric runs are replaced
by a single underbar (<code class="docutils literal"><span class="pre">_</span></code>), and the result is lowercased.</dd>
<dt><code class="docutils literal"><span class="pre">to_filename(name_or_version)</span></code></dt>
<dd>Escape a name or version string so it can be used in a dash-separated
filename (or <code class="docutils literal"><span class="pre">#egg=name-version</span></code> tag) without ambiguity.  You
should only pass in values that were returned by <code class="docutils literal"><span class="pre">safe_name()</span></code> or
<code class="docutils literal"><span class="pre">safe_version()</span></code>.</dd>
</dl>
</div>
<div class="section" id="platform-utilities">
<h4><a class="toc-backref" href="#id34">Platform Utilities</a><a class="headerlink" href="#platform-utilities" title="Permalink to this headline"></a></h4>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">get_build_platform()</span></code></dt>
<dd>Return this platform’s identifier string.  For Windows, the return value
is <code class="docutils literal"><span class="pre">&quot;win32&quot;</span></code>, and for Mac OS X it is a string of the form
<code class="docutils literal"><span class="pre">&quot;macosx-10.4-ppc&quot;</span></code>.  All other platforms return the same uname-based
string that the <code class="docutils literal"><span class="pre">distutils.util.get_platform()</span></code> function returns.
This string is the minimum platform version required by distributions built
on the local machine.  (Backward compatibility note: setuptools versions
prior to 0.6b1 called this function <code class="docutils literal"><span class="pre">get_platform()</span></code>, and the function is
still available under that name for backward compatibility reasons.)</dd>
<dt><code class="docutils literal"><span class="pre">get_supported_platform()</span></code> (New in 0.6b1)</dt>
<dd>This is the similar to <code class="docutils literal"><span class="pre">get_build_platform()</span></code>, but is the maximum
platform version that the local machine supports.  You will usually want
to use this value as the <code class="docutils literal"><span class="pre">provided</span></code> argument to the
<code class="docutils literal"><span class="pre">compatible_platforms()</span></code> function.</dd>
<dt><code class="docutils literal"><span class="pre">compatible_platforms(provided,</span> <span class="pre">required)</span></code></dt>
<dd>Return true if a distribution built on the <cite>provided</cite> platform may be used
on the <cite>required</cite> platform.  If either platform value is <code class="docutils literal"><span class="pre">None</span></code>, it is
considered a wildcard, and the platforms are therefore compatible.
Likewise, if the platform strings are equal, they’re also considered
compatible, and <code class="docutils literal"><span class="pre">True</span></code> is returned.  Currently, the only non-equal
platform strings that are considered compatible are Mac OS X platform
strings with the same hardware type (e.g. <code class="docutils literal"><span class="pre">ppc</span></code>) and major version
(e.g. <code class="docutils literal"><span class="pre">10</span></code>) with the <cite>provided</cite> platform’s minor version being less than
or equal to the <cite>required</cite> platform’s minor version.</dd>
<dt><code class="docutils literal"><span class="pre">get_default_cache()</span></code></dt>
<dd>Determine the default cache location for extracting resources from zipped
eggs.  This routine returns the <code class="docutils literal"><span class="pre">PYTHON_EGG_CACHE</span></code> environment variable,
if set.  Otherwise, on Windows, it returns a “Python-Eggs” subdirectory of
the user’s “Application Data” directory.  On all other systems, it returns
<code class="docutils literal"><span class="pre">os.path.expanduser(&quot;~/.python-eggs&quot;)</span></code> if <code class="docutils literal"><span class="pre">PYTHON_EGG_CACHE</span></code> is not
set.</dd>
</dl>
</div>
<div class="section" id="pep-302-utilities">
<h4><a class="toc-backref" href="#id35">PEP 302 Utilities</a><a class="headerlink" href="#pep-302-utilities" title="Permalink to this headline"></a></h4>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">get_importer(path_item)</span></code></dt>
<dd>A deprecated alias for <code class="docutils literal"><span class="pre">pkgutil.get_importer()</span></code></dd>
</dl>
</div>
<div class="section" id="file-path-utilities">
<h4><a class="toc-backref" href="#id36">File/Path Utilities</a><a class="headerlink" href="#file-path-utilities" title="Permalink to this headline"></a></h4>
<dl class="docutils">
<dt><code class="docutils literal"><span class="pre">ensure_directory(path)</span></code></dt>
<dd>Ensure that the parent directory (<code class="docutils literal"><span class="pre">os.path.dirname</span></code>) of <cite>path</cite> actually
exists, using <code class="docutils literal"><span class="pre">os.makedirs()</span></code> if necessary.</dd>
<dt><code class="docutils literal"><span class="pre">normalize_path(path)</span></code></dt>
<dd>Return a “normalized” version of <cite>path</cite>, such that two paths represent
the same filesystem location if they have equal <code class="docutils literal"><span class="pre">normalized_path()</span></code>
values.  Specifically, this is a shortcut for calling <code class="docutils literal"><span class="pre">os.path.realpath</span></code>
and <code class="docutils literal"><span class="pre">os.path.normcase</span></code> on <cite>path</cite>.  Unfortunately, on certain platforms
(notably Cygwin and Mac OS X) the <code class="docutils literal"><span class="pre">normcase</span></code> function does not accurately
reflect the platform’s case-sensitivity, so there is always the possibility
of two apparently-different paths being equal on such platforms.</dd>
</dl>
</div>
<div class="section" id="history">
<h4><a class="toc-backref" href="#id37">History</a><a class="headerlink" href="#history" title="Permalink to this headline"></a></h4>
<dl class="docutils">
<dt>0.6c9</dt>
<dd><ul class="first last simple">
<li>Fix <code class="docutils literal"><span class="pre">resource_listdir('')</span></code> always returning an empty list for zipped eggs.</li>
</ul>
</dd>
<dt>0.6c7</dt>
<dd><ul class="first last simple">
<li>Fix package precedence problem where single-version eggs installed in
<code class="docutils literal"><span class="pre">site-packages</span></code> would take precedence over <code class="docutils literal"><span class="pre">.egg</span></code> files (or directories)
installed in <code class="docutils literal"><span class="pre">site-packages</span></code>.</li>
</ul>
</dd>
<dt>0.6c6</dt>
<dd><ul class="first last simple">
<li>Fix extracted C extensions not having executable permissions under Cygwin.</li>
<li>Allow <code class="docutils literal"><span class="pre">.egg-link</span></code> files to contain relative paths.</li>
<li>Fix cache dir defaults on Windows when multiple environment vars are needed
to construct a path.</li>
</ul>
</dd>
<dt>0.6c4</dt>
<dd><ul class="first last simple">
<li>Fix “dev” versions being considered newer than release candidates.</li>
</ul>
</dd>
<dt>0.6c3</dt>
<dd><ul class="first last simple">
<li>Python 2.5 compatibility fixes.</li>
</ul>
</dd>
<dt>0.6c2</dt>
<dd><ul class="first last simple">
<li>Fix a problem with eggs specified directly on <code class="docutils literal"><span class="pre">PYTHONPATH</span></code> on
case-insensitive filesystems possibly not showing up in the default
working set, due to differing normalizations of <code class="docutils literal"><span class="pre">sys.path</span></code> entries.</li>
</ul>
</dd>
<dt>0.6b3</dt>
<dd><ul class="first last simple">
<li>Fixed a duplicate path insertion problem on case-insensitive filesystems.</li>
</ul>
</dd>
<dt>0.6b1</dt>
<dd><ul class="first last simple">
<li>Split <code class="docutils literal"><span class="pre">get_platform()</span></code> into <code class="docutils literal"><span class="pre">get_supported_platform()</span></code> and
<code class="docutils literal"><span class="pre">get_build_platform()</span></code> to work around a Mac versioning problem that caused
the behavior of <code class="docutils literal"><span class="pre">compatible_platforms()</span></code> to be platform specific.</li>
<li>Fix entry point parsing when a standalone module name has whitespace
between it and the extras.</li>
</ul>
</dd>
<dt>0.6a11</dt>
<dd><ul class="first last simple">
<li>Added <code class="docutils literal"><span class="pre">ExtractionError</span></code> and <code class="docutils literal"><span class="pre">ResourceManager.extraction_error()</span></code> so that
cache permission problems get a more user-friendly explanation of the
problem, and so that programs can catch and handle extraction errors if they
need to.</li>
</ul>
</dd>
<dt>0.6a10</dt>
<dd><ul class="first last simple">
<li>Added the <code class="docutils literal"><span class="pre">extras</span></code> attribute to <code class="docutils literal"><span class="pre">Distribution</span></code>, the <code class="docutils literal"><span class="pre">find_plugins()</span></code>
method to <code class="docutils literal"><span class="pre">WorkingSet</span></code>, and the <code class="docutils literal"><span class="pre">__add__()</span></code> and <code class="docutils literal"><span class="pre">__iadd__()</span></code> methods
to <code class="docutils literal"><span class="pre">Environment</span></code>.</li>
<li><code class="docutils literal"><span class="pre">safe_name()</span></code> now allows dots in project names.</li>
<li>There is a new <code class="docutils literal"><span class="pre">to_filename()</span></code> function that escapes project names and
versions for safe use in constructing egg filenames from a Distribution
object’s metadata.</li>
<li>Added <code class="docutils literal"><span class="pre">Distribution.clone()</span></code> method, and keyword argument support to other
<code class="docutils literal"><span class="pre">Distribution</span></code> constructors.</li>
<li>Added the <code class="docutils literal"><span class="pre">DEVELOP_DIST</span></code> precedence, and automatically assign it to
eggs using <code class="docutils literal"><span class="pre">.egg-info</span></code> format.</li>
</ul>
</dd>
<dt>0.6a9</dt>
<dd><ul class="first last simple">
<li>Don’t raise an error when an invalid (unfinished) distribution is found
unless absolutely necessary.  Warn about skipping invalid/unfinished eggs
when building an Environment.</li>
<li>Added support for <code class="docutils literal"><span class="pre">.egg-info</span></code> files or directories with version/platform
information embedded in the filename, so that system packagers have the
option of including <code class="docutils literal"><span class="pre">PKG-INFO</span></code> files to indicate the presence of a
system-installed egg, without needing to use <code class="docutils literal"><span class="pre">.egg</span></code> directories, zipfiles,
or <code class="docutils literal"><span class="pre">.pth</span></code> manipulation.</li>
<li>Changed <code class="docutils literal"><span class="pre">parse_version()</span></code> to remove dashes before pre-release tags, so
that <code class="docutils literal"><span class="pre">0.2-rc1</span></code> is considered an <em>older</em> version than <code class="docutils literal"><span class="pre">0.2</span></code>, and is equal
to <code class="docutils literal"><span class="pre">0.2rc1</span></code>.  The idea that a dash <em>always</em> meant a post-release version
was highly non-intuitive to setuptools users and Python developers, who
seem to want to use <code class="docutils literal"><span class="pre">-rc</span></code> version numbers a lot.</li>
</ul>
</dd>
<dt>0.6a8</dt>
<dd><ul class="first last simple">
<li>Fixed a problem with <code class="docutils literal"><span class="pre">WorkingSet.resolve()</span></code> that prevented version
conflicts from being detected at runtime.</li>
<li>Improved runtime conflict warning message to identify a line in the user’s
program, rather than flagging the <code class="docutils literal"><span class="pre">warn()</span></code> call in <code class="docutils literal"><span class="pre">pkg_resources</span></code>.</li>
<li>Avoid giving runtime conflict warnings for namespace packages, even if they
were declared by a different package than the one currently being activated.</li>
<li>Fix path insertion algorithm for case-insensitive filesystems.</li>
<li>Fixed a problem with nested namespace packages (e.g. <code class="docutils literal"><span class="pre">peak.util</span></code>) not
being set as an attribute of their parent package.</li>
</ul>
</dd>
<dt>0.6a6</dt>
<dd><ul class="first last simple">
<li>Activated distributions are now inserted in <code class="docutils literal"><span class="pre">sys.path</span></code> (and the working
set) just before the directory that contains them, instead of at the end.
This allows e.g. eggs in <code class="docutils literal"><span class="pre">site-packages</span></code> to override unmanaged modules in
the same location, and allows eggs found earlier on <code class="docutils literal"><span class="pre">sys.path</span></code> to override
ones found later.</li>
<li>When a distribution is activated, it now checks whether any contained
non-namespace modules have already been imported and issues a warning if
a conflicting module has already been imported.</li>
<li>Changed dependency processing so that it’s breadth-first, allowing a
depender’s preferences to override those of a dependee, to prevent conflicts
when a lower version is acceptable to the dependee, but not the depender.</li>
<li>Fixed a problem extracting zipped files on Windows, when the egg in question
has had changed contents but still has the same version number.</li>
</ul>
</dd>
<dt>0.6a4</dt>
<dd><ul class="first last simple">
<li>Fix a bug in <code class="docutils literal"><span class="pre">WorkingSet.resolve()</span></code> that was introduced in 0.6a3.</li>
</ul>
</dd>
<dt>0.6a3</dt>
<dd><ul class="first last simple">
<li>Added <code class="docutils literal"><span class="pre">safe_extra()</span></code> parsing utility routine, and use it for Requirement,
EntryPoint, and Distribution objects’ extras handling.</li>
</ul>
</dd>
<dt>0.6a1</dt>
<dd><ul class="first last simple">
<li>Enhanced performance of <code class="docutils literal"><span class="pre">require()</span></code> and related operations when all
requirements are already in the working set, and enhanced performance of
directory scanning for distributions.</li>
<li>Fixed some problems using <code class="docutils literal"><span class="pre">pkg_resources</span></code> w/PEP 302 loaders other than
<code class="docutils literal"><span class="pre">zipimport</span></code>, and the previously-broken “eager resource” support.</li>
<li>Fixed <code class="docutils literal"><span class="pre">pkg_resources.resource_exists()</span></code> not working correctly, along with
some other resource API bugs.</li>
<li>Many API changes and enhancements:<ul>
<li>Added <code class="docutils literal"><span class="pre">EntryPoint</span></code>, <code class="docutils literal"><span class="pre">get_entry_map</span></code>, <code class="docutils literal"><span class="pre">load_entry_point</span></code>, and
<code class="docutils literal"><span class="pre">get_entry_info</span></code> APIs for dynamic plugin discovery.</li>
<li><code class="docutils literal"><span class="pre">list_resources</span></code> is now <code class="docutils literal"><span class="pre">resource_listdir</span></code> (and it actually works)</li>
<li>Resource API functions like <code class="docutils literal"><span class="pre">resource_string()</span></code> that accepted a package
name and resource name, will now also accept a <code class="docutils literal"><span class="pre">Requirement</span></code> object in
place of the package name (to allow access to non-package data files in
an egg).</li>
<li><code class="docutils literal"><span class="pre">get_provider()</span></code> will now accept a <code class="docutils literal"><span class="pre">Requirement</span></code> instance or a module
name.  If it is given a <code class="docutils literal"><span class="pre">Requirement</span></code>, it will return a corresponding
<code class="docutils literal"><span class="pre">Distribution</span></code> (by calling <code class="docutils literal"><span class="pre">require()</span></code> if a suitable distribution
isn’t already in the working set), rather than returning a metadata and
resource provider for a specific module.  (The difference is in how
resource paths are interpreted; supplying a module name means resources
path will be module-relative, rather than relative to the distribution’s
root.)</li>
<li><code class="docutils literal"><span class="pre">Distribution</span></code> objects now implement the <code class="docutils literal"><span class="pre">IResourceProvider</span></code> and
<code class="docutils literal"><span class="pre">IMetadataProvider</span></code> interfaces, so you don’t need to reference the (no
longer available) <code class="docutils literal"><span class="pre">metadata</span></code> attribute to get at these interfaces.</li>
<li><code class="docutils literal"><span class="pre">Distribution</span></code> and <code class="docutils literal"><span class="pre">Requirement</span></code> both have a <code class="docutils literal"><span class="pre">project_name</span></code>
attribute for the project name they refer to.  (Previously these were
<code class="docutils literal"><span class="pre">name</span></code> and <code class="docutils literal"><span class="pre">distname</span></code> attributes.)</li>
<li>The <code class="docutils literal"><span class="pre">path</span></code> attribute of <code class="docutils literal"><span class="pre">Distribution</span></code> objects is now <code class="docutils literal"><span class="pre">location</span></code>,
because it isn’t necessarily a filesystem path (and hasn’t been for some
time now).  The <code class="docutils literal"><span class="pre">location</span></code> of <code class="docutils literal"><span class="pre">Distribution</span></code> objects in the filesystem
should always be normalized using <code class="docutils literal"><span class="pre">pkg_resources.normalize_path()</span></code>; all
of the setuptools and EasyInstall code that generates distributions from
the filesystem (including <code class="docutils literal"><span class="pre">Distribution.from_filename()</span></code>) ensure this
invariant, but if you use a more generic API like <code class="docutils literal"><span class="pre">Distribution()</span></code> or
<code class="docutils literal"><span class="pre">Distribution.from_location()</span></code> you should take care that you don’t
create a distribution with an un-normalized filesystem path.</li>
<li><code class="docutils literal"><span class="pre">Distribution</span></code> objects now have an <code class="docutils literal"><span class="pre">as_requirement()</span></code> method that
returns a <code class="docutils literal"><span class="pre">Requirement</span></code> for the distribution’s project name and version.</li>
<li>Distribution objects no longer have an <code class="docutils literal"><span class="pre">installed_on()</span></code> method, and the
<code class="docutils literal"><span class="pre">install_on()</span></code> method is now <code class="docutils literal"><span class="pre">activate()</span></code> (but may go away altogether
soon).  The <code class="docutils literal"><span class="pre">depends()</span></code> method has also been renamed to <code class="docutils literal"><span class="pre">requires()</span></code>,
and <code class="docutils literal"><span class="pre">InvalidOption</span></code> is now <code class="docutils literal"><span class="pre">UnknownExtra</span></code>.</li>
<li><code class="docutils literal"><span class="pre">find_distributions()</span></code> now takes an additional argument called <code class="docutils literal"><span class="pre">only</span></code>,
that tells it to only yield distributions whose location is the passed-in
path.  (It defaults to False, so that the default behavior is unchanged.)</li>
<li><code class="docutils literal"><span class="pre">AvailableDistributions</span></code> is now called <code class="docutils literal"><span class="pre">Environment</span></code>, and the
<code class="docutils literal"><span class="pre">get()</span></code>, <code class="docutils literal"><span class="pre">__len__()</span></code>, and <code class="docutils literal"><span class="pre">__contains__()</span></code> methods were removed,
because they weren’t particularly useful.  <code class="docutils literal"><span class="pre">__getitem__()</span></code> no longer
raises <code class="docutils literal"><span class="pre">KeyError</span></code>; it just returns an empty list if there are no
distributions for the named project.</li>
<li>The <code class="docutils literal"><span class="pre">resolve()</span></code> method of <code class="docutils literal"><span class="pre">Environment</span></code> is now a method of
<code class="docutils literal"><span class="pre">WorkingSet</span></code> instead, and the <code class="docutils literal"><span class="pre">best_match()</span></code> method now uses a working
set instead of a path list as its second argument.</li>
<li>There is a new <code class="docutils literal"><span class="pre">pkg_resources.add_activation_listener()</span></code> API that lets
you register a callback for notifications about distributions added to
<code class="docutils literal"><span class="pre">sys.path</span></code> (including the distributions already on it).  This is
basically a hook for extensible applications and frameworks to be able to
search for plugin metadata in distributions added at runtime.</li>
</ul>
</li>
</ul>
</dd>
<dt>0.5a13</dt>
<dd><ul class="first last simple">
<li>Fixed a bug in resource extraction from nested packages in a zipped egg.</li>
</ul>
</dd>
<dt>0.5a12</dt>
<dd><ul class="first last simple">
<li>Updated extraction/cache mechanism for zipped resources to avoid inter-
process and inter-thread races during extraction.  The default cache
location can now be set via the <code class="docutils literal"><span class="pre">PYTHON_EGGS_CACHE</span></code> environment variable,
and the default Windows cache is now a <code class="docutils literal"><span class="pre">Python-Eggs</span></code> subdirectory of the
current user’s “Application Data” directory, if the <code class="docutils literal"><span class="pre">PYTHON_EGGS_CACHE</span></code>
variable isn’t set.</li>
</ul>
</dd>
<dt>0.5a10</dt>
<dd><ul class="first last simple">
<li>Fix a problem with <code class="docutils literal"><span class="pre">pkg_resources</span></code> being confused by non-existent eggs on
<code class="docutils literal"><span class="pre">sys.path</span></code> (e.g. if a user deletes an egg without removing it from the
<code class="docutils literal"><span class="pre">easy-install.pth</span></code> file).</li>
<li>Fix a problem with “basket” support in <code class="docutils literal"><span class="pre">pkg_resources</span></code>, where egg-finding
never actually went inside <code class="docutils literal"><span class="pre">.egg</span></code> files.</li>
<li>Made <code class="docutils literal"><span class="pre">pkg_resources</span></code> import the module you request resources from, if it’s
not already imported.</li>
</ul>
</dd>
<dt>0.5a4</dt>
<dd><ul class="first last simple">
<li><code class="docutils literal"><span class="pre">pkg_resources.AvailableDistributions.resolve()</span></code> and related methods now
accept an <code class="docutils literal"><span class="pre">installer</span></code> argument: a callable taking one argument, a
<code class="docutils literal"><span class="pre">Requirement</span></code> instance.  The callable must return a <code class="docutils literal"><span class="pre">Distribution</span></code>
object, or <code class="docutils literal"><span class="pre">None</span></code> if no distribution is found.  This feature is used by
EasyInstall to resolve dependencies by recursively invoking itself.</li>
</ul>
</dd>
<dt>0.4a4</dt>
<dd><ul class="first last simple">
<li>Fix problems with <code class="docutils literal"><span class="pre">resource_listdir()</span></code>, <code class="docutils literal"><span class="pre">resource_isdir()</span></code> and resource
directory extraction for zipped eggs.</li>
</ul>
</dd>
<dt>0.4a3</dt>
<dd><ul class="first last simple">
<li>Fixed scripts not being able to see a <code class="docutils literal"><span class="pre">__file__</span></code> variable in <code class="docutils literal"><span class="pre">__main__</span></code></li>
<li>Fixed a problem with <code class="docutils literal"><span class="pre">resource_isdir()</span></code> implementation that was introduced
in 0.4a2.</li>
</ul>
</dd>
<dt>0.4a1</dt>
<dd><ul class="first last simple">
<li>Fixed a bug in requirements processing for exact versions (i.e. <code class="docutils literal"><span class="pre">==</span></code> and
<code class="docutils literal"><span class="pre">!=</span></code>) when only one condition was included.</li>
<li>Added <code class="docutils literal"><span class="pre">safe_name()</span></code> and <code class="docutils literal"><span class="pre">safe_version()</span></code> APIs to clean up handling of
arbitrary distribution names and versions found on PyPI.</li>
</ul>
</dd>
<dt>0.3a4</dt>
<dd><ul class="first last simple">
<li><code class="docutils literal"><span class="pre">pkg_resources</span></code> now supports resource directories, not just the resources
in them.  In particular, there are <code class="docutils literal"><span class="pre">resource_listdir()</span></code> and
<code class="docutils literal"><span class="pre">resource_isdir()</span></code> APIs.</li>
<li><code class="docutils literal"><span class="pre">pkg_resources</span></code> now supports “egg baskets” – .egg zipfiles which contain
multiple distributions in subdirectories whose names end with <code class="docutils literal"><span class="pre">.egg</span></code>.
Having such a “basket” in a directory on <code class="docutils literal"><span class="pre">sys.path</span></code> is equivalent to
having the individual eggs in that directory, but the contained eggs can
be individually added (or not) to <code class="docutils literal"><span class="pre">sys.path</span></code>.  Currently, however, there
is no automated way to create baskets.</li>
<li>Namespace package manipulation is now protected by the Python import lock.</li>
</ul>
</dd>
<dt>0.3a1</dt>
<dd><ul class="first last simple">
<li>Initial release.</li>
</ul>
</dd>
</dl>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Package Discovery and Resource Access using <code class="docutils literal"><span class="pre">pkg_resources</span></code></a><ul>
<li><a class="reference internal" href="#overview">Overview</a></li>
<li><a class="reference internal" href="#api-reference">API Reference</a><ul>
<li><a class="reference internal" href="#namespace-package-support">Namespace Package Support</a></li>
<li><a class="reference internal" href="#workingset-objects"><code class="docutils literal"><span class="pre">WorkingSet</span></code> Objects</a><ul>
<li><a class="reference internal" href="#basic-workingset-methods">Basic <code class="docutils literal"><span class="pre">WorkingSet</span></code> Methods</a></li>
<li><a class="reference internal" href="#workingset-methods-and-attributes"><code class="docutils literal"><span class="pre">WorkingSet</span></code> Methods and Attributes</a></li>
<li><a class="reference internal" href="#receiving-change-notifications">Receiving Change Notifications</a></li>
<li><a class="reference internal" href="#locating-plugins">Locating Plugins</a></li>
</ul>
</li>
<li><a class="reference internal" href="#environment-objects"><code class="docutils literal"><span class="pre">Environment</span></code> Objects</a></li>
<li><a class="reference internal" href="#requirement-objects"><code class="docutils literal"><span class="pre">Requirement</span></code> Objects</a><ul>
<li><a class="reference internal" href="#requirements-parsing">Requirements Parsing</a></li>
<li><a class="reference internal" href="#requirement-methods-and-attributes"><code class="docutils literal"><span class="pre">Requirement</span></code> Methods and Attributes</a></li>
</ul>
</li>
<li><a class="reference internal" href="#entry-points">Entry Points</a><ul>
<li><a class="reference internal" href="#convenience-api">Convenience API</a></li>
<li><a class="reference internal" href="#creating-and-parsing">Creating and Parsing</a></li>
<li><a class="reference internal" href="#entrypoint-objects"><code class="docutils literal"><span class="pre">EntryPoint</span></code> Objects</a></li>
</ul>
</li>
<li><a class="reference internal" href="#distribution-objects"><code class="docutils literal"><span class="pre">Distribution</span></code> Objects</a><ul>
<li><a class="reference internal" href="#getting-or-creating-distributions">Getting or Creating Distributions</a></li>
<li><a class="reference internal" href="#distribution-attributes"><code class="docutils literal"><span class="pre">Distribution</span></code> Attributes</a></li>
<li><a class="reference internal" href="#distribution-methods"><code class="docutils literal"><span class="pre">Distribution</span></code> Methods</a></li>
</ul>
</li>
<li><a class="reference internal" href="#resourcemanager-api"><code class="docutils literal"><span class="pre">ResourceManager</span></code> API</a><ul>
<li><a class="reference internal" href="#basic-resource-access">Basic Resource Access</a></li>
<li><a class="reference internal" href="#resource-extraction">Resource Extraction</a></li>
<li><a class="reference internal" href="#provider-interface">“Provider” Interface</a></li>
</ul>
</li>
<li><a class="reference internal" href="#metadata-api">Metadata API</a><ul>
<li><a class="reference internal" href="#imetadataprovider-methods"><code class="docutils literal"><span class="pre">IMetadataProvider</span></code> Methods</a></li>
</ul>
</li>
<li><a class="reference internal" href="#exceptions">Exceptions</a></li>
<li><a class="reference internal" href="#supporting-custom-importers">Supporting Custom Importers</a><ul>
<li><a class="reference internal" href="#iresourceprovider">IResourceProvider</a></li>
<li><a class="reference internal" href="#built-in-resource-providers">Built-in Resource Providers</a></li>
</ul>
</li>
<li><a class="reference internal" href="#utility-functions">Utility Functions</a><ul>
<li><a class="reference internal" href="#parsing-utilities">Parsing Utilities</a></li>
<li><a class="reference internal" href="#platform-utilities">Platform Utilities</a></li>
<li><a class="reference internal" href="#pep-302-utilities">PEP 302 Utilities</a></li>
<li><a class="reference internal" href="#file-path-utilities">File/Path Utilities</a></li>
<li><a class="reference internal" href="#history">History</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="easy_install.html"
                        title="previous chapter">Easy Install</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="python3.html"
                        title="next chapter">Supporting both Python 2 and Python 3 with Setuptools</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/pkg_resources.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="python3.html" title="Supporting both Python 2 and Python 3 with Setuptools"
             >next</a></li>
        <li class="right" >
          <a href="easy_install.html" title="Easy Install"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Python  documentation</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright .
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.7.
    </div>
  </body>
</html>