Skip to content

Commit

Permalink
PyInstaller integration (#34)
Browse files Browse the repository at this point in the history
* Test project.entry-points

* Add 1st version of PyInstaller hooks

* Package Fletd, custom host binding for Fletd

* Remove pyinstaller dependency

* Start Fletd without window on Windows
  • Loading branch information
FeodorFitsner authored Jun 21, 2022
1 parent 3eed963 commit b7b9fb1
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 4 deletions.
5 changes: 5 additions & 0 deletions sdk/python/flet/__pyinstaller/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os


def get_hook_dirs():
return [os.path.dirname(__file__)]
11 changes: 11 additions & 0 deletions sdk/python/flet/__pyinstaller/hook-flet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

# package entire "bin" folder
bin_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, "bin"))

# package "bin/fletd" only
if os.getenv("PACKAGE_FLETD_ONLY"):
bin_path = os.path.join(bin_path, "fletd*")

# binaries = [(bin_path, "flet/bin")]
binaries = [(bin_path, "flet/bin")]
5 changes: 5 additions & 0 deletions sdk/python/flet/__pyinstaller/rthooks.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
'flet': [
'pyi_rth_localhost_fletd.py'
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import logging
import os

logging.info("Running PyInstaller runtime hook for Flet...")

os.environ["FLET_SERVER_IP"] = "localhost"
6 changes: 6 additions & 0 deletions sdk/python/flet/flet.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,19 @@ def _start_flet_server(port, attached, assets_dir, web_renderer):
log_level_name = logging.getLevelName(log_level).lower()
args.extend(["--log-level", log_level_name])

startupinfo = None
if is_windows():
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

subprocess.Popen(
args,
env=fletd_env,
creationflags=creationflags,
start_new_session=start_new_session,
stdout=subprocess.DEVNULL if log_level >= logging.WARNING else None,
stderr=subprocess.DEVNULL if log_level >= logging.WARNING else None,
startupinfo=startupinfo,
)

return port
Expand Down
6 changes: 4 additions & 2 deletions sdk/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ tests = [
"pytest>=6.1.2",
]
dev = [
"pre-commit>=2.17.0",
]
"pre-commit>=2.17.0"]

[project.entry-points.pyinstaller40]
hook-dirs = "flet.__pyinstaller:get_hook_dirs"

[build-system]
requires = ["pdm-pep517"]
Expand Down
5 changes: 5 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
defaultAppURL = "http://localhost:3000"
defaultServerPort = 8550
serverPort = "SERVER_PORT"
serverIP = "SERVER_IP"
forceSSL = "FORCE_SSL"
defaultWebSocketMaxMessageSize = 2097152 // 2 MB
wsMaxMessageSize = "WS_MAX_MESSAGE_SIZE"
Expand Down Expand Up @@ -170,6 +171,10 @@ func ServerPort() int {
return viper.GetInt(serverPort)
}

func ServerIP() string {
return viper.GetString(serverIP)
}

func MaxWebSocketMessageSize() int {
return viper.GetInt(wsMaxMessageSize)
}
Expand Down
5 changes: 3 additions & 2 deletions server/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,12 @@ func Start(ctx context.Context, wg *sync.WaitGroup, serverPort int) {
}
})

log.Println("Starting server on port", serverPort)
addr := fmt.Sprintf("%s:%d", config.ServerIP(), serverPort)
log.Println("Starting server on", addr)

// Start and run the server
srv := &http.Server{
Addr: fmt.Sprintf(":%d", serverPort),
Addr: addr,
Handler: router,
}

Expand Down

0 comments on commit b7b9fb1

Please sign in to comment.