Skip to content

Commit

Permalink
Bugfix: flet pack --distpath deletes dist directory (#2500)
Browse files Browse the repository at this point in the history
* Bugfix: `flet pack --distpath` deletes `dist` directory
`flet pack --distpath DISTPATH` deletes "dist" directory even
when `DISTPATH` is specified. The solution is to ask the user whether
to delete the directories.

* Add non-interactive option to `flet pack` command.
  • Loading branch information
taaaf11 committed Feb 2, 2024
1 parent 417607f commit f0d6109
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions sdk/python/packages/flet/src/flet/cli/commands/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,54 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
action="store_true",
help="Using this option creates a Manifest that will request elevation upon application start.(Windows)",
)
parser.add_argument(
"-y",
"--yes",
dest="non_interactive",
default=False,
action="store_true",
help="Non-interactive mode.",
)

def handle(self, options: argparse.Namespace) -> None:
is_dir_not_empty = lambda dir: os.path.isdir(dir) and len(os.listdir(dir)) != 0

# delete "build" directory
build_dir = os.path.join(os.getcwd(), "build")
if os.path.exists(build_dir):
shutil.rmtree(build_dir, ignore_errors=True)
if is_dir_not_empty(build_dir):
if options.non_interactive:
shutil.rmtree(build_dir, ignore_errors=True)
else:
delete_dir_prompt = input(
f'Do you want to delete "build" directory? (y/n) '
)
if not delete_dir_prompt.lower() == "n":
shutil.rmtree(build_dir, ignore_errors=True)
else:
print('Failing... "build" directory must be empty to proceed.')
exit(1)

# delete "dist" directory or DISTPATH directory
# if --distpath cli option is specified
if options.distpath:
dist_dir = os.path.join(os.getcwd(), options.distpath)
else:
dist_dir = os.path.join(os.getcwd(), "dist")

# delete "dist" directory
dist_dir = os.path.join(os.getcwd(), "dist")
if os.path.exists(dist_dir):
shutil.rmtree(dist_dir, ignore_errors=True)
if is_dir_not_empty(dist_dir):
if options.non_interactive:
shutil.rmtree(dist_dir, ignore_errors=True)
else:
delete_dir_prompt = input(
f'Do you want to delete "{os.path.basename(dist_dir)}" directory? (y/n) '
)
if not delete_dir_prompt.lower() == "n":
shutil.rmtree(dist_dir, ignore_errors=True)
else:
print(
f'Failing... DISTPATH "{os.path.basename(dist_dir)}" directory must be empty to proceed.'
)
exit(1)

try:
import PyInstaller.__main__
Expand Down

0 comments on commit f0d6109

Please sign in to comment.