Skip to content

Create Project Folder Structure: support list of str for leaf folders #1169

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

Conversation

BigRoy
Copy link
Collaborator

@BigRoy BigRoy commented Mar 4, 2025

Changelog Description

Support list[str] for leaf entries in core/project_folder_structure settings to define folder names instead of requiring dicts with empty values

Additional info

Should implement and allow what @MustafaJafar did here.

Would allow this:

{
    "__project_root__": {
        "Assets": {
            "Characters": {
                "NewRobo": {
                    "work": [
                        "cfx",
                        "concept",
                        "modeling",
                        "walkcycle"
                    ]
                },
                "RoboPoro": {
                    "work": [
                        "cfx",
                        "concept",
                        "modeling",
                        "walkcycle"
                    ]
                },
                "RoboMad": {
                    "work": [
                        "cfx",
                        "concept",
                        "modeling",
                        "walkcycle"
                    ]
                }
            }
        }
    }
}

Instead of requiring:

{
    "__project_root__": {
        "Assets": {
            "Characters": {
                "NewRobo": {
                    "work": {
                        "cfx": {},
                        "concept": {},
                        "modeling": {},
                        "walkcycle": {},
                    }
                },
                "RoboPoro": {
                    "work": {
                        "cfx": {},
                        "concept": {},
                        "modeling": {},
                        "walkcycle": {},
                    }
                },
                "RoboMad": {
                    "work": {
                        "cfx": {},
                        "concept": {},
                        "modeling": {},
                        "walkcycle": {},
                    }
                }
            }
        }
    }
}

Testing notes:

  1. Setup ayon+settings://core/project_folder_structure to include leaf (end) folders using just a list of strings.
  2. Creating folder structure should work.

BigRoy added 2 commits March 4, 2025 16:06
…e` settings to define folder names instead of requiring dicts with empty values
@BigRoy BigRoy added community Issues and PRs coming from the community members type: enhancement Improvement of existing functionality or minor addition labels Mar 4, 2025
@BigRoy BigRoy requested a review from MustafaJafar March 4, 2025 15:10
@BigRoy BigRoy self-assigned this Mar 4, 2025
@ynbot ynbot added the size/XS label Mar 4, 2025
Copy link
Contributor

@MustafaJafar MustafaJafar left a comment

Choose a reason for hiding this comment

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

It works!
Tested along with #679

@alainxi
Copy link

alainxi commented Mar 5, 2025

Does not work for me, when tested with #679
It only creates the first ones :
NewRobo is created, but not RoboPoro and RoboMad.
cfx is created, but not concept , modeling, walkcycle.

Also, I prefer the old method (dicts with empty values), but it's still supported, so I'm happy.
The old method makes possible to use a very simple script to create a json from an existing disk folder tree :

import json
import os
def generate_json_tree(path):
    result = {}
    for item in os.listdir(path):
        item_path = os.path.join(path, item)
        if os.path.isdir(item_path):
            result[item] = generate_json_tree(item_path)
        else:
            pass
    return result

root_path = "d:/test/forTreeToJsonConvert"
json_tree = {"{root[work]}/{project[name]}": generate_json_tree(root_path)}

with open("D:/test/folder_tree.json", "w") as f:
    json.dump(json_tree, f, indent=4)

To use list[str] for leaf entries, the script is more convoluted, and creates edge cases.
Here is what I have so far :

import json
import os

def generate_json_tree(path):
    result = {}
    for item in os.listdir(path):
        item_path = os.path.join(path, item)
        if os.path.isdir(item_path):
            sub_tree = generate_json_tree(item_path)
            # If all values in sub_tree are empty lists, convert to a list
            if all(isinstance(v, list) and not v for v in sub_tree.values()):
                result[item] = list(sub_tree.keys())
            else:
                result[item] = sub_tree
    return result

root_path = "d:/test/forTreeToJsonConvert"
json_tree = {"{root[work]}/{project[name]}": generate_json_tree(root_path)}

with open("D:/test/folder_tree.json", "w") as f:
    json.dump(json_tree, f, indent=4)

@MustafaJafar
Copy link
Contributor

MustafaJafar commented Mar 5, 2025

Thank you!
So, I revisited my created folders and I didn't notice the last time it created the folders in strange way.
the list of folders are nested folders.
image

It should look like this (moved them manually to show how they should be created.)
image

@MustafaJafar MustafaJafar self-requested a review March 5, 2025 10:47
@BigRoy
Copy link
Collaborator Author

BigRoy commented Mar 5, 2025

Thanks - will double check what's up. How interesting to see everyone seems to jump on this one this quickly :D haha

@BigRoy BigRoy marked this pull request as draft March 5, 2025 10:49
@BigRoy
Copy link
Collaborator Author

BigRoy commented Mar 5, 2025

There's no means to deprecated the old @alainxi so that should continue to work.

@MustafaJafar try again - it should now work with 7baf208

@BigRoy BigRoy marked this pull request as ready for review March 5, 2025 13:52
@MustafaJafar
Copy link
Contributor

I got this printed in the console window but no folders were created.

[
    [
        "__project_root__",
        "Assets",
        "Characters",
        "NewRobo",
        "work",
        "cfx"
    ],
    [
        "__project_root__",
        "Assets",
        "Characters",
        "NewRobo",
        "work",
        "concept"
    ],
    [
        "__project_root__",
        "Assets",
        "Characters",
        "NewRobo",
        "work",
        "modeling"
    ],
    [
        "__project_root__",
        "Assets",
        "Characters",
        "NewRobo",
        "work",
        "walkcycle"
    ],
    [
        "__project_root__",
        "Assets",
        "Characters",
        "RoboPoro",
        "work",
        "cfx"
    ],
    [
        "__project_root__",
        "Assets",
        "Characters",
        "RoboPoro",
        "work",
        "concept"
    ],
    [
        "__project_root__",
        "Assets",
        "Characters",
        "RoboPoro",
        "work",
        "modeling"
    ],
    [
        "__project_root__",
        "Assets",
        "Characters",
        "RoboPoro",
        "work",
        "walkcycle"
    ],
    [
        "__project_root__",
        "Assets",
        "Characters",
        "RoboMad",
        "work",
        "cfx"
    ],
    [
        "__project_root__",
        "Assets",
        "Characters",
        "RoboMad",
        "work",
        "concept"
    ],
    [
        "__project_root__",
        "Assets",
        "Characters",
        "RoboMad",
        "work",
        "modeling"
    ],
    [
        "__project_root__",
        "Assets",
        "Characters",
        "RoboMad",
        "work",
        "walkcycle"
    ]
]

Copy link
Contributor

@MustafaJafar MustafaJafar left a comment

Choose a reason for hiding this comment

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

It works
image

@BigRoy BigRoy requested a review from iLLiCiTiT March 5, 2025 14:11
@alainxi
Copy link

alainxi commented Mar 5, 2025

I tested the new version. Now it works for both methods of leaf entries :

  • dicts with empty values
  • list[str]

@BigRoy BigRoy requested a review from iLLiCiTiT March 10, 2025 10:52
@MustafaJafar MustafaJafar merged commit f54096a into ynput:develop Mar 14, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Issues and PRs coming from the community members size/XS type: enhancement Improvement of existing functionality or minor addition
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants