From bc2b93db1bd2ea1ede206a7a81bc88e3db217ff8 Mon Sep 17 00:00:00 2001 From: Ying Chen Date: Sun, 7 Apr 2024 19:03:38 +0800 Subject: [PATCH] [Internal]Add executable path to environment variable to avoid start pfs failed in some environment (#2660) # Description Please add an informative description that covers that changes made by the pull request and link all relevant issues. # All Promptflow Contribution checklist: - [ ] **The pull request does not introduce [breaking changes].** - [ ] **CHANGELOG is updated for new features, bug fixes or other significant changes.** - [ ] **I have read the [contribution guidelines](../CONTRIBUTING.md).** - [ ] **Create an issue and link to the pull request to get dedicated review from promptflow team. Learn more: [suggested workflow](../CONTRIBUTING.md#suggested-workflow).** ## General Guidelines and Best Practices - [ ] Title of the pull request is clear and informative. - [ ] There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md). ### Testing Guidelines - [ ] Pull request includes test coverage for the included changes. Co-authored-by: Ying Chen <2601502859@qq.com> --- src/promptflow-devkit/promptflow/_cli/_pf/_service.py | 7 +++++++ src/promptflow/tests/sdk_pfs_test/e2etests/test_cli.py | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/promptflow-devkit/promptflow/_cli/_pf/_service.py b/src/promptflow-devkit/promptflow/_cli/_pf/_service.py index 0b71e9ff47e..8bc484d2a7b 100644 --- a/src/promptflow-devkit/promptflow/_cli/_pf/_service.py +++ b/src/promptflow-devkit/promptflow/_cli/_pf/_service.py @@ -202,6 +202,13 @@ def validate_port(port, force_start): sys.stdout = old_stdout sys.stderr = old_stderr else: + # Add executable script dir to PATH to make sure the subprocess can find the executable, especially in notebook + # environment which won't add it to system path automatically. + python_dir = os.path.dirname(sys.executable) + executable_dir = os.path.join(python_dir, "Scripts") if platform.system() == "Windows" else python_dir + if executable_dir not in os.environ["PATH"].split(os.pathsep): + os.environ["PATH"] = executable_dir + os.pathsep + os.environ["PATH"] + # Start a pfs process using detach mode. It will start a new process and create a new app. So we use environment # variable to pass the debug mode, since it will inherit parent process environment variable. if platform.system() == "Windows": diff --git a/src/promptflow/tests/sdk_pfs_test/e2etests/test_cli.py b/src/promptflow/tests/sdk_pfs_test/e2etests/test_cli.py index 5740180293d..5e9a92ce4ba 100644 --- a/src/promptflow/tests/sdk_pfs_test/e2etests/test_cli.py +++ b/src/promptflow/tests/sdk_pfs_test/e2etests/test_cli.py @@ -2,6 +2,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # --------------------------------------------------------- +import os +import platform import subprocess import sys @@ -56,6 +58,9 @@ def test_start_service(self): self._test_start_service(force=True) # previous pfs is killed assert start_pfs.poll() is not None + python_dir = os.path.dirname(sys.executable) + executable_dir = os.path.join(python_dir, "Scripts") if platform.system() == "Windows" else python_dir + assert executable_dir in os.environ["PATH"].split(os.pathsep) finally: port = get_port_from_config() kill_exist_service(port=port)