pkgtools.pkg: Package Utilities

class pkgtools.pkg.Dist(file_objects)

This is the base class for all other objects. It requires a list of tuples ((file_data, file_name)) and provides some attributes/methods:


The package’s name.


The package’s current version.


The string that represents the parsed requirement.


This distribution’s requirements (including extras).


The distribution’s metadata location.


All the files parsed by this distribution.


This attribute is True when the distribution has some metadata, False otherwise.


Returns PKG-INFO’s data. Equivalent to Dist.file('PKG-INFO').


False whether the package has a not-zip-safe file, True otherwise.


Returns the content of the specified file. Raises KeyError when the distribution does not have such file.


Returns the elements under the specified section in the entry_points.txt file.

class pkgtools.pkg.Egg(egg_path)

Given the egg path, returns a Dist object:

>>> e = Egg('pyg-0.4-py2.7.egg')
>>> e
<Egg[pyg-0.4-py2.7.egg] object at 157366028>
>>> e.files()
['top_level.txt', 'requires.txt', 'PKG-INFO', 'entry_points.txt', 'SOURCES.txt']
>>> e.file('requires.txt')
['setuptools', 'pkgtools>=0.3.1', 'argh>=0.14']
>>> e.pkg_info['Name']
>>> e.version
>>> e.as_req
>>> e.entry_points_map('console_scripts')
{'pyg': 'pyg:main'}
>>> e.file('entry_points.txt')
{'console_scripts': {'pyg': 'pyg:main'}}
class pkgtools.pkg.SDist(sdist_path)

Given the source distribution path, returns a Dist object:

>>> s = SDist('pyg-0.4.tar.gz')
>>> s
<SDist[pyg-0.4.tar.gz] object at 157425036>
>>> s.files()
['top_level.txt', 'requires.txt', 'PKG-INFO', 'entry_points.txt', 'SOURCES.txt']
>>> s.pkg_info['Metadata-Version']
>>> s.as_req()
class pkgtools.pkg.Develop(package)

This class accepts either a string or a module object. Returns a Dist object:

>>> d = Develop('pkgtools')
>>> d
<Develop[pkgtools] object at 158833324>
>>> d.files()
['top_level.txt', 'dependency_links.txt', 'PKG-INFO', 'SOURCES.txt']
>>> d.file('SOURCES.txt')
'docs/Makefile', 'docs/', 'docs/index.rst', 'docs/make.bat', 'docs/pkg.rst',
'docs/pypi.rst', 'docs/_themes/pyg/theme.conf', 'docs/_themes/pyg/static/pyg.css_t',
'pkgtools/', 'pkgtools/__init__.pyc', 'pkgtools/', 'pkgtools/pkg.pyc',
'pkgtools/', 'pkgtools/pypi.pyc', 'pkgtools/', 'pkgtools/utils.pyc',
'pkgtools.egg-info/PKG-INFO', 'pkgtools.egg-info/SOURCES.txt',
'pkgtools.egg-info/dependency_links.txt', 'pkgtools.egg-info/top_level.txt']
>>> import pyg
>>> d = Develop(pyg)
>>> d
<Develop[/home/3jkldfi84r2hj/pyg/pyg.egg-info] object at 175354540>
>>> d.files()
['requires.txt', 'PKG-INFO', 'SOURCES.txt', 'top_level.txt', 'dependency_links.txt', 'entry_points.txt']
class pkgtools.pkg.Installed(package)

This class accepts either a string or a module object and returns a Dist object:

>>> i = Installed('argh')
>>> i
<Installed[argh] object at 158358348>
>>> i.files()
['top_level.txt', 'dependency_links.txt', 'PKG-INFO', 'SOURCES.txt']
>>> i.file('top_level.txt')
>>> import argh
>>> i = Installed(argh)
>>> i
<Installed[/usr/local/lib/python2.7/dist-packages/argh-0.14.0-py2.7.egg-info] object at 175527500>
>>> i.files()
['top_level.txt', 'dependency_links.txt', 'PKG-INFO', 'SOURCES.txt']

New in version 0.7.

Returns the installed files of this distribution. It returns a dictionary, with these keys:

  • lib: files placed into the site/dist-packages directory.
  • bin: Python executable file names


>>> i = Installed('pyg')
>>> files = i.installed_files()
>>> files['lib']
>>> files['bin']
set(['pyg2.7', 'pyg'])
class pkgtools.pkg.Dir(path)

Given a path containing the metadata files, returns a Dist object:

>>> d = Dir('/usr/local/lib/python2.7/dist-packages/pypol_-0.5.egg-info')
>>> d
<Dir[/usr/local/lib/python2.7/dist-packages/pypol_-0.5.egg-info] object at 157419436>
>>> d.as_req()
>>> d.pkg_info
{'Name': 'pypol-', 'License': 'GNU GPL v3',
'Author': 'Michele Lacchia', 'Metadata-Version': '1.0',
'Home-page': '',
'Summary': 'Python polynomial library', 'Platform': 'any',
'Version': '0.5', 'Download-URL': '',
'Classifier': 'Programming Language :: Python :: 2.7',
'Author-email': '', 'Description': 'UNKNOWN'
class pkgtools.pkg.EggDir(path)

Given a directory path which contains an EGG-INFO dir, returns a Dist object:

>>> ed = EggDir('/usr/local/lib/python2.7/dist-packages/pkgtools-0.3.1-py2.7.egg')
>>> ed
<EggDir[/usr/local/lib/python2.7/dist-packages/pkgtools-0.3.1-py2.7.egg/EGG-INFO] object at 145505740>
>>> ed.files()
['top_level.txt', 'PKG-INFO', 'SOURCES.txt']
>>> ed.pkg_info['Summary']
'Python Packages Tools'
>>> ed.as_req()
>>> ed.file('entry_points.txt')
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pkgtools-0.3.1-py2.7.egg/pkgtools/", line 140, in file
    raise KeyError('This package does not have {0} file'.format(name))
KeyError: 'This package does not have entry_points.txt file'
>>> ed.zip_safe

This Page