Permalink
Browse files

add pdistreport command

  • Loading branch information...
1 parent 49f7c34 commit b210ce350a3856166376f63a32725cc1516ba294 @mcdonc mcdonc committed Aug 2, 2013
Showing with 144 additions and 0 deletions.
  1. +4 −0 CHANGES.txt
  2. +24 −0 docs/narr/commandline.rst
  3. +4 −0 docs/whatsnew-1.5.rst
  4. +37 −0 pyramid/scripts/pdistreport.py
  5. +74 −0 pyramid/tests/test_scripts/test_pdistreport.py
  6. +1 −0 setup.py
View
4 CHANGES.txt
@@ -4,6 +4,10 @@ Next Release
Features
--------
+- Add ``pdistreport`` script, which prints the Python version in use, the
+ Pyramid version in use, and the version number and location of all Python
+ distributions currently installed.
+
- Add the ability to invert the result of any view, route, or subscriber
predicate using the ``not_`` class. For example::
View
24 docs/narr/commandline.rst
@@ -474,6 +474,30 @@ input of the ``prequest`` process is used as the ``POST`` body::
$ $VENV/bin/prequest -mPOST development.ini / < somefile
+Showing All Installed Distributions and their Versions
+------------------------------------------------------
+
+.. versionadded:: 1.5
+
+You can use the ``pdistreport`` command to show the Pyramid version in use, the
+Python version in use, and all installed versions of Python distributions in
+your Python environment::
+
+ $ $VENV/bin/pdistreport
+ Pyramid version: 1.5dev
+ Platform Linux-3.2.0-51-generic-x86_64-with-debian-wheezy-sid
+ Packages:
+ authapp 0.0
+ /home/chrism/projects/foo/src/authapp
+ beautifulsoup4 4.1.3
+ /home/chrism/projects/foo/lib/python2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg
+ ... more output ...
+
+``pdistreport`` takes no options. Its output is useful to paste into a
+pastebin when you are having problems and need someone with more familiarity
+with Python packaging and distribution than you have to look at your
+environment.
+
.. _writing_a_script:
Writing a Script
View
4 docs/whatsnew-1.5.rst
@@ -12,6 +12,10 @@ Feature Additions
The feature additions in Pyramid 1.5 follow.
+- Add ``pdistreport`` script, which prints the Python version in use, the
+ Pyramid version in use, and the version number and location of all Python
+ distributions currently installed.
+
- Add the ability to invert the result of any view, route, or subscriber
predicate value using the ``not_`` class. For example:
View
37 pyramid/scripts/pdistreport.py
@@ -0,0 +1,37 @@
+import sys
+import platform
+import pkg_resources
+import optparse
+from operator import itemgetter
+
+def out(*args): # pragma: no cover
+ for arg in args:
+ sys.stdout.write(arg)
+ sys.stdout.write(' ')
+ sys.stdout.write('\n')
+
+def main(argv=sys.argv, pkg_resources=pkg_resources, platform=platform.platform,
+ out=out):
+ # all args except argv are for unit testing purposes only
+ description = "Show Python distribution versions and locations in use"
+ usage = "usage: %prog"
+ parser = optparse.OptionParser(usage, description=description)
+ parser.parse_args(argv[1:])
+ packages = []
+ for distribution in pkg_resources.working_set:
+ name = distribution.project_name
+ packages.append(
+ {'version': distribution.version,
+ 'lowername': name.lower(),
+ 'name': name,
+ 'location':distribution.location}
+ )
+ packages = sorted(packages, key=itemgetter('lowername'))
+ pyramid_version = pkg_resources.get_distribution('pyramid').version
+ plat = platform()
+ out('Pyramid version:', pyramid_version)
+ out('Platform:', plat)
+ out('Packages:')
+ for package in packages:
+ out(' ', package['name'], package['version'])
+ out(' ', package['location'])
View
74 pyramid/tests/test_scripts/test_pdistreport.py
@@ -0,0 +1,74 @@
+import unittest
+from pyramid.tests.test_scripts import dummy
+
+class TestPDistReportCommand(unittest.TestCase):
+ def _callFUT(self, **kw):
+ argv = []
+ from pyramid.scripts.pdistreport import main
+ return main(argv, **kw)
+
+ def test_no_dists(self):
+ def platform():
+ return 'myplatform'
+ pkg_resources = DummyPkgResources()
+ L = []
+ def out(*args):
+ L.extend(args)
+ result = self._callFUT(pkg_resources=pkg_resources, platform=platform,
+ out=out)
+ self.assertEqual(result, None)
+ self.assertEqual(
+ L,
+ ['Pyramid version:', '1',
+ 'Platform:', 'myplatform',
+ 'Packages:']
+ )
+
+ def test_with_dists(self):
+ def platform():
+ return 'myplatform'
+ working_set = (DummyDistribution('abc'), DummyDistribution('def'))
+ pkg_resources = DummyPkgResources(working_set)
+ L = []
+ def out(*args):
+ L.extend(args)
+ result = self._callFUT(pkg_resources=pkg_resources, platform=platform,
+ out=out)
+ self.assertEqual(result, None)
+ self.assertEqual(
+ L,
+ ['Pyramid version:',
+ '1',
+ 'Platform:',
+ 'myplatform',
+ 'Packages:',
+ ' ',
+ 'abc',
+ '1',
+ ' ',
+ '/projects/abc',
+ ' ',
+ 'def',
+ '1',
+ ' ',
+ '/projects/def']
+ )
+
+class DummyPkgResources(object):
+ def __init__(self, working_set=()):
+ self.working_set = working_set
+
+ def get_distribution(self, name):
+ return Version('1')
+
+class Version(object):
+ def __init__(self, version):
+ self.version = version
+
+class DummyDistribution(object):
+ def __init__(self, name):
+ self.project_name = name
+ self.version = '1'
+ self.location = '/projects/%s' % name
+
+
View
1 setup.py
@@ -118,6 +118,7 @@
pviews = pyramid.scripts.pviews:main
ptweens = pyramid.scripts.ptweens:main
prequest = pyramid.scripts.prequest:main
+ pdistreport = pyramid.scripts.pdistreport:main
[paste.server_runner]
wsgiref = pyramid.scripts.pserve:wsgiref_server_runner
cherrypy = pyramid.scripts.pserve:cherrypy_server_runner

0 comments on commit b210ce3

Please sign in to comment.