0

Updating the question.

I am developing a command-line tool for a framework.
and I am struggling with how to detect if the current directory is a project of my framework.

I have two solutions in mind.

  1. some hidden file in the directory
  2. detect the project structure by files and folders.

What do you think is the best approach?

Thank you, Shay

Thank you very much

shay te
  • 1,028
  • 3
  • 12
  • 23
  • 2
    Please, spend some time reading ["How to create a Minimal, Complete, and Verifiable example"](https://stackoverflow.com/help/mcve) and ["How to ask"](https://stackoverflow.com/help/how-to-ask). You will get better results by following the tips in those articles. – accdias Jan 05 '21 at 16:20
  • 1
    Does this answer your question? [Recursively compare two directories to ensure they have the same files and subdirectories](https://stackoverflow.com/questions/4187564/recursively-compare-two-directories-to-ensure-they-have-the-same-files-and-subdi) – Roberto Caboni Jan 05 '21 at 16:21
  • 2
    can you please clarify the type of input, the code will except, i.e code snippet, file name, certain strings, which it will check against given path, be it dir or file – sadbro Jan 05 '21 at 16:44
  • 1
    you have `os.listdir()`, `os.walk()` to get filenames in folder(s) and then you can check if they match to what need. – furas Jan 05 '21 at 17:10

1 Answers1

0

In my opinion, a good idea would be to either have a project directory structure that you can use a signature for the project/framework, that you can use within the tool as a list of signature-like structures, for example PROJECT_STRUCTURE_SIGNATURES = [ "custom_project", "custom_project/tests", "custom_project/build", "custom_project/config", "config/environments" ] and then just check if any(signature in os.getcwd() for signature in PROJECT_STRUCTURE_SIGNATURES).

if the project structure is not too complex, I suppose that would be a start in order to identify the requirements that you're looking for.

However, if this is not the case, then I suppose a dictionary-like structure that you could use to traverse the key-value pairs similar to the project's file structure and check the current directory against those would be a better idea, where if none of the elements from the nested dictionary traversal matches, then the directory is not within the project structure.