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

Refactor lib/init/grass.py to extract the resuable parts #4181

Open
wenzeslaus opened this issue Aug 14, 2024 · 1 comment
Open

Refactor lib/init/grass.py to extract the resuable parts #4181

wenzeslaus opened this issue Aug 14, 2024 · 1 comment
Labels
enhancement New feature or request Python Related code is in Python

Comments

@wenzeslaus
Copy link
Member

To be clear about the goal of some of the refactoring PRs for lib/init/grass.py: The lib/init/grass.py file is currently very long with a lot of code accumulated over the years. While the structure of the code improved over years, the functionality is not available for reuse elsewhere.

I'm aiming at refactoring of some of the code there so that the functionality can be reused in grass.script.setup. In simplified terms, the lib/init/grass.py file should look like this:

# ... helper functions

def main():
    find_packages()
    import grass.app
    grass.app.main()

# ... "if name equals main" block

I'm not saying that's what I will achieve because that's not currently my goal, but that's the idea in terms of dependencies. Nothing depends or should depend on lib/init/grass.py. There should be only limited code in lib/init/grass.py. Most of it should be in grass.app, grass.grassdb, and grass.script.

What I'm aiming at is having all the initialization functions in the library, that includes runtime, session files, locking, project management, but does not necessarily include functionality related to the main grass executable only such as command line parameters and interactive-only components.

@wenzeslaus wenzeslaus added enhancement New feature or request Python Related code is in Python labels Aug 14, 2024
@echoix
Copy link
Member

echoix commented Aug 14, 2024

The cherry on top would be that doing

python -m grass

Would simply open the grass application (either console or gui, depending on where we are at).
All it takes is a __main__.py file, which calls what it needs to start GRASS (as an application). That's what things like unittest to have it run like an app but also like a module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Python Related code is in Python
Projects
None yet
Development

No branches or pull requests

2 participants