tuttle-dev / tuttle

🪰 Tuttle - time and money management for freelancers
GNU General Public License v3.0
61 stars 12 forks source link

Distribution: Refactor into functioning Python package #216

Closed clstaudt closed 1 year ago

clstaudt commented 1 year ago

Distributing the project requires that the entire code is packaged as a proper Python package. This is currently not the case for the app code.

To verify that Python package is properly structured:

  1. cd <project_dir>
  2. pip install -e .
  3. cd <out_of_project_dir>
  4. python
  5. import tuttle

To verify that the Package can be packaged as an executable:

  1. flet pack tuttle/app/app.py --name Tuttle --icon tuttle/app/assets/icon/macos/AppIcon.icns --product-name Tuttle --product-version 1.0
  2. run the resulting binary distribution from the command line and watch for errors in the logs
clstaudt commented 1 year ago

@vlad-ed-git I think the code should live in a package called tuttle and this package should be installable and distributable. I started moving the app folder into the tuttle module and turning each folder into a package. #217

The imports are no longer working, and since there are massive amounts of import lines a lot of changes may be necessary.

Do you have a suggestion on how to tackle this?

clstaudt commented 1 year ago

When running the bundled executable:

Traceback (most recent call last):
  File "app/app.py", line 14, in <module>
    from auth.view import ProfileScreen, SplashScreen
ModuleNotFoundError: No module named 'auth'
[46878] Failed to execute script 'app' due to unhandled exception: No module named 'auth'
[46878] Traceback:
Traceback (most recent call last):
  File "app/app.py", line 14, in <module>
    from auth.view import ProfileScreen, SplashScreen
ModuleNotFoundError: No module named 'auth'
clstaudt commented 1 year ago

@vlad-ed-git An attempt at restructuring:

https://github.com/tuttle-dev/tuttle/tree/dev-packaging

To test that imports are correct without packaging every time, run from another directory, e.g.:

python ~/Documents/Work/Projects/PrototypeFund/Dev/tuttle/app.py        

(I suppose the app was only working when you ran it from its own directory, otherwise none of the imports are working.)

It seems to me like every local import in the app code needs to be touched, rewritten as a relative import:

from ..auth.intent import AuthIntent
from ..core import utils, views
from ..core.abstractions import TView, TViewParams

One reason why I wasn't such a fan of a large number of import lines. But I guess it's necessary to try it out. Do you see an alternative to this?