Skip to content

Commit

Permalink
add pdistreport command
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdonc committed Aug 2, 2013
1 parent 49f7c34 commit b210ce3
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down
24 changes: 24 additions & 0 deletions docs/narr/commandline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docs/whatsnew-1.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
37 changes: 37 additions & 0 deletions pyramid/scripts/pdistreport.py
Original file line number Diff line number Diff line change
@@ -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'])
74 changes: 74 additions & 0 deletions pyramid/tests/test_scripts/test_pdistreport.py
Original file line number Diff line number Diff line change
@@ -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


1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b210ce3

Please sign in to comment.