Skip to content

Commit

Permalink
Error out if output path already exists (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani authored May 23, 2024
1 parent e0ebc36 commit 12d1004
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/packaged/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def __init__(self, python_version: str) -> None:
self.python_version = python_version


class OutputPathExists(Exception):
"""Raised when the output path already exists."""


def create_package(
source_directory: str | None,
output_path: str,
Expand All @@ -46,6 +50,9 @@ def create_package(
quiet: bool = False,
) -> None:
"""Create the makeself executable, with the startup script in it."""
if os.path.exists(output_path):
raise OutputPathExists

if source_directory is None:
source_directory = tempfile.mkdtemp()

Expand Down
9 changes: 8 additions & 1 deletion src/packaged/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from packaged import (
DEFAULT_PYTHON_VERSION,
OutputPathExists,
PythonNotAvailable,
SourceDirectoryNotFound,
create_package,
Expand All @@ -23,7 +24,7 @@

def error(message: str) -> None:
"""Print error message"""
print(f"\033[1;31mError:\033[m {message}")
print(f"\033[1;31mError:\033[m {message}", file=sys.stderr)


def cli(argv: list[str] | None = None) -> int:
Expand Down Expand Up @@ -91,5 +92,11 @@ def cli(argv: list[str] | None = None) -> int:
except PythonNotAvailable as exc:
error(f"Python {exc.python_version!r} is not available for download.")
return 5
except OutputPathExists:
err_msg = f"output path {config.output_path!r} already exists"
if config.output_path == ".":
err_msg += "\nConsider giving a filename, like './myapp.bin'"
error(err_msg)
return 6

return 0

0 comments on commit 12d1004

Please sign in to comment.