From 68f2aa86ba4c5a134aeab193cb65ec27b8d60cc5 Mon Sep 17 00:00:00 2001 From: Ray Ge Date: Thu, 3 Dec 2026 16:47:09 -0800 Subject: [PATCH 1/2] fix(cli): refuse to overwrite an existing project in uipath new Running `uipath new ` for a function project in a folder that already had main.py, pyproject.toml or uipath.json silently replaced them. Exit 1 naming the existing files instead. Co-Authored-By: Claude Opus 5.5 (1M context) --- packages/uipath/pyproject.toml | 2 +- packages/uipath/src/uipath/_cli/cli_new.py | 12 ++++++++++++ packages/uipath/tests/cli/test_new.py | 14 +++++++++----- packages/uipath/uv.lock | 10 +++++----- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/packages/uipath/pyproject.toml b/packages/uipath/pyproject.toml index dae9eebae..41d086e8f 100644 --- a/packages/uipath/pyproject.toml +++ b/packages/uipath/pyproject.toml @@ -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" diff --git a/packages/uipath/src/uipath/_cli/cli_new.py b/packages/uipath/src/uipath/_cli/cli_new.py index 7035bff03..ae11a42e6 100644 --- a/packages/uipath/src/uipath/_cli/cli_new.py +++ b/packages/uipath/src/uipath/_cli/cli_new.py @@ -226,6 +226,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: + 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." + ) + location = f"in '{target_dir}'" if target_dir else "in current directory" with console.spinner(f"Creating new project {name} {location} ..."): generate_script(directory) diff --git a/packages/uipath/tests/cli/test_new.py b/packages/uipath/tests/cli/test_new.py index c8da8dead..ed3775e0a 100644 --- a/packages/uipath/tests/cli/test_new.py +++ b/packages/uipath/tests/cli/test_new.py @@ -63,15 +63,19 @@ 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"]) - assert result.exit_code == 0 - assert "Created 'main.py' file." in result.output + 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 "empty folder" 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_dir_scaffolds_into_that_directory( self, runner: CliRunner, temp_dir: str diff --git a/packages/uipath/uv.lock b/packages/uipath/uv.lock index ee06f3d06..ee8cfac5f 100644 --- a/packages/uipath/uv.lock +++ b/packages/uipath/uv.lock @@ -1,16 +1,16 @@ version = 1 -revision = 3 +revision = 5 requires-python = ">=3.11" [options] -exclude-newer = "2026-11-24T09:19:03.0927496Z" +exclude-newer = "0001-01-01T00:00:00Z" # This has no effect and is included for backwards compatibility when using relative exclude-newer values. exclude-newer-span = "P2D" [options.exclude-newer-package] +uipath-core = false uipath-ipc = false -uipath-runtime = false uipath-platform = false -uipath-core = false +uipath-runtime = false [[package]] name = "aiohappyeyeballs" @@ -2720,7 +2720,7 @@ wheels = [ [[package]] name = "uipath" -version = "2.15.15" +version = "2.15.16" source = { editable = "." } dependencies = [ { name = "applicationinsights" }, From d19a818b093df3f0698b25627a2356e4458d8b49 Mon Sep 17 00:00:00 2001 From: Ray Ge Date: Thu, 3 Dec 2026 17:07:25 -0800 Subject: [PATCH 2/2] feat(cli): add --force to uipath new to overwrite an existing project Co-Authored-By: Claude Opus 5.5 (1M context) --- packages/uipath/src/uipath/_cli/cli_new.py | 18 +++++++++++++++--- packages/uipath/tests/cli/test_new.py | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/packages/uipath/src/uipath/_cli/cli_new.py b/packages/uipath/src/uipath/_cli/cli_new.py index ae11a42e6..22c87b2fb 100644 --- a/packages/uipath/src/uipath/_cli/cli_new.py +++ b/packages/uipath/src/uipath/_cli/cli_new.py @@ -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() @@ -231,11 +243,11 @@ def new( for f in ("main.py", PYTHON_CONFIGURATION_FILE, UIPATH_CONFIG_FILE) if os.path.exists(os.path.join(directory, f)) ] - if existing: + 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." + "Run `uipath new` in an empty folder, or pass --force to overwrite." ) location = f"in '{target_dir}'" if target_dir else "in current directory" diff --git a/packages/uipath/tests/cli/test_new.py b/packages/uipath/tests/cli/test_new.py index ed3775e0a..c3ffbbbfe 100644 --- a/packages/uipath/tests/cli/test_new.py +++ b/packages/uipath/tests/cli/test_new.py @@ -71,12 +71,28 @@ def test_new_project_with_existing_files( 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 "empty folder" 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 ) -> None: