[Python-modules-commits] [python-rebulk] 05/05: Remove embedded toposort

Etienne Millon emillon-guest at moszumanska.debian.org
Thu Nov 16 22:36:41 UTC 2017


This is an automated email from the git hooks/post-receive script.

emillon-guest pushed a commit to branch master
in repository python-rebulk.

commit be233dda6cec0bed0c4b228cbc2ab5863c93adf8
Author: Etienne Millon <me at emillon.org>
Date:   Thu Nov 16 23:15:10 2017 +0100

    Remove embedded toposort
---
 debian/patches/0001-Remove-embedded-toposort.patch | 232 +++++++++++++++++++++
 debian/patches/series                              |   1 +
 2 files changed, 233 insertions(+)

diff --git a/debian/patches/0001-Remove-embedded-toposort.patch b/debian/patches/0001-Remove-embedded-toposort.patch
new file mode 100644
index 0000000..1ae6f44
--- /dev/null
+++ b/debian/patches/0001-Remove-embedded-toposort.patch
@@ -0,0 +1,232 @@
+From: Etienne Millon <me at emillon.org>
+Date: Thu, 16 Nov 2017 23:14:06 +0100
+Subject: Remove embedded toposort
+
+---
+ rebulk/rules.py              |   2 +-
+ rebulk/test/test_toposort.py | 111 -------------------------------------------
+ rebulk/toposort.py           |  84 --------------------------------
+ 3 files changed, 1 insertion(+), 196 deletions(-)
+ delete mode 100644 rebulk/test/test_toposort.py
+ delete mode 100644 rebulk/toposort.py
+
+diff --git a/rebulk/rules.py b/rebulk/rules.py
+index 19b563a..55d165d 100644
+--- a/rebulk/rules.py
++++ b/rebulk/rules.py
+@@ -11,7 +11,7 @@ from logging import getLogger
+ import six
+ from .utils import is_iterable
+ 
+-from .toposort import toposort
++from toposort import toposort
+ 
+ from . import debug
+ 
+diff --git a/rebulk/test/test_toposort.py b/rebulk/test/test_toposort.py
+deleted file mode 100644
+index 76ea603..0000000
+--- a/rebulk/test/test_toposort.py
++++ /dev/null
+@@ -1,111 +0,0 @@
+-#!/usr/bin/env python
+-# -*- coding: utf-8 -*-
+-# Copyright 2014 True Blade Systems, Inc.
+-#
+-# Licensed under the Apache License, Version 2.0 (the "License");
+-# you may not use this file except in compliance with the License.
+-# You may obtain a copy of the License at
+-#
+-# http://www.apache.org/licenses/LICENSE-2.0
+-#
+-# Original:
+-#   - https://bitbucket.org/ericvsmith/toposort (1.4)
+-# Modifications:
+-#   - port to pytest
+-# pylint: skip-file
+-
+-import pytest
+-from ..toposort import toposort, toposort_flatten, CyclicDependency
+-
+-
+-class TestCase(object):
+-    def test_simple(self):
+-        results = list(toposort({2: set([11]), 9: set([11, 8]), 10: set([11, 3]), 11: set([7, 5]), 8: set([7, 3])}))
+-        expected = [set([3, 5, 7]), set([8, 11]), set([2, 9, 10])]
+-        assert results == expected
+-
+-        # make sure self dependencies are ignored
+-        results = list(toposort({2: set([2, 11]), 9: set([11, 8]), 10: set([10, 11, 3]), 11: set([7, 5]), 8: set([7, 3])}))
+-        expected = [set([3, 5, 7]), set([8, 11]), set([2, 9, 10])]
+-        assert results == expected
+-
+-        assert list(toposort({1: set()})) == [set([1])]
+-        assert list(toposort({1: set([1])})) == [set([1])]
+-
+-    def test_no_dependencies(self):
+-        assert list(toposort({1: set([2]), 3: set([4]), 5: set([6])})) == [set([2, 4, 6]), set([1, 3, 5])]
+-        assert list(toposort({1: set(), 3: set(), 5: set()})) == [set([1, 3, 5])]
+-
+-    def test_empty(self):
+-        assert list(toposort({})) == []
+-
+-    def test_strings(self):
+-        results = list(toposort({'2': set(['11']), '9': set(['11', '8']), '10': set(['11', '3']), '11': set(['7', '5']), '8': set(['7', '3'])}))
+-        expected = [set(['3', '5', '7']), set(['8', '11']), set(['2', '9', '10'])]
+-        assert results == expected
+-
+-    def test_objects(self):
+-        o2 = object()
+-        o3 = object()
+-        o5 = object()
+-        o7 = object()
+-        o8 = object()
+-        o9 = object()
+-        o10 = object()
+-        o11 = object()
+-        results = list(toposort({o2: set([o11]), o9: set([o11, o8]), o10: set([o11, o3]), o11: set([o7, o5]), o8: set([o7, o3, o8])}))
+-        expected = [set([o3, o5, o7]), set([o8, o11]), set([o2, o9, o10])]
+-        assert results == expected
+-
+-    def test_cycle(self):
+-        # a simple, 2 element cycle
+-        with pytest.raises(CyclicDependency):
+-            list(toposort({1: set([2]), 2: set([1])}))
+-
+-        # an indirect cycle
+-        with pytest.raises(CyclicDependency):
+-            list(toposort({1: set([2]), 2: set([3]), 3: set([1])}))
+-
+-    def test_input_not_modified(self):
+-        data = {2: set([11]),
+-                9: set([11, 8]),
+-                10: set([11, 3]),
+-                11: set([7, 5]),
+-                8: set([7, 3, 8]),  # includes something self-referential
+-                }
+-        orig = data.copy()
+-        results = list(toposort(data))
+-        assert data == orig
+-
+-    def test_input_not_modified_when_cycle_error(self):
+-        data = {1: set([2]),
+-                2: set([1]),
+-                3: set([4]),
+-                }
+-        orig = data.copy()
+-        with pytest.raises(CyclicDependency):
+-            list(toposort(data))
+-        assert data == orig
+-
+-
+-class TestCaseAll(object):
+-    def test_sort_flatten(self):
+-        data = {2: set([11]),
+-                9: set([11, 8]),
+-                10: set([11, 3]),
+-                11: set([7, 5]),
+-                8: set([7, 3, 8]),  # includes something self-referential
+-                }
+-        expected = [set([3, 5, 7]), set([8, 11]), set([2, 9, 10])]
+-        assert list(toposort(data)) == expected
+-
+-        # now check the sorted results
+-        results = []
+-        for item in expected:
+-            results.extend(sorted(item))
+-        assert toposort_flatten(data) == results
+-
+-        # and the unsorted results. break the results up into groups to compare them
+-        actual = toposort_flatten(data, False)
+-        results = [set([i for i in actual[0:3]]), set([i for i in actual[3:5]]), set([i for i in actual[5:8]])]
+-        assert results == expected
+diff --git a/rebulk/toposort.py b/rebulk/toposort.py
+deleted file mode 100644
+index 2bcba9a..0000000
+--- a/rebulk/toposort.py
++++ /dev/null
+@@ -1,84 +0,0 @@
+-#!/usr/bin/env python
+-# -*- coding: utf-8 -*-
+-# Copyright 2014 True Blade Systems, Inc.
+-#
+-# Licensed under the Apache License, Version 2.0 (the "License");
+-# you may not use this file except in compliance with the License.
+-# You may obtain a copy of the License at
+-#
+-# http://www.apache.org/licenses/LICENSE-2.0
+-#
+-# Original:
+-#   - https://bitbucket.org/ericvsmith/toposort (1.4)
+-# Modifications:
+-#   - merged Pull request #2 for CyclicDependency error
+-#   - import reduce as original name
+-#   - support python 2.6 dict comprehension
+-
+-# pylint: skip-file
+-from functools import reduce
+-
+-
+-class CyclicDependency(ValueError):
+-    def __init__(self, cyclic):
+-        s = 'Cyclic dependencies exist among these items: {0}'.format(', '.join(repr(x) for x in cyclic.items()))
+-        super(CyclicDependency, self).__init__(s)
+-        self.cyclic = cyclic
+-
+-
+-def toposort(data):
+-    """
+-    Dependencies are expressed as a dictionary whose keys are items
+-    and whose values are a set of dependent items. Output is a list of
+-    sets in topological order. The first set consists of items with no
+-    dependences, each subsequent set consists of items that depend upon
+-    items in the preceeding sets.
+-    :param data:
+-    :type data:
+-    :return:
+-    :rtype:
+-    """
+-
+-    # Special case empty input.
+-    if len(data) == 0:
+-        return
+-
+-    # Copy the input so as to leave it unmodified.
+-    data = data.copy()
+-
+-    # Ignore self dependencies.
+-    for k, v in data.items():
+-        v.discard(k)
+-    # Find all items that don't depend on anything.
+-    extra_items_in_deps = reduce(set.union, data.values()) - set(data.keys())
+-    # Add empty dependences where needed.
+-    data.update(dict((item, set()) for item in extra_items_in_deps))
+-    while True:
+-        ordered = set(item for item, dep in data.items() if len(dep) == 0)
+-        if not ordered:
+-            break
+-        yield ordered
+-        data = dict((item, (dep - ordered))
+-                for item, dep in data.items()
+-                if item not in ordered)
+-    if len(data) != 0:
+-        raise CyclicDependency(data)
+-
+-
+-def toposort_flatten(data, sort=True):
+-    """
+-    Returns a single list of dependencies. For any set returned by
+-    toposort(), those items are sorted and appended to the result (just to
+-    make the results deterministic).
+-    :param data:
+-    :type data:
+-    :param sort:
+-    :type sort:
+-    :return: Single list of dependencies.
+-    :rtype: list
+-    """
+-
+-    result = []
+-    for d in toposort(data):
+-        result.extend((sorted if sort else list)(d))
+-    return result
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..a030f8e
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1 @@
+0001-Remove-embedded-toposort.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-rebulk.git



More information about the Python-modules-commits mailing list