[Checkins] SVN: van.pydeb/trunk/ Expose version and package name conversion functions via the command line interface.
Brian Sutherland
jinty at web.de
Fri May 29 13:11:35 EDT 2009
Log message for revision 100537:
Expose version and package name conversion functions via the command line interface.
e.g. This command will print out the debian binary package name::
$ van-pydeb py_to_bin foo
Changed:
U van.pydeb/trunk/CHANGES.txt
U van.pydeb/trunk/van/pydeb/__init__.py
U van.pydeb/trunk/van/pydeb/tests/__init__.py
U van.pydeb/trunk/van/pydeb/tests/extras.txt
U van.pydeb/trunk/van/pydeb/tests/translations.txt
U van.pydeb/trunk/van/pydeb/tests/version.txt
-=-
Modified: van.pydeb/trunk/CHANGES.txt
===================================================================
--- van.pydeb/trunk/CHANGES.txt 2009-05-29 16:21:19 UTC (rev 100536)
+++ van.pydeb/trunk/CHANGES.txt 2009-05-29 17:11:35 UTC (rev 100537)
@@ -6,7 +6,11 @@
* Improve README.txt. Thanks to Fabio Tranchitella for a better looking way of
calling van-pydeb in the rules file.
+* Expose version and package name conversion functions via the command line interface.
+ e.g. This command will print out the debian binary package name::
+ $ van-pydeb py_to_bin foo
+
1.1.0 (2009-05-26)
------------------
Modified: van.pydeb/trunk/van/pydeb/__init__.py
===================================================================
--- van.pydeb/trunk/van/pydeb/__init__.py 2009-05-29 16:21:19 UTC (rev 100536)
+++ van.pydeb/trunk/van/pydeb/__init__.py 2009-05-29 17:11:35 UTC (rev 100537)
@@ -19,7 +19,22 @@
from pkg_resources import component_re # Is this a public interface?
_HERE = os.path.dirname(__file__)
+
#
+# Command Line Interface
+#
+
+_COMMANDS = {}
+
+def main(argv=sys.argv):
+ # Handle global options and dispatch the command
+ assert len(argv) >= 2, "You need to specify a command"
+ command = _COMMANDS.get(argv[1])
+ if command is None:
+ raise Exception("No Command: %s" % argv[1])
+ return command(argv)
+
+#
# Package name conversion
#
@@ -65,6 +80,21 @@
"""Convert a debian source package name to a setuptools project name"""
return _SRC_TO_PY.get(source_package, source_package)
+def _string_command(argv):
+ command = argv[1]
+ parser = optparse.OptionParser(usage="usage: %%prog %s argument" % command)
+ options, args = parser.parse_args(argv)
+ assert len(argv) == 3, "Too many or few arguments"
+ print {'py_to_src': py_to_src,
+ 'py_to_bin': py_to_bin,
+ 'bin_to_py': bin_to_py,
+ 'src_to_py': src_to_py,
+ 'py_version_to_deb': py_version_to_deb}[command](argv[2])
+ return 0
+_COMMANDS['py_to_src'] = _COMMANDS['py_to_bin'] = _string_command
+_COMMANDS['src_to_py'] = _COMMANDS['bin_to_py'] = _string_command
+_COMMANDS['py_version_to_deb'] = _string_command
+
#
# Version Conversion
#
@@ -113,7 +143,7 @@
'!=': None, # != not supported by debian, use conflicts in future for this
'<=': '<='}
-def main(argv=sys.argv):
+def _depends_or_provides(argv):
"""Run the dependency calculation program.
>>> import os
@@ -144,6 +174,7 @@
else:
raise Exception("Unknown command: %s" % command)
return 0
+_COMMANDS['depends'] = _COMMANDS['provides'] = _depends_or_provides
def _get_debian_provides(file, extras=None, exclude_extras=None):
# get provides for extras
Modified: van.pydeb/trunk/van/pydeb/tests/__init__.py
===================================================================
--- van.pydeb/trunk/van/pydeb/tests/__init__.py 2009-05-29 16:21:19 UTC (rev 100536)
+++ van.pydeb/trunk/van/pydeb/tests/__init__.py 2009-05-29 17:11:35 UTC (rev 100537)
@@ -1 +1,9 @@
# import
+
+from van.pydeb import main
+
+def runit(string):
+ "Test run a command"
+ exitcode = main(string.split())
+ if exitcode != 0:
+ return exitcode
Modified: van.pydeb/trunk/van/pydeb/tests/extras.txt
===================================================================
--- van.pydeb/trunk/van/pydeb/tests/extras.txt 2009-05-29 16:21:19 UTC (rev 100536)
+++ van.pydeb/trunk/van/pydeb/tests/extras.txt 2009-05-29 17:11:35 UTC (rev 100537)
@@ -5,27 +5,25 @@
-----
>>> import os
- >>> from van.pydeb import tests, main
+ >>> from van.pydeb import tests
+ >>> from van.pydeb.tests import runit
>>> here = os.path.dirname(tests.__file__)
>>> zope_component = os.path.join(here, 'zope.component.egg-info')
>>> zope_security = os.path.join(here, 'zope.security.egg-info')
>>> zope_app_publication = os.path.join(here, 'zope.app.publication.egg-info')
- >>> def runit(string):
- ... main(['bin'] + string.split())
-
The basic case: package depends directly on all extra dependencies
------------------------------------------------------------------
zope.component has a 'zcml' extra, we should check that by the the dependencies
of this extra are shown in the depends and provides line:
- >>> runit('depends --egg-info %s' % zope_component)
+ >>> runit('van-pydeb depends --egg-info %s' % zope_component)
python-setuptools, python-z3c.recipe.sphinxdoc, python-zodb, python-zope, python-zope.configuration, python-zope.event, python-zope.hookable, python-zope.i18nmessageid, python-zope.interface, python-zope.location, python-zope.proxy, python-zope.security, python-zope.testing
We can have create a provides line for all extras:
- >>> runit('provides --egg-info %s' % zope_component)
+ >>> runit('van-pydeb provides --egg-info %s' % zope_component)
python-zope.component-docs, python-zope.component-hook, python-zope.component-persistentregistry, python-zope.component-test, python-zope.component-zcml
Moving an extra's dependencies into "Suggests:"
@@ -34,12 +32,12 @@
We notice that the "docs" dependency us not a hard one and decide to exclude it
(it goes into Suggests:):
- >>> runit('depends --egg-info %s --exclude-extra docs' % zope_component)
+ >>> runit('van-pydeb depends --egg-info %s --exclude-extra docs' % zope_component)
python-setuptools, python-zodb, python-zope, python-zope.configuration, python-zope.event, python-zope.hookable, python-zope.i18nmessageid, python-zope.interface, python-zope.location, python-zope.proxy, python-zope.security, python-zope.testing
We could also exclude it from the "provides" list:
- >>> runit('provides --egg-info %s --exclude-extra docs' % zope_component)
+ >>> runit('van-pydeb provides --egg-info %s --exclude-extra docs' % zope_component)
python-zope.component-hook, python-zope.component-persistentregistry, python-zope.component-test, python-zope.component-zcml
Moving an extra into a metapackage
@@ -47,19 +45,19 @@
Now we decide to move the 'zcml' extra to it's own metapackage, thus we need to separate out it's dependencies:
- >>> runit('depends --egg-info %s --exclude-extra docs --exclude-extra zcml' % zope_component)
+ >>> runit('van-pydeb depends --egg-info %s --exclude-extra docs --exclude-extra zcml' % zope_component)
python-setuptools, python-zodb, python-zope, python-zope.event, python-zope.hookable, python-zope.interface, python-zope.location, python-zope.testing
- >>> runit('depends --egg-info %s --extra zcml' % zope_component)
+ >>> runit('van-pydeb depends --egg-info %s --extra zcml' % zope_component)
python-zope.configuration, python-zope.i18nmessageid, python-zope.proxy, python-zope.security
We could also have the docs extra included in the metapackage if we wanted:
- >>> runit('depends --egg-info %s --extra zcml --extra docs' % zope_component)
+ >>> runit('van-pydeb depends --egg-info %s --extra zcml --extra docs' % zope_component)
python-z3c.recipe.sphinxdoc, python-zope.configuration, python-zope.i18nmessageid, python-zope.proxy, python-zope.security
And make a "Provides" list for that:
- >>> runit('provides --egg-info %s --extra docs --extra zcml' % zope_component)
+ >>> runit('van-pydeb provides --egg-info %s --extra docs --extra zcml' % zope_component)
python-zope.component-docs, python-zope.component-zcml
Packages that depend on extras
@@ -67,10 +65,10 @@
Depend on the provides list:
- >>> runit('depends --egg-info %s' % zope_app_publication) # doctest: +ELLIPSIS
+ >>> runit('van-pydeb depends --egg-info %s' % zope_app_publication) # doctest: +ELLIPSIS
python-..., python-zope.component-zcml, ...
But packages that don't, get the original dependency:
- >>> runit('depends --egg-info %s' % zope_security) # doctest: +ELLIPSIS
+ >>> runit('van-pydeb depends --egg-info %s' % zope_security) # doctest: +ELLIPSIS
python-..., python-zope.component, ...
Modified: van.pydeb/trunk/van/pydeb/tests/translations.txt
===================================================================
--- van.pydeb/trunk/van/pydeb/tests/translations.txt 2009-05-29 16:21:19 UTC (rev 100536)
+++ van.pydeb/trunk/van/pydeb/tests/translations.txt 2009-05-29 17:11:35 UTC (rev 100537)
@@ -1,9 +1,33 @@
Test various builtin translations
=================================
-
>>> from van import pydeb
+ >>> from van.pydeb.tests import runit
+We can translate package names between setuptools names and debian
+source/binary names using the python API. By default package names convert as
+follows:
+
+ >>> print pydeb.py_to_bin("foo")
+ python-foo
+ >>> print pydeb.py_to_src("foo")
+ foo
+ >>> print pydeb.bin_to_py("python-foo")
+ foo
+ >>> print pydeb.src_to_py("foo")
+ foo
+
+These conversions are also exposed in the command line interface:
+
+ >>> runit('van-pydeb py_to_bin foo')
+ python-foo
+ >>> runit('van-pydeb py_to_src foo')
+ foo
+ >>> runit('van-pydeb bin_to_py python-foo')
+ foo
+ >>> runit('van-pydeb src_to_py foo')
+ foo
+
Paste
-----
@@ -17,6 +41,8 @@
ZODB3
-----
+ZODB3 doesn't follow convention:
+
>>> print pydeb.py_to_bin("ZODB3")
python-zodb
>>> print pydeb.py_to_src("ZODB3")
Modified: van.pydeb/trunk/van/pydeb/tests/version.txt
===================================================================
--- van.pydeb/trunk/van/pydeb/tests/version.txt 2009-05-29 16:21:19 UTC (rev 100536)
+++ van.pydeb/trunk/van/pydeb/tests/version.txt 2009-05-29 17:11:35 UTC (rev 100537)
@@ -1,11 +1,37 @@
-Test conversion between setuptools and debian version numbers
+Setup
+-----
-Setup a testing function:
-
+ >>> from van.pydeb.tests import runit
>>> from van.pydeb import py_version_to_deb
>>> from pkg_resources import parse_version
>>> from subprocess import call
+Python API
+----------
+
+ >>> py_version_to_deb('2.8.0')
+ '2.8.0'
+ >>> py_version_to_deb('2.8.0pre1')
+ '2.8.0~c~pre1'
+
+Command Line Interface
+----------------------
+
+Version comparison is also exposed via the command line interface, which prints
+out the result on stdout.
+
+ >>> runit('van-pydeb py_version_to_deb 2.8.0')
+ 2.8.0
+ >>> runit('van-pydeb py_version_to_deb 2.8.0pre1')
+ 2.8.0~c~pre1
+
+Sort Order
+----------
+
+Test conversion between setuptools and debian version numbers
+
+Setup a testing function:
+
>>> def dpkg_is_gt(v1, v2):
... return call(['dpkg', '--compare-versions', v1, '>>', v2]) == 0
>>> def test_gt(v1, v2):
More information about the Checkins
mailing list