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..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() @@ -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) diff --git a/packages/uipath/tests/cli/test_new.py b/packages/uipath/tests/cli/test_new.py index c8da8dead..c3ffbbbfe 100644 --- a/packages/uipath/tests/cli/test_new.py +++ b/packages/uipath/tests/cli/test_new.py @@ -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 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" },