Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/uipath/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath"
version = "2.15.15"
version = "2.15.16"
description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools."
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down
26 changes: 25 additions & 1 deletion packages/uipath/src/uipath/_cli/cli_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,21 @@ def _scaffold_agent(name: str, agent_framework: str | None) -> MiddlewareResult:
help="Directory to scaffold the project into, created when missing. "
"Defaults to the current directory.",
)
@click.option(
"--force",
is_flag=True,
default=False,
help="Overwrite main.py, pyproject.toml and uipath.json when they already "
"exist. Applies to function projects; agent framework scaffolds decide "
"for themselves.",
)
@track_command("new")
def new(
name: str, project_type: str, agent_framework: str | None, target_dir: str | None
name: str,
project_type: str,
agent_framework: str | None,
target_dir: str | None,
force: bool,
):
"""Generate a quick-start project."""
directory = os.path.abspath(target_dir) if target_dir else os.getcwd()
Expand Down Expand Up @@ -226,6 +238,18 @@ def new(
"function project."
)

existing = [
f
for f in ("main.py", PYTHON_CONFIGURATION_FILE, UIPATH_CONFIG_FILE)
if os.path.exists(os.path.join(directory, f))
]
if existing and not force:
console.error(
f"Refusing to overwrite existing {', '.join(repr(f) for f in existing)} "
f"in {target_dir or 'the current directory'}. "
"Run `uipath new` in an empty folder, or pass --force to overwrite."
)

location = f"in '{target_dir}'" if target_dir else "in current directory"
with console.spinner(f"Creating new project {name} {location} ..."):
generate_script(directory)
Expand Down
26 changes: 23 additions & 3 deletions packages/uipath/tests/cli/test_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,35 @@ def test_new_project_without_name(self, runner: CliRunner, temp_dir: str) -> Non
def test_new_project_with_existing_files(
self, runner: CliRunner, temp_dir: str
) -> None:
"""Test creating a new project when files already exist."""
"""An existing project is refused and left untouched."""
with runner.isolated_filesystem(temp_dir=temp_dir):
# Create existing files
with open("main.py", "w") as f:
f.write("print('Existing file')")

result = runner.invoke(cli, ["new", "my_project"])
result = runner.invoke(cli, ["new", "my_project", "--type", "function"])
assert result.exit_code == 1
assert "Refusing to overwrite existing 'main.py'" in result.output
assert "--force" in result.output
with open("main.py") as f:
assert f.read() == "print('Existing file')"
assert not os.path.exists("pyproject.toml")
assert not os.path.exists("uipath.json")

def test_new_project_with_existing_files_force_overwrites(
self, runner: CliRunner, temp_dir: str
) -> None:
"""--force keeps the in-place overwrite."""
with runner.isolated_filesystem(temp_dir=temp_dir):
with open("main.py", "w") as f:
f.write("print('Existing file')")

result = runner.invoke(
cli, ["new", "my_project", "--type", "function", "--force"]
)
assert result.exit_code == 0
assert "Created 'main.py' file." in result.output
assert os.path.exists("pyproject.toml")
assert os.path.exists("uipath.json")

def test_new_dir_scaffolds_into_that_directory(
self, runner: CliRunner, temp_dir: str
Expand Down
10 changes: 5 additions & 5 deletions packages/uipath/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading