Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create tree from list of indented strings #43

Closed
Sup3rGeo opened this issue Mar 11, 2018 · 5 comments · Fixed by #48
Closed

Create tree from list of indented strings #43

Sup3rGeo opened this issue Mar 11, 2018 · 5 comments · Fixed by #48

Comments

@Sup3rGeo
Copy link

Sup3rGeo commented Mar 11, 2018

Hi,

I am using anytree to generate a tree-view of pytest hooks based on a log file with indented hooks. pytest-dev/pytest#3261

For that I needed to create a function to convert a list of indented strings to a tree. Apparently another users on stackoverflow have needed it:
https://codereview.stackexchange.com/questions/176391/parsing-indented-text-and-inserting-its-data-into-a-tree
https://stackoverflow.com/questions/17858404/creating-a-tree-deeply-nested-dict-from-an-indented-text-file-in-python
https://stackoverflow.com/questions/32101253/converting-a-string-to-a-tree-structure-in-python?rq=1

I have created the following script for doing this and it is quite simple:
https://github.com/Sup3rGeo/pytest/blob/master/doc/pytesthooks.py

I believe it makes sense to make this part of anytree as a "indented strings importer".

So if you agree I would gladly add a pull request for this. Thanks!

@c0fec0de
Copy link
Owner

c0fec0de commented Mar 19, 2018

Good idea to have a IndentedStringImporter class.

Please add an optional callback for creating the single node class instance as the nodecls attribute of the DictImporter does (http://anytree.readthedocs.io/en/latest/importer/dictimporter.html#module-anytree.importer.dictimporter)

Tests with 100% coverage would be highly appreciated.

@Sup3rGeo
Copy link
Author

pull request made (#48)

@Sup3rGeo
Copy link
Author

Hi! I see the documentation for the feature, but the PyPI package v2.4.3 I installed doesn't seem to have it.

@c0fec0de
Copy link
Owner

c0fec0de commented Aug 3, 2018

I need to release the package. The documentation got accidentally updated. I'll fix that.

@c0fec0de c0fec0de closed this as completed Aug 3, 2018
@stevenlis
Copy link

I think the package, but could found a easy way to costruct a tree from a list like the following:

[['harry', 'jane', 'diane', 'mary'],
 ['harry', 'jane', 'mark'],
 ['harry', 'jane', 'diane', 'george', 'jill'],
 ['harry', 'bill']]

Maybe I missed something?

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 a pull request may close this issue.

3 participants