Skip to content

Commit

Permalink
[Internal]Add executable path to environment variable to avoid start …
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
YingChen1996 and Ying Chen authored Apr 7, 2024
1 parent 5dcddc5 commit bc2b93d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/promptflow-devkit/promptflow/_cli/_pf/_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
5 changes: 5 additions & 0 deletions src/promptflow/tests/sdk_pfs_test/e2etests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

import os
import platform
import subprocess
import sys

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bc2b93d

Please sign in to comment.