Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix powershell warning #17500

Merged
merged 3 commits into from
Dec 18, 2024
Merged
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: 9 additions & 8 deletions conan/tools/env/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,14 +542,15 @@ def save_script(self, filename):
is_bat = self._subsystem == WINDOWS
try:
is_ps1 = self._conanfile.conf.get("tools.env.virtualenv:powershell", check_type=bool)
ConanOutput().warning(
"Boolean values for 'tools.env.virtualenv:powershell' are deprecated. "
"Please specify 'powershell.exe' or 'pwsh' instead, appending arguments if needed "
"(for example: 'powershell.exe -argument'). "
"To unset this configuration, use `tools.env.virtualenv:powershell=!`, which matches "
"the previous 'False' behavior.",
warn_tag="deprecated"
)
if is_ps1 is not None:
ConanOutput().warning(
"Boolean values for 'tools.env.virtualenv:powershell' are deprecated. "
"Please specify 'powershell.exe' or 'pwsh' instead, appending arguments if needed "
"(for example: 'powershell.exe -argument'). "
"To unset this configuration, use `tools.env.virtualenv:powershell=!`, which matches "
"the previous 'False' behavior.",
warn_tag="deprecated"
)
except ConanException:
is_ps1 = self._conanfile.conf.get("tools.env.virtualenv:powershell", check_type=str)
if is_ps1:
Expand Down
17 changes: 9 additions & 8 deletions conan/tools/microsoft/visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,15 @@ def generate(self, scope="build"):

try:
is_ps1 = self._conanfile.conf.get("tools.env.virtualenv:powershell", check_type=bool)
ConanOutput().warning(
"Boolean values for 'tools.env.virtualenv:powershell' are deprecated. "
"Please specify 'powershell.exe' or 'pwsh' instead, appending arguments if needed "
"(for example: 'powershell.exe -argument'). "
"To unset this configuration, use `tools.env.virtualenv:powershell=!`, which matches "
"the previous 'False' behavior.",
warn_tag="deprecated"
)
if is_ps1 is not None:
ConanOutput().warning(
"Boolean values for 'tools.env.virtualenv:powershell' are deprecated. "
"Please specify 'powershell.exe' or 'pwsh' instead, appending arguments if needed "
"(for example: 'powershell.exe -argument'). "
"To unset this configuration, use `tools.env.virtualenv:powershell=!`, which matches "
"the previous 'False' behavior.",
warn_tag="deprecated"
)
except ConanException:
is_ps1 = self._conanfile.conf.get("tools.env.virtualenv:powershell", check_type=str)
if is_ps1:
Expand Down
21 changes: 21 additions & 0 deletions test/functional/toolchains/env/test_virtualenv_powershell.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,24 @@ class Pkg(ConanFile):
client.current_folder,"mycompiler1.bat")
client.run_command(cmd)
assert "MYTOOL 1!!" in client.out


@pytest.mark.parametrize("powershell", [None, True, False])
def test_powershell_deprecated_message(powershell):
client = TestClient(light=True)
conanfile = textwrap.dedent("""\
from conan import ConanFile
class Pkg(ConanFile):
settings = "os"
name = "pkg"
version = "0.1"
""")

client.save({"conanfile.py": conanfile})
powershell_arg = f'-c tools.env.virtualenv:powershell={powershell}' if powershell is not None else ""
client.run(f'install . {powershell_arg}')
# only show message if the value is set to False or True if not set do not show message
if powershell is not None:
assert "Boolean values for 'tools.env.virtualenv:powershell' are deprecated" in client.out
else:
assert "Boolean values for 'tools.env.virtualenv:powershell' are deprecated" not in client.out
Loading