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

Packaging fails when using type aliases with explicit type #4007

Closed
1 task done
torablien opened this issue Sep 18, 2024 · 6 comments · Fixed by #4122
Closed
1 task done

Packaging fails when using type aliases with explicit type #4007

torablien opened this issue Sep 18, 2024 · 6 comments · Fixed by #4122
Assignees
Labels
bug Something isn't working packaging Related to app packaging

Comments

@torablien
Copy link

torablien commented Sep 18, 2024

Duplicate Check

Describe the bug

When packaging a Flet app (e.g. via flet build macos), type aliases seem to cause build failures (but works fine when running with flet run). On smaller applications, this is flagged in verbose mode as a syntax error, but in larger applications (seemingly defined as ones with many dependencies even if no real logic), this fails opaquely.

Example error in smaller application:

Listing '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/__pypackages__/sniffio/_tests'...
Compiling '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/__pypackages__/sniffio/_tests/__init__.py'...
Compiling '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/__pypackages__/sniffio/_tests/test_sniffio.py'...
Compiling '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/__pypackages__/sniffio/_version.py'...
Listing '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/__pypackages__/sniffio-1.3.1.dist-info'...
Listing '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/assets'...
Compiling '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/main.py'...
***   File "/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/main.py", line 4
    type Vector = list[float]
         ^^^^^^
SyntaxError: invalid syntax
[20:24:15] Deleting Flutter bootstrap directory /var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/flet_flutter_build_Txn9fVXWcE                                                                                                                           
           Error building Flet app - see the log of failed command above.                                                                                                                                                                                
           Run subprocess: ['/Users/neil/Code/flutter/bin/flutter', 'doctor']      

Example error in larger application:

Compiling '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempWb6cOI/venv/lib/python3.12/site-packages/yaml/scanner.py'...
Compiling '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempWb6cOI/venv/lib/python3.12/site-packages/yaml/serializer.py'...
Compiling '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempWb6cOI/venv/lib/python3.12/site-packages/yaml/tokens.py'...
Listing '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempWb6cOI/venv/share'...
Listing '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempWb6cOI/venv/share/man'...
Listing '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempWb6cOI/venv/share/man/man1'...
[20:32:35] Deleting Flutter bootstrap directory /var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/flet_flutter_build_JsOzp4wfPt                                                                                                                           
           Error building Flet app - see the log of failed command above.                                                                                                                                                                                
           Run subprocess: ['/Users/neil/Code/flutter/bin/flutter', 'doctor']       

Code sample

Running flet build macos -vv on simple Hello World app.

Failing:

import flet as ft


type Vector = list[float]


class VectorDB:
    def __init__(self):
        self.db: dict[str, Vector] = {}


def main(page: ft.Page):
    vector_db = VectorDB()
    page.add(ft.SafeArea(ft.Text("Hello, Flet!")))


ft.app(main)

Works:

import flet as ft


class VectorDB:
    def __init__(self):
        self.db: dict[str, list[float]] = {}


def main(page: ft.Page):
    vector_db = VectorDB()
    page.add(ft.SafeArea(ft.Text("Hello, Flet!")))


ft.app(main)

Both work when running via flet run

The only difference between smaller vs larger app re the missing error logs is the amount of requirements in requirements.txt. Small app has few to no requirements where the large app has many (even though the app remains just hello world).

To reproduce

Run flet create hello_world and add a type alias declaration to main.py (or any file). Then run flet build macos -vv.

Operating System

macOS - M1 Pro

Operating system details

Sonoma 14.5

Flet version

0.24.1

Python version

Running Python 3.12.3

Regression

I'm not sure / I don't know

@ndonkoHenri ndonkoHenri added bug Something isn't working packaging Related to app packaging performance Related to Flet's performance. and removed performance Related to Flet's performance. labels Sep 18, 2024
@torablien torablien changed the title Packaging fails when using type aliases Packaging fails when using type aliases with explicit type Sep 23, 2024
@torablien
Copy link
Author

torablien commented Sep 23, 2024

Notably, this doesn't seem to fail if you just do Vector = list[float] instead of type Vector = list[float] (with the type statement). Python docs explicitly say to use the a type operator here but this workaround seems to work.

@ndonkoHenri
Copy link
Contributor

ndonkoHenri commented Sep 23, 2024

This happens because type was introduced in Python 3.12, but when packaging an app atm, Py3.11.6 is used by Flet(serious-python) instead.

Upgrade to a higher Py version will happen through serious-python.

@torablien
Copy link
Author

Thanks, that's helpful and also explains why I am running into various other SyntaxError issues like with @override which was also introduced in 3.12.

As a suggestion, maybe the build command can provide a warning if the current Python version is > than the one used in packaging?

@ndonkoHenri
Copy link
Contributor

As a suggestion, maybe the build command can provide a warning if the current Python version is > than the one used in packaging?

Nice suggestion.

@kentbull
Copy link

Is there anything I could do to help upgrade serious-python to Python 3.12.3+? I'd gladly submit a PR because I need this.

@kentbull
Copy link

kentbull commented Sep 27, 2024

This may be addressed by flet-dev/serious-python#109.

There are number of dependent PRs in Kivy/kivy-ios and python-for-android that need to be tested, merged, and added to serious-python in order to unblock this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working packaging Related to app packaging
Projects
None yet
4 participants