mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Resolved an issue with "pio pkg exec" command on WIndows while executing Python scripts from a package
This commit is contained in:
@ -19,6 +19,7 @@ PlatformIO Core 6
|
|||||||
~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
* Resolved an issue that caused generated projects for `PlatformIO IDE for VSCode <https://docs.platformio.org/en/latest/integration/ide/vscode.html>`__ to break when the ``-iprefix`` compiler flag was used
|
* Resolved an issue that caused generated projects for `PlatformIO IDE for VSCode <https://docs.platformio.org/en/latest/integration/ide/vscode.html>`__ to break when the ``-iprefix`` compiler flag was used
|
||||||
|
* Resolved an issue encountered while utilizing the `pio pkg exec <https://docs.platformio.org/en/latest/core/userguide/pkg/cmd_exec.html>`__ command on the Windows platform to execute Python scripts from a package
|
||||||
|
|
||||||
6.1.9 (2023-07-06)
|
6.1.9 (2023-07-06)
|
||||||
~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -20,7 +20,7 @@ import click
|
|||||||
from platformio.compat import IS_MACOS, IS_WINDOWS
|
from platformio.compat import IS_MACOS, IS_WINDOWS
|
||||||
from platformio.exception import ReturnErrorCode, UserSideException
|
from platformio.exception import ReturnErrorCode, UserSideException
|
||||||
from platformio.package.manager.tool import ToolPackageManager
|
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")
|
@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)
|
inject_pkg_to_environ(pkg)
|
||||||
os.environ["PIO_PYTHON_EXE"] = get_pythonexe_path()
|
os.environ["PIO_PYTHON_EXE"] = get_pythonexe_path()
|
||||||
|
|
||||||
# inject current python interpreter on Windows
|
# 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)
|
args = [os.environ["PIO_PYTHON_EXE"]] + list(args)
|
||||||
|
if not os.path.exists(args[1]):
|
||||||
|
args[1] = where_is_program(args[1])
|
||||||
|
|
||||||
result = None
|
result = None
|
||||||
try:
|
try:
|
||||||
run_options = dict(shell=call is not None, env=os.environ)
|
run_options = dict(shell=call is not None, env=os.environ)
|
||||||
|
@ -185,10 +185,17 @@ def copy_pythonpath_to_osenv():
|
|||||||
|
|
||||||
|
|
||||||
def where_is_program(program, envpath=None):
|
def where_is_program(program, envpath=None):
|
||||||
env = os.environ
|
env = os.environ.copy()
|
||||||
if envpath:
|
if envpath:
|
||||||
env["PATH"] = 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 OS's built-in commands
|
||||||
try:
|
try:
|
||||||
result = exec_command(["where" if IS_WINDOWS else "which", program], env=env)
|
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:
|
except OSError:
|
||||||
pass
|
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
|
return program
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user