Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Extend PyModuleLoader and SymbolGraph to Support Multiple User-Specified Directories #411

Open
emrgnt-cmplxty opened this issue Aug 3, 2023 · 0 comments

Comments

@emrgnt-cmplxty
Copy link
Owner

Is your feature request related to a problem? Please describe.
The current implementation of the PyModuleLoader and SymbolGraph classes is designed to work with a single file path. This limitation restricts the ability to handle multiple projects or directories. Extending these classes to support multiple user-specified directories would increase flexibility and usability.

Describe the solution you'd like
I propose to introduce a PyModuleLoaderManager class to manage multiple instances of PyModuleLoader, each responsible for a different directory. This manager would have methods to add loaders, fetch AST modules, and delegate other operations as needed.

For the SymbolGraph class, additional work will be needed to ensure that it can handle symbols and relationships across multiple directories.

Here is a rough sketch of the proposed PyModuleLoaderManager:

class PyModuleLoaderManager:
    def __init__(self):
        self.loaders: List[PyModuleLoader] = []

    def add_loader(self, root_fpath: str, project_name: str):
        loader = PyModuleLoader()
        loader.initialize(root_fpath, project_name)
        self.loaders.append(loader)

    def fetch_ast_module(self, module_dotpath: str) -> Optional[Module]:
        for loader in self.loaders:
            if module_dotpath in loader:
                return loader.fetch_ast_module(module_dotpath)
        return None

    # Add similar delegate methods for other operations as needed

# Usage example:
manager = PyModuleLoaderManager()
manager.add_loader("/path/to/project1", "project1")
manager.add_loader("/path/to/project2", "project2")
module = manager.fetch_ast_module("some.dot.path")

Describe alternatives you've considered
An alternative approach could be to refactor the existing classes to handle multiple directories directly, but introducing a manager class provides a cleaner separation of concerns and aligns with the Single Responsibility Principle.

Additional context
The proposed changes are crucial for projects that need to work with multiple directories or sub-projects. Care must be taken to ensure that existing functionalities remain intact and that the new features are adequately tested.

Please adjust the issue's content as needed, based on your project's specific requirements and guidelines.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant