diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/python/Python.java b/cli/src/main/java/com/devonfw/tools/ide/tool/python/Python.java index caa38b5a3e..bb39c131ad 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/python/Python.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/python/Python.java @@ -66,6 +66,7 @@ public void setEnvironment(EnvironmentContext environmentContext, ToolInstallati super.setEnvironment(environmentContext, toolInstallation, additionalInstallation); environmentContext.withEnvVar("VIRTUAL_ENV", toolInstallation.rootDir().toString()); + environmentContext.withEnvVar("XDG_BIN_HOME", toolInstallation.binDir().toString()); } @Override diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/uv/Uv.java b/cli/src/main/java/com/devonfw/tools/ide/tool/uv/Uv.java index 4efdac6c65..fa61b1516b 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/uv/Uv.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/uv/Uv.java @@ -6,11 +6,13 @@ import com.devonfw.tools.ide.common.Tag; import com.devonfw.tools.ide.context.IdeContext; +import com.devonfw.tools.ide.process.EnvironmentContext; import com.devonfw.tools.ide.process.ProcessContext; import com.devonfw.tools.ide.process.ProcessMode; import com.devonfw.tools.ide.process.ProcessResult; import com.devonfw.tools.ide.tool.LocalToolCommandlet; import com.devonfw.tools.ide.tool.ToolCommandlet; +import com.devonfw.tools.ide.tool.ToolInstallation; import com.devonfw.tools.ide.version.VersionIdentifier; /** @@ -42,4 +44,11 @@ public void installPython(Path installationPath, VersionIdentifier resolvedVersi ProcessResult result = runTool(processContext, ProcessMode.DEFAULT_CAPTURE, List.of("venv", "--python", resolvedVersion.toString())); assert result.isSuccessful(); } + @Override + public void setEnvironment(EnvironmentContext environmentContext, ToolInstallation toolInstallation, boolean additionalInstallation) { + + super.setEnvironment(environmentContext, toolInstallation, additionalInstallation); + Path pythonBinPath = this.context.getSoftwarePath().resolve("python").resolve("bin"); + environmentContext.withEnvVar("XDG_BIN_HOME", pythonBinPath.toString()); + } } diff --git a/cli/src/test/java/com/devonfw/tools/ide/tool/python/PythonTest.java b/cli/src/test/java/com/devonfw/tools/ide/tool/python/PythonTest.java new file mode 100644 index 0000000000..7c2240bbf1 --- /dev/null +++ b/cli/src/test/java/com/devonfw/tools/ide/tool/python/PythonTest.java @@ -0,0 +1,41 @@ +package com.devonfw.tools.ide.tool.python; + +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import com.devonfw.tools.ide.context.AbstractIdeContextTest; +import com.devonfw.tools.ide.context.IdeTestContext; +import com.devonfw.tools.ide.environment.EnvironmentVariablesType; +import com.devonfw.tools.ide.environment.VariableLine; +import com.devonfw.tools.ide.environment.VariableSource; +import com.devonfw.tools.ide.os.WindowsPathSyntax; +import com.devonfw.tools.ide.process.EnvironmentVariableCollectorContext; +import com.devonfw.tools.ide.tool.ToolInstallation; +import com.devonfw.tools.ide.version.VersionIdentifier; + +/** + * Test of {@link Python}. + */ +public class PythonTest extends AbstractIdeContextTest { + + @Test + public void testSetEnvironment() { + + // arrange + IdeTestContext context = newContext(PROJECT_BASIC); + Python python = new Python(context); + Path rootDir = context.getSoftwarePath().resolve("python"); + ToolInstallation toolInstallation = new ToolInstallation(rootDir, rootDir, rootDir.resolve("bin"), VersionIdentifier.of("3.12.0"), true); + Map variables = new HashMap<>(); + EnvironmentVariableCollectorContext environmentContext = new EnvironmentVariableCollectorContext(variables, new VariableSource(EnvironmentVariablesType.WORKSPACE, null), WindowsPathSyntax.MSYS); + + // act + python.setEnvironment(environmentContext, toolInstallation, false); + + // assert + assertThat(Path.of(variables.get("XDG_BIN_HOME").getValue())).isEqualTo(toolInstallation.binDir()); + } +} diff --git a/cli/src/test/java/com/devonfw/tools/ide/tool/uv/UvTest.java b/cli/src/test/java/com/devonfw/tools/ide/tool/uv/UvTest.java new file mode 100644 index 0000000000..2dbfa3a1f7 --- /dev/null +++ b/cli/src/test/java/com/devonfw/tools/ide/tool/uv/UvTest.java @@ -0,0 +1,42 @@ +package com.devonfw.tools.ide.tool.uv; + +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import com.devonfw.tools.ide.context.AbstractIdeContextTest; +import com.devonfw.tools.ide.context.IdeTestContext; +import com.devonfw.tools.ide.environment.EnvironmentVariablesType; +import com.devonfw.tools.ide.environment.VariableLine; +import com.devonfw.tools.ide.environment.VariableSource; +import com.devonfw.tools.ide.os.WindowsPathSyntax; +import com.devonfw.tools.ide.process.EnvironmentVariableCollectorContext; +import com.devonfw.tools.ide.tool.ToolInstallation; +import com.devonfw.tools.ide.version.VersionIdentifier; + +/** + * Test of {@link Uv}. + */ +public class UvTest extends AbstractIdeContextTest { + + @Test + public void testSetEnvironment() { + + // arrange + IdeTestContext context = newContext(PROJECT_BASIC); + Uv uv = new Uv(context); + Path rootDir = context.getSoftwarePath().resolve("uv"); + ToolInstallation toolInstallation = new ToolInstallation(rootDir, rootDir, rootDir, VersionIdentifier.of("0.1.0"), true); + Map variables = new HashMap<>(); + EnvironmentVariableCollectorContext environmentContext = new EnvironmentVariableCollectorContext(variables, new VariableSource(EnvironmentVariablesType.WORKSPACE, null), WindowsPathSyntax.MSYS); + + // act + uv.setEnvironment(environmentContext, toolInstallation, false); + + // assert + Path expectedPythonBinPath = context.getSoftwarePath().resolve("python").resolve("bin"); + assertThat(Path.of(variables.get("XDG_BIN_HOME").getValue())).isEqualTo(expectedPythonBinPath); + } +}