Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion colcon_powershell/shell/powershell.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from colcon_core.shell import logger
from colcon_core.shell import ShellExtensionPoint
from colcon_core.shell.template import expand_template
import psutil

"""Environment variable to override the CMake executable"""
POWERSHELL_COMMAND_ENVIRONMENT_VARIABLE = EnvironmentVariable(
Expand Down Expand Up @@ -44,6 +45,20 @@ def which_executable(environment_variable, executable_name):
POWERSHELL_COMMAND_ENVIRONMENT_VARIABLE.name, powershell_executable_name)


def parent_process_is_powershell():
"""Determine if the parent process is PowerShell.

In case the executable name is not found,
it is assumed that the parent process is not PowerShell.
"""
parent = psutil.Process().parent()
if parent is None:
return False

parent_name = parent.name()
return parent_name == powershell_executable_name


class PowerShellExtension(ShellExtensionPoint):
"""Generate `.ps1` scripts to extend the environment."""

Expand All @@ -66,7 +81,7 @@ def __init__(self): # noqa: D107
pathexts = os.environ.get('PATHEXT', '').lower().split(os.pathsep)
self._is_primary = '.cpl' in pathexts
else:
self._is_primary = bool(os.environ.get('PSModulePath'))
self._is_primary = parent_process_is_powershell()

if not POWERSHELL_EXECUTABLE:
self._is_primary = False
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ keywords = colcon
python_requires = >=3.6
install_requires =
colcon-core>=0.12.0
psutil>=5.4.3
packages = find:
zip_safe = false

Expand Down
2 changes: 1 addition & 1 deletion stdeb.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[colcon-powershell]
No-Python2:
Depends3: python3-colcon-core (>= 0.12.0)
Depends3: python3-colcon-core (>= 0.12.0), python3-psutil (>= 5.4.3)
Suite: focal jammy noble resolute bookworm trixie
X-Python3-Version: >= 3.6
Upstream-Version-Suffix: +upstream
1 change: 1 addition & 0 deletions test/spell_check.words
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pathlib
plugin
powershell
prepend
psutil
pwsh
pydocstyle
pytest
Expand Down
Loading