Skip to content

Commit 2068136

Browse files
authored
Use correct python executable inside venv for perf tests on Windows (#4339)
* Use correct python executable inside venv * Put "echo on" on windows, not linux
1 parent 21273c5 commit 2068136

File tree

3 files changed

+54
-47
lines changed

3 files changed

+54
-47
lines changed

scripts/run_performance_job.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,6 @@ def get_pre_commands(args: RunPerformanceJobArgs, v8_version: str):
122122
if args.os_group != "windows":
123123
helix_pre_commands += ["export CRYPTOGRAPHY_ALLOW_OPENSSL_102=true"]
124124

125-
if args.os_group == "windows":
126-
python = "py -3"
127-
else:
128-
python = "python3"
129-
130125
# Create separate list of commands to handle the next part.
131126
# On non-Windows, these commands are chained together with && so they will stop if any fail
132127
install_prerequisites: list[str] = []
@@ -144,6 +139,7 @@ def get_pre_commands(args: RunPerformanceJobArgs, v8_version: str):
144139
install_prerequisites += [
145140
"py -3 -m venv %HELIX_WORKITEM_ROOT%\\.venv",
146141
"call %HELIX_WORKITEM_ROOT%\\.venv\\Scripts\\activate.bat",
142+
"echo on" # venv activate script turns echo off, so turn it back on
147143
]
148144
else:
149145
if args.os_group != "osx" and args.os_sub_group != "_musl":
@@ -162,13 +158,13 @@ def get_pre_commands(args: RunPerformanceJobArgs, v8_version: str):
162158

163159
# Install python pacakges needed to upload results to azure storage
164160
install_prerequisites += [
165-
f"{python} -m pip install -U pip --force-reinstall",
166-
f"{python} -m pip install azure.storage.blob==12.13.0 --force-reinstall",
167-
f"{python} -m pip install azure.storage.queue==12.4.0 --force-reinstall",
168-
f"{python} -m pip install azure.identity==1.16.1 --force-reinstall",
169-
f"{python} -m pip install urllib3==1.26.19 --force-reinstall",
170-
f"{python} -m pip install opentelemetry-api==1.23.0 --force-reinstall",
171-
f"{python} -m pip install opentelemetry-sdk==1.23.0 --force-reinstall",
161+
f"python -m pip install -U pip --force-reinstall",
162+
f"python -m pip install azure.storage.blob==12.13.0 --force-reinstall",
163+
f"python -m pip install azure.storage.queue==12.4.0 --force-reinstall",
164+
f"python -m pip install azure.identity==1.16.1 --force-reinstall",
165+
f"python -m pip install urllib3==1.26.19 --force-reinstall",
166+
f"python -m pip install opentelemetry-api==1.23.0 --force-reinstall",
167+
f"python -m pip install opentelemetry-sdk==1.23.0 --force-reinstall",
172168
]
173169

174170
# Install prereqs for NodeJS https://github.com/dotnet/runtime/pull/40667
@@ -619,11 +615,11 @@ def run_performance_job(args: RunPerformanceJobArgs):
619615

620616
# ensure work item directory is not empty
621617
shutil.copytree(os.path.join(args.performance_repo_dir, "docs"), work_item_dir)
622-
618+
623619
if args.os_group == "windows":
624-
python = "py -3"
620+
agent_python = "py -3"
625621
else:
626-
python = "python3"
622+
agent_python = "python3"
627623

628624
helix_pre_commands = get_pre_commands(args, v8_version)
629625
helix_post_commands = get_post_commands(args)
@@ -747,15 +743,15 @@ def run_performance_job(args: RunPerformanceJobArgs):
747743
os.environ["Architecture"] = args.architecture
748744
os.environ["TargetsWindows"] = "true" if args.os_group == "windows" else "false"
749745
os.environ["HelixTargetQueues"] = args.queue
750-
os.environ["Python"] = python
746+
os.environ["Python"] = agent_python
751747
os.environ["RuntimeFlavor"] = args.runtime_flavor or ''
752748
os.environ["HybridGlobalization"] = str(args.hybrid_globalization)
753749

754750
# TODO: See if these commands are needed for linux as they were being called before but were failing.
755751
if args.os_group == "windows" or args.os_group == "osx":
756-
RunCommand([*(python.split(" ")), "-m", "pip", "install", "--user", "--upgrade", "pip"]).run()
757-
RunCommand([*(python.split(" ")), "-m", "pip", "install", "--user", "urllib3==1.26.19"]).run()
758-
RunCommand([*(python.split(" ")), "-m", "pip", "install", "--user", "requests"]).run()
752+
RunCommand([*(agent_python.split(" ")), "-m", "pip", "install", "--user", "--upgrade", "pip"]).run()
753+
RunCommand([*(agent_python.split(" ")), "-m", "pip", "install", "--user", "urllib3==1.26.19"]).run()
754+
RunCommand([*(agent_python.split(" ")), "-m", "pip", "install", "--user", "requests"]).run()
759755

760756
scenarios_path = os.path.join(args.performance_repo_dir, "src", "scenarios")
761757
script_path = os.path.join(args.performance_repo_dir, "scripts")
@@ -843,12 +839,12 @@ def run_performance_job(args: RunPerformanceJobArgs):
843839

844840
if args.os_group == "windows":
845841
work_item_command = [
846-
python,
842+
"python",
847843
"%HELIX_WORKITEM_ROOT%\\performance\\scripts\\benchmarks_ci.py",
848844
"--csproj", f"%HELIX_WORKITEM_ROOT%\\performance\\{args.target_csproj}"]
849845
else:
850846
work_item_command = [
851-
python,
847+
"python",
852848
"$HELIX_WORKITEM_ROOT/performance/scripts/benchmarks_ci.py",
853849
"--csproj", f"$HELIX_WORKITEM_ROOT/performance/{args.target_csproj}"]
854850

@@ -895,7 +891,7 @@ def run_performance_job(args: RunPerformanceJobArgs):
895891
download_files_from_helix=True,
896892
targets_windows=args.os_group == "windows",
897893
helix_results_destination_dir=helix_results_destination_dir,
898-
python=python,
894+
python="python",
899895
affinity=args.affinity)
900896

901897
if args.send_to_helix:

src/scenarios/shared/runner.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,20 @@ def run(self):
245245
Runs the specified scenario
246246
'''
247247
self.parseargs()
248+
249+
python_command = pythoncommand().split(' ')
250+
python_exe = python_command[0]
251+
python_args = " ".join(python_command[1:])
248252
if self.testtype == const.INNERLOOP:
249253
startup = StartupWrapper()
250254
self.traits.add_traits(scenarioname=self.scenarioname,
251255
scenariotypename=const.SCENARIO_NAMES[const.INNERLOOP],
252256
apptorun='dotnet', appargs='run --project %s' % appfolder(self.traits.exename, self.traits.projext),
253-
innerloopcommand=pythoncommand(),
254-
iterationsetup=pythoncommand(),
255-
setupargs='%s %s setup_build' % ('-3' if iswin() else '', const.ITERATION_SETUP_FILE),
256-
iterationcleanup=pythoncommand(),
257-
cleanupargs='%s %s cleanup' % ('-3' if iswin() else '', const.ITERATION_SETUP_FILE),
257+
innerloopcommand=python_exe,
258+
iterationsetup=python_exe,
259+
setupargs='%s %s setup_build' % (python_args, const.ITERATION_SETUP_FILE),
260+
iterationcleanup=python_exe,
261+
cleanupargs='%s %s cleanup' % (python_args, const.ITERATION_SETUP_FILE),
258262
affinity=self.affinity)
259263
startup.runtests(self.traits)
260264

@@ -263,11 +267,11 @@ def run(self):
263267
self.traits.add_traits(scenarioname=self.scenarioname,
264268
scenariotypename=const.SCENARIO_NAMES[const.INNERLOOPMSBUILD],
265269
apptorun='dotnet', appargs='run --project %s' % appfolder(self.traits.exename, self.traits.projext),
266-
innerloopcommand=pythoncommand(),
267-
iterationsetup=pythoncommand(),
268-
setupargs='%s %s setup_build' % ('-3' if iswin() else '', const.ITERATION_SETUP_FILE),
269-
iterationcleanup=pythoncommand(),
270-
cleanupargs='%s %s cleanup' % ('-3' if iswin() else '', const.ITERATION_SETUP_FILE),
270+
innerloopcommand=python_exe,
271+
iterationsetup=python_exe,
272+
setupargs='%s %s setup_build' % (python_args, const.ITERATION_SETUP_FILE),
273+
iterationcleanup=python_exe,
274+
cleanupargs='%s %s cleanup' % (python_args, const.ITERATION_SETUP_FILE),
271275
affinity=self.affinity)
272276
startup.runtests(self.traits)
273277

@@ -276,11 +280,11 @@ def run(self):
276280
self.traits.add_traits(scenarioname=self.scenarioname,
277281
scenariotypename=const.SCENARIO_NAMES[const.DOTNETWATCH],
278282
apptorun='dotnet', appargs='watch -v',
279-
innerloopcommand=pythoncommand(),
280-
iterationsetup=pythoncommand(),
281-
setupargs='%s %s setup_build' % ('-3' if iswin() else '', const.ITERATION_SETUP_FILE),
282-
iterationcleanup=pythoncommand(),
283-
cleanupargs='%s %s cleanup' % ('-3' if iswin() else '', const.ITERATION_SETUP_FILE),
283+
innerloopcommand=python_exe,
284+
iterationsetup=python_exe,
285+
setupargs='%s %s setup_build' % (python_args, const.ITERATION_SETUP_FILE),
286+
iterationcleanup=python_exe,
287+
cleanupargs='%s %s cleanup' % (python_args, const.ITERATION_SETUP_FILE),
284288
affinity=self.affinity)
285289
self.traits.add_traits(workingdir = const.APPDIR)
286290
startup.runtests(self.traits)
@@ -312,10 +316,10 @@ def run(self):
312316
scenariotypename='%s_%s' % (const.SCENARIO_NAMES[const.SDK], const.CLEAN_BUILD),
313317
apptorun=const.DOTNET,
314318
appargs='build',
315-
iterationsetup=pythoncommand(),
316-
setupargs='%s %s setup_build' % ('-3' if iswin() else '', const.ITERATION_SETUP_FILE),
317-
iterationcleanup=pythoncommand(),
318-
cleanupargs='%s %s cleanup' % ('-3' if iswin() else '', const.ITERATION_SETUP_FILE),
319+
iterationsetup=python_exe,
320+
setupargs='%s %s setup_build' % (python_args, const.ITERATION_SETUP_FILE),
321+
iterationcleanup=python_exe,
322+
cleanupargs='%s %s cleanup' % (python_args, const.ITERATION_SETUP_FILE),
319323
workingdir=const.APPDIR,
320324
environmentvariables=envlistcleanbuild,
321325
)
@@ -344,10 +348,10 @@ def run(self):
344348
apptorun=const.DOTNET,
345349
scenarioname=self.scenarioname,
346350
scenariotypename='%s_%s' % (const.SCENARIO_NAMES[const.SDK], const.NEW_CONSOLE),
347-
iterationsetup=pythoncommand(),
348-
setupargs='%s %s setup_new' % ('-3' if iswin() else '', const.ITERATION_SETUP_FILE),
349-
iterationcleanup=pythoncommand(),
350-
cleanupargs='%s %s cleanup' % ('-3' if iswin() else '', const.ITERATION_SETUP_FILE),
351+
iterationsetup=python_exe,
352+
setupargs='%s %s setup_new' % (python_args, const.ITERATION_SETUP_FILE),
353+
iterationcleanup=python_exe,
354+
cleanupargs='%s %s cleanup' % (python_args, const.ITERATION_SETUP_FILE),
351355
workingdir=const.APPDIR
352356
)
353357
self.traits.add_traits(overwrite=True, startupmetric=const.STARTUP_PROCESSTIME)

src/scenarios/shared/util.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,16 @@ def getruntimeidentifier():
7070

7171
return rid
7272

73+
# https://stackoverflow.com/a/42580137
74+
def is_venv():
75+
return (hasattr(sys, 'real_prefix') or
76+
(hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))
77+
7378
def pythoncommand():
74-
if iswin():
75-
return 'py'
79+
if is_venv():
80+
return 'python'
81+
elif iswin():
82+
return 'py -3'
7683
else:
7784
return 'python3'
7885

0 commit comments

Comments
 (0)