[Python-modules-commits] [toposort] 02/07: New upstream version 1.5
Luca Falavigna
dktrkranz at moszumanska.debian.org
Tue Oct 25 15:34:54 UTC 2016
This is an automated email from the git hooks/post-receive script.
dktrkranz pushed a commit to branch master
in repository toposort.
commit d0d2ac477ec26e2a9465a507284e04d71a493093
Author: Luca Falavigna <dktrkranz at debian.org>
Date: Tue Oct 25 17:12:13 2016 +0200
New upstream version 1.5
---
.hg_archival.txt | 4 ++--
.hgtags | 1 +
CHANGES.txt | 15 +++++++++++++++
README.txt | 10 +++++++---
setup.cfg | 2 ++
setup.py | 23 ++++-------------------
test/test_toposort.py | 25 ++++++++++++++++++++++++-
toposort.py | 14 ++++++++++++--
8 files changed, 67 insertions(+), 27 deletions(-)
diff --git a/.hg_archival.txt b/.hg_archival.txt
index 964e0d2..5fed27a 100644
--- a/.hg_archival.txt
+++ b/.hg_archival.txt
@@ -1,4 +1,4 @@
repo: 641ad0e3f272bba47558e955319884471ce5e009
-node: 9ef748788b05917300364bb339f6f779487f6a6b
+node: 36129704f0a7dbed9986b1b02f750c5e21e634e1
branch: default
-tag: 1.4
+tag: 1.5
diff --git a/.hgtags b/.hgtags
index 6bb6f80..a865862 100644
--- a/.hgtags
+++ b/.hgtags
@@ -8,3 +8,4 @@ c335d14368a591c2818f06f88ce4b748c78815f1 1.1
63aab3edfecbf0232ba352dc70c1a38cd3f6c731 1.2
f4d510c1e885f3aed6ab3a81cd6f6e4d8b423eb8 1.2
b3f4f29c2685aad55c47a37cbc9c040536a2a57f 1.3
+9ef748788b05917300364bb339f6f779487f6a6b 1.4
diff --git a/CHANGES.txt b/CHANGES.txt
index faee3f7..bf8b56e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,21 @@
Change log
==========
+1.5 2016-10-24 Eric V. Smith
+----------------------------
+
+* When a circular dependency error is detected, raise a specific
+ exception, CircularDependencyError, which is a subclass of
+ ValueError. The 'data' attribute of the exception will contain the
+ data involved in the circular dependency (issue #2). Thanks
+ lilydjwg for the initial patch.
+
+* To make building wheels easier, always require setuptools in
+ setup.py (issue #5).
+
+* Mark wheel as being universal, that is, supporting both Python 2.7
+ and 3.x (issue #7).
+
1.4 2015-05-16 Eric V. Smith
----------------------------
diff --git a/README.txt b/README.txt
index 6df7079..55ec7a4 100644
--- a/README.txt
+++ b/README.txt
@@ -51,15 +51,19 @@ returned, or a circular dependency is detected.
Circular dependencies
=====================
-A circular dependency will raise a ValueError. Here 1 depends on 2,
-and 2 depends on 1::
+A circular dependency will raise a CyclicDependencyError, which is
+derived from ValueError. Here 1 depends on 2, and 2 depends on 1::
>>> list(toposort({1: {2},
... 2: {1},
... }))
Traceback (most recent call last):
...
- ValueError: Cyclic dependencies exist among these items: (1, {2}), (2, {1})
+ toposort.CircularDependencyError: Circular dependencies exist among these items: {1:{2}, 2:{1}}
+
+In addition, the 'data' attribute of the raised CyclicDependencyError
+will contain a dict containing the subset of the input data involved
+in the circular dependency.
Module contents
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..3c6e79c
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,2 @@
+[bdist_wheel]
+universal=1
diff --git a/setup.py b/setup.py
index 5e14f74..7a33916 100644
--- a/setup.py
+++ b/setup.py
@@ -1,20 +1,5 @@
from __future__ import print_function
-from distutils.core import setup, Command
-import sys
-
-# This is a hack in order to get the package name to be different when
-# building an RPM file. When 'setup.py bdist_rpm' is called, it invokes
-# setup.py twice more, with these command lines:
-# ['setup.py', 'build']
-# ['setup.py', 'install', '-O1', '--root=/home/eric/local/toposort/build/bdist.linux-i686/rpm/BUILDROOT/python-toposort-0.1-1.i386', '--record=INSTALLED_FILES']
-# It's only on the original call (when bdist_rpm is in sys.argv) that
-# I adjust the package name. With Python 2.7, that's enough. I'm not
-# sure about 3.x.
-
-name = 'toposort'
-if 'bdist_rpm' in sys.argv:
- name = 'python{0}-{1}'.format('' if sys.version_info.major == 2 else '3', name)
-
+from setuptools import setup, Command
# run our tests
class PyTest(Command):
@@ -39,8 +24,8 @@ class PyTest(Command):
print('test complete')
-setup(name=name,
- version='1.4',
+setup(name='toposort',
+ version='1.5',
url='https://bitbucket.org/ericvsmith/toposort',
author='Eric V. Smith',
author_email='eric at trueblade.com',
@@ -53,9 +38,9 @@ setup(name=name,
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
+ 'Programming Language :: Python :: 3.5',
],
license='Apache License Version 2.0',
py_modules=['toposort'],
-
cmdclass = {'test': PyTest},
)
diff --git a/test/test_toposort.py b/test/test_toposort.py
index 0d7a22a..f698deb 100644
--- a/test/test_toposort.py
+++ b/test/test_toposort.py
@@ -21,7 +21,7 @@
import unittest
-from toposort import toposort, toposort_flatten
+from toposort import toposort, toposort_flatten, CircularDependencyError
class TestCase(unittest.TestCase):
def test_simple(self):
@@ -104,15 +104,37 @@ class TestCase(unittest.TestCase):
def test_cycle(self):
# a simple, 2 element cycle
+ # make sure we can catch this both as ValueError and CircularDependencyError
self.assertRaises(ValueError, list, toposort({1: {2},
2: {1}
}))
+ with self.assertRaises(CircularDependencyError) as ex:
+ list(toposort({1: {2},
+ 2: {1}
+ }))
+ self.assertEqual(ex.exception.data, {1: {2}, 2: {1}})
# an indirect cycle
self.assertRaises(ValueError, list, toposort({1: {2},
2: {3},
3: {1},
}))
+ with self.assertRaises(CircularDependencyError) as ex:
+ list(toposort({1: {2},
+ 2: {3},
+ 3: {1},
+ }))
+ self.assertEqual(ex.exception.data, {1: {2}, 2: {3}, 3: {1}})
+
+ # not all elements involved in a cycle
+ with self.assertRaises(CircularDependencyError) as ex:
+ list(toposort({1: {2},
+ 2: {3},
+ 3: {1},
+ 5: {4},
+ 4: {6},
+ }))
+ self.assertEqual(ex.exception.data, {1: set([2]), 2: set([3]), 3: set([1])})
def test_input_not_modified(self):
data = {2: {11},
@@ -157,6 +179,7 @@ class TestCaseAll(unittest.TestCase):
results = [{i for i in actual[0:3]}, {i for i in actual[3:5]}, {i for i in actual[5:8]}]
self.assertEqual(results, expected)
+
class TestAll(unittest.TestCase):
def test_all(self):
import toposort
diff --git a/toposort.py b/toposort.py
index 64931c3..25e6aeb 100644
--- a/toposort.py
+++ b/toposort.py
@@ -35,7 +35,17 @@
from functools import reduce as _reduce
-__all__ = ['toposort', 'toposort_flatten']
+__all__ = ['toposort', 'toposort_flatten', 'CircularDependencyError']
+
+
+class CircularDependencyError(ValueError):
+ def __init__(self, data):
+ # Sort the data just to make the output consistent, for use in
+ # error messages. That's convenient for doctests.
+ s = 'Circular dependencies exist among these items: {{{}}}'.format(', '.join('{!r}:{!r}'.format(key, value) for key, value in sorted(data.items())))
+ super(CircularDependencyError, self).__init__(s)
+ self.data = data
+
def toposort(data):
"""Dependencies are expressed as a dictionary whose keys are items
@@ -68,7 +78,7 @@ items in the preceeding sets.
for item, dep in data.items()
if item not in ordered}
if len(data) != 0:
- raise ValueError('Cyclic dependencies exist among these items: {}'.format(', '.join(repr(x) for x in data.items())))
+ raise CircularDependencyError(data)
def toposort_flatten(data, sort=True):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/toposort.git
More information about the Python-modules-commits
mailing list