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:-
name
¶ The package’s name.
-
version
¶ The package’s current version.
-
as_req
¶ The string that represents the parsed requirement.
-
requires
¶ This distribution’s requirements (including extras).
-
location
¶ The distribution’s metadata location.
-
files
¶ All the files parsed by this distribution.
-
has_metadata
¶ This attribute is True when the distribution has some metadata, False otherwise.
-
pkg_info
¶ Returns PKG-INFO’s data. Equivalent to
Dist.file('PKG-INFO')
.
-
zip_safe
¶ False whether the package has a
not-zip-safe
file, True otherwise.
-
file
(name)¶ Returns the content of the specified file. Raises
KeyError
when the distribution does not have such file.
-
entry_points_map
(group)¶ 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'] 'pyg' >>> e.name 'pyg' >>> e.version '0.4' >>> e.as_req 'pyg==0.4' >>> 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'] '1.1' >>> s.as_req() 'pyg==0.4'
-
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') ['AUTHORS', 'CHANGES', 'LICENSE', 'MANIFEST.in', 'README', 'TODO', 'setup.py', 'docs/Makefile', 'docs/conf.py', '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/__init__.py', 'pkgtools/__init__.pyc', 'pkgtools/pkg.py', 'pkgtools/pkg.pyc', 'pkgtools/pypi.py', 'pkgtools/pypi.pyc', 'pkgtools/utils.py', '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') ['argh'] >>> 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']
-
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() 'pypol-==0.5' >>> d.pkg_info {'Name': 'pypol-', 'License': 'GNU GPL v3', 'Author': 'Michele Lacchia', 'Metadata-Version': '1.0', 'Home-page': 'http://pypol.altervista.org/', 'Summary': 'Python polynomial library', 'Platform': 'any', 'Version': '0.5', 'Download-URL': 'http://github.com/rubik/pypol/downloads/', 'Classifier': 'Programming Language :: Python :: 2.7', 'Author-email': 'michelelacchia@gmail.com', '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() 'pkgtools==0.3.1' >>> ed.file('entry_points.txt') Traceback (most recent call last): File "<pyshell#7>", line 1, in <module> ed.file('entry_points.txt') File "/usr/local/lib/python2.7/dist-packages/pkgtools-0.3.1-py2.7.egg/pkgtools/pkg.py", 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 False