-
Notifications
You must be signed in to change notification settings - Fork 84
#2100: Resolve python versions via uv instead of ide-urls #2152
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
Merged
hohwille
merged 9 commits into
devonfw:main
from
Paras14:2100-python-not-available-for-mac-x64
Jul 21, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
230f107
#2100: Resolve python versions via uv instead of ide-urls
Paras14 6e56ed4
#2100: Update the CHANGELOG
Paras14 9e63620
#2100: Fix merge conflicts
Paras14 2111d02
Merge branch 'main' into 2100-python-not-available-for-mac-x64
Paras14 f38bcea
Merge branch 'main' into 2100-python-not-available-for-mac-x64
hohwille 9c43375
Merge branch 'main' into 2100-python-not-available-for-mac-x64
hohwille a3ab737
Merge branch 'main' into 2100-python-not-available-for-mac-x64
Paras14 50e7894
Update cli/src/main/java/com/devonfw/tools/ide/tool/python/PythonUvLi…
Paras14 c5f920c
Merge branch 'main' into 2100-python-not-available-for-mac-x64
hohwille File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
cli/src/main/java/com/devonfw/tools/ide/tool/python/PythonRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package com.devonfw.tools.ide.tool.python; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import com.devonfw.tools.ide.context.IdeContext; | ||
| import com.devonfw.tools.ide.process.ProcessErrorHandling; | ||
| import com.devonfw.tools.ide.process.ProcessMode; | ||
| import com.devonfw.tools.ide.process.ProcessResult; | ||
| import com.devonfw.tools.ide.tool.ToolCommandlet; | ||
| import com.devonfw.tools.ide.tool.repository.AbstractToolRepository; | ||
| import com.devonfw.tools.ide.tool.uv.Uv; | ||
| import com.devonfw.tools.ide.url.model.file.UrlDownloadFileMetadata; | ||
| import com.devonfw.tools.ide.version.VersionIdentifier; | ||
|
|
||
| /** | ||
| * {@link com.devonfw.tools.ide.tool.repository.ToolRepository ToolRepository} for Python. | ||
| */ | ||
| public class PythonRepository extends AbstractToolRepository { | ||
|
|
||
| /** {@link #getId() ID} of this repository. */ | ||
| public static final String ID = "python"; | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(PythonRepository.class); | ||
|
|
||
| private List<VersionIdentifier> cachedVersions; | ||
|
|
||
| /** | ||
| * The constructor. | ||
| * | ||
| * @param context the owning {@link IdeContext}. | ||
| */ | ||
| public PythonRepository(IdeContext context) { | ||
|
|
||
| super(context); | ||
| } | ||
|
|
||
| @Override | ||
| public String getId() { | ||
|
|
||
| return ID; | ||
| } | ||
|
|
||
| @Override | ||
| public List<String> getSortedEditions(String tool) { | ||
|
|
||
| return List.of(tool); | ||
| } | ||
|
|
||
| @Override | ||
| public List<VersionIdentifier> getSortedVersions(String tool, String edition, ToolCommandlet toolCommandlet) { | ||
|
|
||
| if (this.cachedVersions == null) { | ||
| this.cachedVersions = computeSortedVersions(); | ||
| } | ||
| return this.cachedVersions; | ||
| } | ||
|
|
||
| private List<VersionIdentifier> computeSortedVersions() { | ||
|
|
||
| List<PythonUvListEntry> entries = fetchUvPythonList(); | ||
| List<VersionIdentifier> versions = new ArrayList<>(); | ||
| for (PythonUvListEntry entry : entries) { | ||
| if (entry.isCpython()) { | ||
| VersionIdentifier version = VersionIdentifier.of(entry.version()); | ||
| if ((version != null) && !versions.contains(version)) { | ||
| versions.add(version); | ||
| } | ||
| } | ||
| } | ||
| versions.sort(Comparator.reverseOrder()); | ||
| LOG.debug("Found {} Python version(s) available via uv for the current platform.", versions.size()); | ||
| return versions; | ||
| } | ||
|
|
||
| /** | ||
| * Runs {@code uv python list} and parses the result. Extracted as a protected method so tests can stub the {@code uv} interaction. | ||
| * | ||
| * @return the parsed {@link PythonUvListEntry entries}. | ||
| */ | ||
| protected List<PythonUvListEntry> fetchUvPythonList() { | ||
|
|
||
| Uv uv = this.context.getCommandletManager().getCommandlet(Uv.class); | ||
| // We use the runTool variant that ensures uv is installed before running the command. | ||
| ProcessResult result = uv.runTool(ProcessMode.DEFAULT_CAPTURE, null, ProcessErrorHandling.THROW_CLI, | ||
| List.of("python", "list", "--all-versions", "--only-downloads", "--output-format", "json", "--no-config")); | ||
| return uv.parsePythonListJson(result.getOut()); | ||
| } | ||
|
|
||
| @Override | ||
| protected UrlDownloadFileMetadata getMetadata(String tool, String edition, VersionIdentifier version, ToolCommandlet toolCommandlet) { | ||
|
|
||
| throw new UnsupportedOperationException( | ||
| "Python is installed via uv and is never downloaded from a URL. This repository only resolves versions."); | ||
| } | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
cli/src/main/java/com/devonfw/tools/ide/tool/python/PythonUvListEntry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.devonfw.tools.ide.tool.python; | ||
|
|
||
| /** | ||
| * Represents a single entry of the JSON output of {@code uv python list --output-format json}. Only the fields required for version resolution are mapped. | ||
| * | ||
| * @param version the full Python version (e.g. {@code 3.11.8}) or {@code null} if absent. | ||
| * @param implementation the Python implementation (e.g. {@code cpython}, {@code pypy}) or {@code null} if absent. | ||
| */ | ||
| public record PythonUvListEntry(String version, String implementation) { | ||
|
|
||
| /** | ||
| * @return {@code true} if this entry is a CPython distribution, {@code false} otherwise. | ||
| */ | ||
| public boolean isCpython() { | ||
|
|
||
| return "cpython".equalsIgnoreCase(this.implementation); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
cli/src/test/java/com/devonfw/tools/ide/tool/python/PythonRepositoryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package com.devonfw.tools.ide.tool.python; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| 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.tool.uv.Uv; | ||
| import com.devonfw.tools.ide.version.VersionIdentifier; | ||
|
|
||
| /** | ||
| * Test of {@link PythonRepository}. | ||
| */ | ||
| public class PythonRepositoryTest extends AbstractIdeContextTest { | ||
|
|
||
| /** JSON same structure as produced by {@code uv python list --all-versions --output-format json}. */ | ||
| private static final String UV_PYTHON_LIST_JSON = """ | ||
| [ | ||
| {"version": "3.14.6", "implementation": "cpython", "os": "macos", "arch": "x86_64"}, | ||
| {"version": "3.13.14", "implementation": "cpython", "os": "macos", "arch": "x86_64"}, | ||
| {"version": "3.11.4", "implementation": "cpython", "os": "macos", "arch": "x86_64"}, | ||
| {"version": "7.3.17", "implementation": "pypy", "os": "macos", "arch": "x86_64"} | ||
| ] | ||
| """; | ||
|
|
||
| private PythonRepository newRepository(IdeTestContext context) { | ||
|
|
||
| return new PythonRepository(context) { | ||
| @Override | ||
| protected List<PythonUvListEntry> fetchUvPythonList() { | ||
| return context.getCommandletManager().getCommandlet(Uv.class).parsePythonListJson(List.of(UV_PYTHON_LIST_JSON)); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetSortedVersionsComesFromUvAndDropsNonCpython() { | ||
|
|
||
| // arrange | ||
| IdeTestContext context = newContext(PROJECT_BASIC); | ||
| PythonRepository repository = newRepository(context); | ||
|
|
||
| // act | ||
| List<VersionIdentifier> versions = repository.getSortedVersions("python", "python", null); | ||
|
|
||
| // assert | ||
| assertThat(versions).containsExactly( | ||
| VersionIdentifier.of("3.14.6"), | ||
| VersionIdentifier.of("3.13.14"), | ||
| VersionIdentifier.of("3.11.4")); | ||
| // PyPy must not leak in as a python version | ||
| assertThat(versions).doesNotContain(VersionIdentifier.of("7.3.17")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testResolveVersionPatternFindsPlatformSpecificBuild() { | ||
|
|
||
| // arrange | ||
| IdeTestContext context = newContext(PROJECT_BASIC); | ||
| PythonRepository repository = newRepository(context); | ||
|
|
||
| // act | ||
| VersionIdentifier resolved = repository.resolveVersion("python", "python", VersionIdentifier.of("3.14*"), null); | ||
|
|
||
| // assert | ||
| assertThat(resolved).isEqualTo(VersionIdentifier.of("3.14.6")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetSortedEditionsIsToolNameOnly() { | ||
|
|
||
| // arrange | ||
| IdeTestContext context = newContext(PROJECT_BASIC); | ||
| PythonRepository repository = newRepository(context); | ||
|
|
||
| // act & assert | ||
| assertThat(repository.getSortedEditions("python")).containsExactly("python"); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.