30 Commits

Author SHA1 Message Date
Takashi Kajinami
80e1aadc49 Run pyupgrade to clean up Python 2 syntaxes
Update all .py source files by
 $ pyupgrade --py3-only $(git ls-files | grep ".py$")
to modernize the code according to Python 3 syntaxes.

pep8 errors are fixed by
 $ autopep8 --select=E127,E128,E501 --max-line-length 79 -r \
    --in-place taskflow

Also add the pyupgrade hook to pre-commit to avoid merging additional
Python 2 syntaxes.

Change-Id: Ifd0a0ade9789497482c7937bffd82c48acfb3d78
2025-04-02 15:23:12 +09:00
Takashi Kajinami
44f17d005f Remove six
This library no longer supports Python 2, thus usage of six can be
removed. This also removes workaround about pickle library used in
Python 2 only.

Change-Id: I19d298cf0f402d65f0b142dea0bf35cf992332a9
2022-05-18 16:12:37 +09:00
Michal Arbet
d985c5a256 Fix code to support networkx > 1.0
With the release of NetworkX 2.0 the reporting API was
moved to view/iterator model. Many methods were moved from
reporting lists or dicts to iterating over the information.
Methods that used to return containers now return views and
methods that returned iterators have been removed in networkx.
Because of this change in NetworkX 2.0 , taskflow code
have to be changed also to support networkx > 2.0

Change-Id: I23c226f37bd85c1e38039fbcb302a2d0de49f333
Closes-Bug: #1778115
2018-07-11 13:11:51 +02:00
howardlee
271c637d5c Remove vim header from source files
Trivial fix

[H106] Don't put vim configuration in source files (off by default).

Change-Id: I7e9e9930fd6f135074078637f5af6f403e75ff78
2016-11-09 16:06:10 +08:00
Pablo Iranzo Gómez
74221942ef Fix some misspellings in the function name and descriptions
Change-Id: I7e3451feb94b1f25b00c5e7b197bb6b527548306
2016-06-30 17:44:49 +02:00
Jenkins
ed88aa4c39 Merge "Enable conversion of the tree nodes into a digraph" 2015-11-18 22:58:32 +00:00
Joshua Harlow
484ded4baa Enable conversion of the tree nodes into a digraph
Just like it's useful to be able to translate a execution
graph into a dot diagram, the same usefulness can be helpful
for the engine scoping hierarchy that is created, to make
it easily possible to do this provide a tree method that
converts itself (and its children) into a direct graph which
can then easily be exported as a dot diagram (and then
rendered as needed).

Change-Id: I0addc2dee4cdce03ee5f33832a419303abc77db4
2015-11-18 20:10:12 +00:00
Joshua Harlow
4f41c43ed0 Ensure node 'remove' and 'disassociate' can not be called when frozen
When a tree node is frozen it should not be possible to remove nodes
from it or cause that tree node to disassociate itself from its parent,
so make sure that the appropriate decorator is used to ensure this
can not happen (and add tests that verify an exception is raised when
mutations are attempted).

Change-Id: I27e4af7b891ea3fd1826d5a5e71e808ad5af7647
2015-10-14 22:47:06 -07:00
Joshua Harlow
75517eb0e0 Use the node built-in 'dfs_iter' instead of recursion
We can just use the non-recursive depth first iteration
of nodes when scanning for atoms to select for a given
scope level instead of using recursive calls to achieve
the same effect.

This makes it possible to have large and heavily nested
flows that are not restricted by the python stack limit.

Change-Id: I0d18565680f777adbdfca9d4983636c6b3e848da
2015-10-02 23:14:22 +00:00
Joshua Harlow
b1c22dc2e2 Replace the tree 'pformat()' recursion with non-recursive variant
This adjusted variant creates the same output but is hopefully
easier to understand and follow than the recursive version.

This version is also not limited by the python stack limit which
is a general good thing to avoid being limited by.

It also adds a bunch of tests to make sure the format is as expected
under various tree structures.

Change-Id: I2ae42c7c1bf72794800929250bcf6ccbe658230b
2015-07-27 11:20:39 -07:00
Joshua Harlow
de68bc2d72 Allow providing a node stringify function to tree pformat
Allow providing a node to string function that will be activated
when the root node pformat routine needs to format a node into
a string (for viewing purposes); this allows for subclasses or
other users of nodes to provide there own function that they can
specialize as they see fit (without duplicating the pformat
routine itself).

To start use it to print out the node link target in the fake
in-memory filesystem when a link is encountered.

Change-Id: I33b8f1ec8d30d72ae35971e35f5edd84a9145db7
2015-03-29 22:59:04 -07:00
Joshua Harlow
db22de960c Add node removal/disassociate functions
When a node desires to be removed from its parent (or
a parent wants to remove a child) it is quite useful
to provide functions that do just this so that nodes
can remove themselves or there children when this kind
of usage is desired.

Change-Id: I0071e9a7e15219e0cb7b92779e4f5a08596e5d34
2015-03-04 11:53:57 -08:00
Jenkins
3bc546b7ed Merge "Add a frozen checking decorator" 2015-03-04 06:55:03 +00:00
Joshua Harlow
53af5d3221 Allow node finding to not do a deep search
When a local search is preferred allow for it
to be done by passing in a 'only_direct' option,
also allows passing in a 'include_self' option
to ignore/include the current node when finding.

The defaults of 'include_self' and 'only_direct'
work just as they did prior to this change, so that
the addition does not affect current usage(s) of
this method.

Change-Id: I89fb476bee32144092ea141ca3b971118ab633be
2015-03-03 21:02:20 +00:00
Joshua Harlow
3c806b1d6a Add a frozen checking decorator
Since quite a few of the types check for being
frozen and disallow mutations on there instances
we can take advantage of a common decorator that
checks the frozen attribute and raises instead
of duplicating the same logic at the start of
the mutating methods.

Change-Id: I8c81a26d2d39bb9da4f68d64e07f67ac26ee0b08
2015-03-02 23:05:46 -08:00
Jenkins
345afc037b Merge "Add a BFS tree iterator" 2015-02-15 05:10:19 +00:00
Jenkins
f11f7bbda7 Merge "Docstrings should document parameters return values" 2015-02-12 21:01:59 +00:00
Vilobh Meshram
b7d59ec748 Docstrings should document parameters return values
Partial-Bug: #1374202

Documents what the function parameters are, what
is the type of the parameters passed what return
values are, how it is used and what they should
provide for it when using a method/class or deriving
from an existing class.

Change-Id: Ie81b3a446c9fee2dad9411efa28dad8d455b06ba
2015-02-11 07:03:34 +00:00
Joshua Harlow
19e0789ebe Add a BFS tree iterator
To complement the DFS iterator that we provide in our
tree helper/type class add a BFS iterator as well so that
when/if we extract this module to elsewhere we can have
a nice featureful (and hopefully useful) set of iterators
for folks to use.

Change-Id: I1bc10c25bb62a5ffc85863f3f894d5469db95ff6
2015-02-10 15:36:03 -08:00
Joshua Harlow
3bf3249cc7 DFS in right order when not starting at the provided node
When the dfs iteration is requested to start at the provided
nodes children make sure that we create the stack in the same
way as we do its children to ensure that the DFS iteration
order is maintained correctly in this situation.

Change-Id: I9d5e3a46b4d2349ab1662a634d635b2052be4a55
2015-02-10 15:28:53 -08:00
Joshua Harlow
524289229e Use class constants during pformatting a tree node
To match the table type (which also uses class constants
for pformatting) have the tree type also use class constants
in its pformat method; this makes it easier to understand
what the constants are (and allows them to change if needed)
by associating 'useful' variable names to them...

Change-Id: I0a392542d2572e12718972a9f74ecf838918699d
2015-02-01 22:16:40 -08:00
Joshua Harlow
42a665d06f Use platform neutral line separator(s)
To at least try to support things like windows it's better
if we can make an attempt to use the platform neutral
characters for line separator(s) where appropriate.

Change-Id: Icc533ed4d4c94f461b7f19600b74146221f17b18
2015-01-12 20:33:51 -08:00
Joshua Harlow
49ac8ec3ee Avoid creating a temporary list(s) for tree type
Instead of creating a temporary list of the node using
its __iter__() function and then reversing that list just
use the natively provided reverse_iter() method instead
that reduces this wasteful list copying and creating in
the first place.

Also does the same in the pformat() function which was
needlessly creating a temporary list of children nodes
instead of just using the nodes __iter__() functionality
directly.

Change-Id: Ice4001e6d014d2c0a1f7d8b916c60370fd5443a7
2014-12-29 14:19:00 -08:00
Jenkins
4370fd19a5 Merge "Better handle the tree freeze method" 2014-10-18 21:43:05 +00:00
Jenkins
5ce5b23dde Merge "Revamp the symbol lookup mechanism" 2014-10-18 18:25:03 +00:00
Rafael Rivero
de652c770a Typos "searchs"
Misspelling of "searchs" in method index.

Change-Id: Ifb17fc1a4b4df2ea7cbc3a49e9815888dd1d7467
2014-09-20 15:59:43 +00:00
Joshua Harlow
8bbc2fd05c Better handle the tree freeze method
Instead of dynamically replacing the existing method
with a new method, just have the existing method check
if the node has been frozen and immediately abort, this
workers better with decorators, subclassing...

This also unifies how freezing is done across all types
that support it, ensuring that the frozen attribute can
be set by users (if they so choose).

Change-Id: I1e6c6568b7f91765d654d25ca6e68e9b568603fc
2014-09-18 13:52:56 -07:00
Joshua Harlow
185199b910 Add existing types to generated documentation
Also makes some docstring adjustments to make sure
the documentation looks readable (especially the
inline examples).

Part of blueprint top-level-types

Change-Id: Ic6f02ce92449ee23aa9be8645edd8f6f11ee18ab
2014-09-12 21:59:09 +00:00
Joshua Harlow
fa077c953f Revamp the symbol lookup mechanism
To complement the future changes in patterns we also want
to allow the execution of patterns to be affected in a similar
manner so that symbol lookup is no longer as confined as it was.

This change adds in the following:

- Symbol lookup by walking through an atoms contained scope/s.
- Better error messaging when symbols are not found.
- Adjusted & new tests (existing ones work).
- Better logging of the symbol lookup mechanism (helpful
  during debugging, although it is very verbose...)

Part of blueprint taskflow-improved-scoping

Change-Id: Id921a4abd9bf2b7b5c5a762337f8e90e8f1fe194
2014-09-08 13:00:25 -07:00
Joshua Harlow
ade8bb35fa Add a tree type
A tree module will be very useful for tracking tree
structures in taskflow. So to encourage development and
usage of such structures add a type module and helper
classes that can be used perform tree operations on
tree structures.

Change-Id: I63c0653d051aeb4d1ea8a55f0e25fc25ff9e37f1
2014-06-18 14:36:22 -07:00