Skip to content

Add Custom Topological Sorter#748

Open
yaskhan wants to merge 1 commit intopy2many:mainfrom
yaskhan:customtopo
Open

Add Custom Topological Sorter#748
yaskhan wants to merge 1 commit intopy2many:mainfrom
yaskhan:customtopo

Conversation

@yaskhan
Copy link
Contributor

@yaskhan yaskhan commented Jan 27, 2026

Custom Topological Sorter (py2many/toposort_modules.py) #729

Implemented a replacement for graphlib.TopologicalSorter to handle real-world module complexities:

  • Cycle Tolerance: No longer raises CycleError on circular imports.
  • Deterministic Breakage: Resolves cycles by selecting the lexicographically first node when blocked.
  • Stability: Maintains consistent output order by sorting groups of ready nodes.

I've implemented a comprehensive test suite for the custom TopologicalSorter in tests/test_toposort.py. All 6 test cases passed, covering:

  • Basic DAG handling
  • Simple and complex cycle tolerance
  • Deterministic lexicographical breakage
  • Stability of independent node groups

self.done(*node_group)


class StableTopologicalSorter(TopologicalSorter):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove



class StableTopologicalSorter(TopologicalSorter):
class TopologicalSorter:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring on how this is different from graphlib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants