Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions sdk/python/packages/flet/src/flet/cli/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
default=None,
help="custom TCP port to run Flet app on",
)
parser.add_argument(
"-m",
"--module",
dest="module",
action="store_true",
default=False,
help="treat the script as a python module path as opposed to a file path",
)
parser.add_argument(
"-d",
"--directory",
Expand Down Expand Up @@ -74,9 +82,17 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:

def handle(self, options: argparse.Namespace) -> None:
# print("RUN COMMAND", options)
script_path = options.script
if not os.path.isabs(options.script):
script_path = str(Path(os.getcwd()).joinpath(options.script).resolve())
if options.module:
script_path = str(options.script).replace(".", "/")
if os.path.isdir(script_path):
script_path += "/__main__.py"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would / work on Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thankfully yes, I'm on windows and python can handle it apparently. Even when I mix / and \ it seems.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.path.join ?

else:
script_path += ".py"
else:
script_path = options.script

if not os.path.isabs(script_path):
script_path = str(Path(os.getcwd()).joinpath(script_path).resolve())

if not Path(script_path).exists():
print(f"File not found: {script_path}")
Expand All @@ -99,7 +115,8 @@ def handle(self, options: argparse.Namespace) -> None:
)

my_event_handler = Handler(
[sys.executable, "-u", script_path],
[sys.executable, "-u"] + ["-m"] * options.module +
[options.script if options.module else script_path],
None if options.directory or options.recursive else script_path,
port,
uds_path,
Expand Down