Resolved an issue with "pio pkg exec" command on WIndows while executing Python scripts from a package

This commit is contained in:
Ivan Kravets committed 2023-07-11 14:23:05 +03:00
1 parent 68e62c7137
commit be4d016f61
3 files changed
+15 -10

No files matched your search

+6 -2
View File
@@ -20,7 +20,7 @@ import click
from platformio.compat import IS_MACOS, IS_WINDOWS
from platformio.exception import ReturnErrorCode, UserSideException
from platformio.package.manager.tool import ToolPackageManager
from platformio.proc import get_pythonexe_path
from platformio.proc import get_pythonexe_path, where_is_program
@click.command("exec", short_help="Run command from package tool")
@@ -52,9 +52,13 @@ def package_exec_cmd(obj, package, call, args):
inject_pkg_to_environ(pkg)
os.environ["PIO_PYTHON_EXE"] = get_pythonexe_path()
# inject current python interpreter on Windows
if IS_WINDOWS and args and args[0].endswith(".py"):
if args[0].endswith(".py"):
args = [os.environ["PIO_PYTHON_EXE"]] + list(args)
if not os.path.exists(args[1]):
args[1] = where_is_program(args[1])
result = None
try:
run_options = dict(shell=call is not None, env=os.environ)
+8 -8
View File
@@ -185,10 +185,17 @@ def copy_pythonpath_to_osenv():
def where_is_program(program, envpath=None):
env = os.environ
env = os.environ.copy()
if envpath:
env["PATH"] = envpath
# look up in $PATH
for bin_dir in env.get("PATH", "").split(os.pathsep):
if os.path.isfile(os.path.join(bin_dir, program)):
return os.path.join(bin_dir, program)
if IS_WINDOWS and os.path.isfile(os.path.join(bin_dir, "%s.exe" % program)):
return os.path.join(bin_dir, "%s.exe" % program)
# try OS's built-in commands
try:
result = exec_command(["where" if IS_WINDOWS else "which", program], env=env)
@@ -197,13 +204,6 @@ def where_is_program(program, envpath=None):
except OSError:
pass
# look up in $PATH
for bin_dir in env.get("PATH", "").split(os.pathsep):
if os.path.isfile(os.path.join(bin_dir, program)):
return os.path.join(bin_dir, program)
if os.path.isfile(os.path.join(bin_dir, "%s.exe" % program)):
return os.path.join(bin_dir, "%s.exe" % program)
return program