Commit 93656a11 authored by Stefano Rivera's avatar Stefano Rivera

Import objgraph_3.0.0.orig.tar.gz

parent b0bec11e
language: python
sudo: required
sudo: false
python:
- 2.6
- 2.7
- 3.2
- 3.3
- 3.4
- 3.5
addons:
apt:
packages:
- graphviz
install:
- sudo apt-get install graphviz || sudo apt-get update && sudo apt-get install graphviz
- pip install coverage coveralls flake8 -e .
before_script:
before_script:
- make lint
script:
- coverage run --source=objgraph tests.py
......
......@@ -3,6 +3,28 @@ Changes
.. currentmodule:: objgraph
3.0.0 (2016-04-13)
------------------
- :func:`show_most_common_types` and :func:`show_growth` now accept a ``file``
argument if you want to redirect the output elsewhere.
Fixes `issue 24 <https://github.com/mgedmin/objgraph/pull/24>`_. Contributed
by "d-sun-d".
- Don't trust ``__class__`` to be accurate and ``__name__`` to be a string.
Fixes errors in some convoluted corner cases when mocks are involved.
Contributed by Andrew Shannon Brown in `PR 26
<https://github.com/mgedmin/objgraph/pull/26>`_.
- Drop support for Python 2.4, 2.5, and 2.6.
- Drop support for Python 3.1 and 3.2.
- Add support for Python 3.5.
2.0.1 (2015-07-28)
------------------
......
......@@ -9,4 +9,4 @@ include docs/conf.py
include docs/_static/*.css
include .gitignore
include .gitattributes
include .travis.yml
include *.yml
......@@ -8,7 +8,7 @@ VCS_DIFF_IMAGES = git diff docs/*.png
VCS_TAG = git tag
VCS_COMMIT_AND_PUSH = git commit -av -m "Post-release version bump" && git push && git push --tags
SUPPORTED_PYTHON_VERSIONS = 2.4 2.5 2.6 2.7 3.1 3.2 3.3 3.4
SUPPORTED_PYTHON_VERSIONS = 2.7 3.3 3.4 3.5
SPHINXOPTS =
SPHINXBUILD = sphinx-build
......@@ -69,7 +69,7 @@ lint:
.PHONY: dist
dist:
$(PYTHON) setup.py sdist
$(PYTHON) setup.py -q sdist
.PHONY: distcheck
distcheck:
......@@ -131,7 +131,7 @@ release: releasechecklist config-imgdiff
@echo
@echo "then either revert or commit the new images and run"
@echo
@echo " rm -rf dist && $(PYTHON) setup.py sdist --unicode-description && twine upload dist/* && $(VCS_TAG) `$(PYTHON) setup.py --version`"
@echo " rm -rf dist && $(PYTHON) setup.py sdist && twine upload dist/* && $(VCS_TAG) `$(PYTHON) setup.py --version`"
@echo " make publish-docs"
@echo
@echo "Please increment the version number in $(FILE_WITH_VERSION)"
......
Metadata-Version: 1.1
Name: objgraph
Version: 2.0.1
Version: 3.0.0
Summary: Draws Python object reference graphs with graphviz
Home-page: http://mg.pov.lt/objgraph/
Author: Marius Gedminas
......@@ -13,13 +13,14 @@ Description: Python Object Graphs
:target: https://travis-ci.org/mgedmin/objgraph
:alt: Build Status
.. image:: https://ci.appveyor.com/api/projects/status/github/mgedmin/objgraph?branch=master&svg=true
:target: https://ci.appveyor.com/project/mgedmin/objgraph
:alt: Build Status (Windows)
.. image:: https://coveralls.io/repos/mgedmin/objgraph/badge.svg?branch=master
:target: https://coveralls.io/r/mgedmin/objgraph?branch=master
:alt: Test Coverage
.. image:: https://pypip.in/version/objgraph/badge.svg?style=flat
:target: https://pypi.python.org/pypi/objgraph
.. image:: https://readthedocs.org/projects/objgraph/badge/?version=latest
:target: https://readthedocs.org/projects/objgraph/?badge=latest
:alt: Documentation Status
......@@ -80,6 +81,28 @@ Description: Python Object Graphs
3.0.0 (2016-04-13)
------------------
- `show_most_common_types` and `show_growth` now accept a ``file``
argument if you want to redirect the output elsewhere.
Fixes `issue 24 <https://github.com/mgedmin/objgraph/pull/24>`_. Contributed
by "d-sun-d".
- Don't trust ``__class__`` to be accurate and ``__name__`` to be a string.
Fixes errors in some convoluted corner cases when mocks are involved.
Contributed by Andrew Shannon Brown in `PR 26
<https://github.com/mgedmin/objgraph/pull/26>`_.
- Drop support for Python 2.4, 2.5, and 2.6.
- Drop support for Python 3.1 and 3.2.
- Add support for Python 3.5.
2.0.1 (2015-07-28)
------------------
......@@ -315,12 +338,8 @@ Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.4
Classifier: Programming Language :: Python :: 2.5
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.1
Classifier: Programming Language :: Python :: 3.2
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
......@@ -5,13 +5,14 @@ Python Object Graphs
:target: https://travis-ci.org/mgedmin/objgraph
:alt: Build Status
.. image:: https://ci.appveyor.com/api/projects/status/github/mgedmin/objgraph?branch=master&svg=true
:target: https://ci.appveyor.com/project/mgedmin/objgraph
:alt: Build Status (Windows)
.. image:: https://coveralls.io/repos/mgedmin/objgraph/badge.svg?branch=master
:target: https://coveralls.io/r/mgedmin/objgraph?branch=master
:alt: Test Coverage
.. image:: https://pypip.in/version/objgraph/badge.svg?style=flat
:target: https://pypi.python.org/pypi/objgraph
.. image:: https://readthedocs.org/projects/objgraph/badge/?version=latest
:target: https://readthedocs.org/projects/objgraph/?badge=latest
:alt: Documentation Status
......
version: build-{build}-{branch}
environment:
matrix:
# http://www.appveyor.com/docs/installed-software#python lists available
# versions
- PYTHON: "C:\\Python26"
- PYTHON: "C:\\Python27"
- PYTHON: "C:\\Python33"
- PYTHON: "C:\\Python34"
- PYTHON: "C:\\Python35"
init:
- "echo %PYTHON%"
install:
- "set PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
- python --version
- pip install tox
- choco install graphviz.portable
- dot -V
build: off
test_script:
- tox -e py
......@@ -11,13 +11,13 @@ Statistics
.. autofunction:: count(typename[, objects])
.. autofunction:: typestats([objects])
.. autofunction:: typestats([objects, shortnames=True])
.. autofunction:: most_common_types([limit=10, objects, shortnames=True])
.. autofunction:: show_most_common_types([limit=10, objects, shortnames=True])
.. autofunction:: show_most_common_types([limit=10, objects, shortnames=True, file=sys.stdout])
.. autofunction:: show_growth([limit=10, peak_stats={}, shortnames=True])
.. autofunction:: show_growth([limit=10, peak_stats={}, shortnames=True, file=sys.stdout])
Locating and Filtering Objects
......
Metadata-Version: 1.1
Name: objgraph
Version: 2.0.1
Version: 3.0.0
Summary: Draws Python object reference graphs with graphviz
Home-page: http://mg.pov.lt/objgraph/
Author: Marius Gedminas
......@@ -13,13 +13,14 @@ Description: Python Object Graphs
:target: https://travis-ci.org/mgedmin/objgraph
:alt: Build Status
.. image:: https://ci.appveyor.com/api/projects/status/github/mgedmin/objgraph?branch=master&svg=true
:target: https://ci.appveyor.com/project/mgedmin/objgraph
:alt: Build Status (Windows)
.. image:: https://coveralls.io/repos/mgedmin/objgraph/badge.svg?branch=master
:target: https://coveralls.io/r/mgedmin/objgraph?branch=master
:alt: Test Coverage
.. image:: https://pypip.in/version/objgraph/badge.svg?style=flat
:target: https://pypi.python.org/pypi/objgraph
.. image:: https://readthedocs.org/projects/objgraph/badge/?version=latest
:target: https://readthedocs.org/projects/objgraph/?badge=latest
:alt: Documentation Status
......@@ -80,6 +81,28 @@ Description: Python Object Graphs
3.0.0 (2016-04-13)
------------------
- `show_most_common_types` and `show_growth` now accept a ``file``
argument if you want to redirect the output elsewhere.
Fixes `issue 24 <https://github.com/mgedmin/objgraph/pull/24>`_. Contributed
by "d-sun-d".
- Don't trust ``__class__`` to be accurate and ``__name__`` to be a string.
Fixes errors in some convoluted corner cases when mocks are involved.
Contributed by Andrew Shannon Brown in `PR 26
<https://github.com/mgedmin/objgraph/pull/26>`_.
- Drop support for Python 2.4, 2.5, and 2.6.
- Drop support for Python 3.1 and 3.2.
- Add support for Python 3.5.
2.0.1 (2015-07-28)
------------------
......@@ -315,12 +338,8 @@ Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.4
Classifier: Programming Language :: Python :: 2.5
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.1
Classifier: Programming Language :: Python :: 3.2
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
......@@ -6,6 +6,7 @@ HACKING.rst
MANIFEST.in
Makefile
README.rst
appveyor.yml
objgraph.py
setup.cfg
setup.py
......
{"is_release": false, "git_version": "abe2f37"}
\ No newline at end of file
{"is_release": false, "git_version": "7b448f7"}
\ No newline at end of file
......@@ -3,7 +3,7 @@ Tools for drawing Python object reference graphs with graphviz.
You can find documentation online at http://mg.pov.lt/objgraph/
Copyright (c) 2008-2015 Marius Gedminas <marius@pov.lt> and contributors
Copyright (c) 2008-2016 Marius Gedminas <marius@pov.lt> and contributors
Released under the MIT licence.
"""
......@@ -46,10 +46,10 @@ except ImportError:
__author__ = "Marius Gedminas (marius@gedmin.as)"
__copyright__ = "Copyright (c) 2008-2015 Marius Gedminas and contributors"
__copyright__ = "Copyright (c) 2008-2016 Marius Gedminas and contributors"
__license__ = "MIT"
__version__ = "2.0.1"
__date__ = "2015-07-28"
__version__ = "3.0.0"
__date__ = "2016-04-13"
try:
......@@ -65,19 +65,42 @@ except AttributeError:
iteritems = dict.items
def _isinstance(object, classinfo):
"""Return whether an object is an instance of a class or its subclass.
Differs from the builtin isinstance() implementation in that it does not
depend on the ``__class__`` attribute which is proxied by
mock.Mock(spec=...).
"""
return issubclass(type(object), classinfo)
def count(typename, objects=None):
"""Count objects tracked by the garbage collector with a given class name.
The class name can optionally be fully qualified.
Example:
>>> count('dict')
42
>>> count('MyClass', get_leaking_objects())
3
>>> count('mymodule.MyClass')
2
Note that the GC does not track simple objects like int or str.
.. note::
The Python garbage collector does not track simple
objects like int or str. See
https://docs.python.org/3/library/gc.html#gc.is_tracked
for more information.
Instead of looking through all objects tracked by the GC, you may
specify your own collection, e.g.
>>> count('MyClass', get_leaking_objects())
3
See also: :func:`get_leaking_objects`.
.. versionchanged:: 1.7
New parameter: ``objects``.
......@@ -169,7 +192,11 @@ def most_common_types(limit=10, objects=None, shortnames=True):
return stats
def show_most_common_types(limit=10, objects=None, shortnames=True):
def show_most_common_types(
limit=10,
objects=None,
shortnames=True,
file=sys.stdout):
"""Print the table of types of most common instances.
The caveats documented in :func:`typestats` apply.
......@@ -191,14 +218,17 @@ def show_most_common_types(limit=10, objects=None, shortnames=True):
.. versionchanged:: 1.8
New parameter: ``shortnames``.
.. versionchanged:: 2.1
New parameter: ``file``.
"""
stats = most_common_types(limit, objects, shortnames=shortnames)
width = max(len(name) for name, count in stats)
for name, count in stats:
print('%-*s %i' % (width, name, count))
file.write('%-*s %i\n' % (width, name, count))
def show_growth(limit=10, peak_stats={}, shortnames=True):
def show_growth(limit=10, peak_stats={}, shortnames=True, file=sys.stdout):
"""Show the increase in peak object counts since last call.
Limits the output to ``limit`` largest deltas. You may set ``limit`` to
......@@ -223,6 +253,9 @@ def show_growth(limit=10, peak_stats={}, shortnames=True):
.. versionchanged:: 1.8
New parameter: ``shortnames``.
.. versionchanged:: 2.1
New parameter: ``file``.
"""
gc.collect()
stats = typestats(shortnames=shortnames)
......@@ -239,7 +272,7 @@ def show_growth(limit=10, peak_stats={}, shortnames=True):
if deltas:
width = max(len(name) for name, count in deltas)
for name, delta in deltas:
print('%-*s%9d %+9d' % (width, name, stats[name], delta))
file.write('%-*s%9d %+9d\n' % (width, name, stats[name], delta))
def get_leaking_objects(objects=None):
......@@ -615,7 +648,7 @@ def _show_graph(objs, edge_func, swap_source_target,
highlight=None, filename=None, extra_info=None,
refcounts=False, shortnames=True, output=None,
cull_func=None):
if not isinstance(objs, (list, tuple)):
if not _isinstance(objs, (list, tuple)):
objs = [objs]
if filename and output:
raise ValueError('Cannot specify both output and filename.')
......@@ -834,26 +867,31 @@ def _safe_repr(obj):
return '(unrepresentable)'
def _short_repr(obj):
if isinstance(obj, (type, types.ModuleType, types.BuiltinMethodType,
types.BuiltinFunctionType)):
return obj.__name__
if isinstance(obj, types.MethodType):
try:
if obj.__self__ is not None:
return obj.__func__.__name__ + ' (bound)'
else:
return obj.__func__.__name__
except AttributeError: # pragma: nocover
# Python < 2.6 compatibility
if obj.im_self is not None:
return obj.im_func.__name__ + ' (bound)'
else:
return obj.im_func.__name__
def _name_or_repr(value):
try:
result = value.__name__
except AttributeError:
result = repr(value)[:40]
if _isinstance(result, basestring):
return result
else:
return repr(value)[:40]
if isinstance(obj, types.FrameType):
def _short_repr(obj):
if _isinstance(obj, (type, types.ModuleType, types.BuiltinMethodType,
types.BuiltinFunctionType)):
return _name_or_repr(obj)
if _isinstance(obj, types.MethodType):
name = _name_or_repr(obj.__func__)
if obj.__self__:
return name + ' (bound)'
else:
return name
if _isinstance(obj, types.FrameType):
return '%s:%s' % (obj.f_code.co_filename, obj.f_lineno)
if isinstance(obj, (tuple, list, dict, set)):
if _isinstance(obj, (tuple, list, dict, set)):
return '%d items' % len(obj)
return repr(obj)[:40]
......@@ -872,15 +910,15 @@ def _gradient(start_color, end_color, depth, max_depth):
def _edge_label(source, target, shortnames=True):
if (isinstance(target, dict) and
if (_isinstance(target, dict) and
target is getattr(source, '__dict__', None)):
return ' [label="__dict__",weight=10]'
if isinstance(source, types.FrameType):
if _isinstance(source, types.FrameType):
if target is source.f_locals:
return ' [label="f_locals",weight=10]'
if target is source.f_globals:
return ' [label="f_globals",weight=10]'
if isinstance(source, types.MethodType):
if _isinstance(source, types.MethodType):
try:
if target is source.__self__:
return ' [label="__self__",weight=10]'
......@@ -892,14 +930,14 @@ def _edge_label(source, target, shortnames=True):
return ' [label="im_self",weight=10]'
if target is source.im_func:
return ' [label="im_func",weight=10]'
if isinstance(source, types.FunctionType):
if _isinstance(source, types.FunctionType):
for k in dir(source):
if target is getattr(source, k):
return ' [label="%s",weight=10]' % _quote(k)
if isinstance(source, dict):
if _isinstance(source, dict):
for k, v in iteritems(source):
if v is target:
if isinstance(k, basestring) and _is_identifier(k):
if _isinstance(k, basestring) and _is_identifier(k):
return ' [label="%s",weight=2]' % _quote(k)
else:
if shortnames:
......
......@@ -54,13 +54,6 @@ def get_description():
readme = read('README.rst')
changelog = read('CHANGES.rst')
description = unsphinx(readme + '\n\n\n' + changelog)
if '--unicode-description' in sys.argv:
sys.argv.remove('--unicode-description')
else:
# can't use u'' literals, this is supposed to work on both Py2 and Py3
description = description.replace('Kristj%sn' % unichr(0xe1),
'Kristjan')
description = description.encode('ascii', 'replace').decode('ascii')
return description
......@@ -96,15 +89,12 @@ setup(name='objgraph',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.4',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.1',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
py_modules=['objgraph'],
tests_require=['mock'],
**setuptools_options)
......@@ -9,8 +9,14 @@ import string
import sys
import tempfile
import textwrap
import types
import unittest
try:
from unittest import mock
except ImportError:
import mock
import objgraph
try:
......@@ -304,6 +310,49 @@ class StringRepresentationTest(GarbageCollectedMixin,
return 1/0
self.assertEqual('(unrepresentable)', objgraph._safe_repr(MyClass()))
def test_short_repr_mocked_instance_method(self):
class MyClass(object):
def my_method(self):
pass
my_mock = mock.create_autospec(MyClass)
self.assertRegex(objgraph._short_repr(my_mock.my_method), '<MagicMock')
def test_short_repr_mocked_instance_method_bound(self):
class MyClass(object):
def my_method(self):
pass
mock_method = mock.Mock()
obj = MyClass()
with mock.patch.object(obj, 'my_method',
types.MethodType(mock_method, obj)):
self.assertRegex(objgraph._short_repr(obj.my_method), '<Mock')
def test_short_repr_mocked_name(self):
self.assertRegex(objgraph._short_repr(mock.Mock(__name__=mock.Mock())),
'<Mock')
def test_short_repr_magic_mocked_name(self):
self.assertRegex(objgraph._short_repr(mock.Mock(
__name__=mock.MagicMock())), '<Mock')
def test_short_repr_mock_with_spec(self):
self.assertRegex(objgraph._short_repr(mock.Mock(spec=list)), '<Mock')
def test_short_repr_mocked_instance_method_bound_with_mocked_name(self):
class MyClass(object):
def my_method(self):
pass
mock_method = mock.Mock(__name__=mock.MagicMock())
obj = MyClass()
with mock.patch.object(obj, 'my_method',
types.MethodType(mock_method, obj)):
self.assertRegex(objgraph._short_repr(obj.my_method), '<Mock')
@skipIf(sys.version_info[0] > 2, "Python 3 has no unbound methods")
def test_short_repr_unbound_method(self):
class MyClass(object):
......
[tox]
envlist = py26, py27, py32, py33, py34
envlist = py27, py33, py34, py35
[testenv]
commands = python tests.py
deps = mock
commands =
python tests.py {posargs}
[testenv:py]
commands =
python --version
python tests.py {posargs}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment