Skip to content

Infer platform_python_implementation from known implementation names - #23334

Draft
charliermarsh wants to merge 1 commit into
mainfrom
charlie/infer-implementation-markers
Draft

charliermarsh wants to merge 1 commit into
mainfrom
charlie/infer-implementation-markers

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

For a project that supports only PyPy, uv lock can include Jupyter Core’s Windows dependency, pywin32, even though Jupyter explicitly excludes it on PyPy.

[project]
name = "example"
version = "0.1.0"
requires-python = "==3.11.*"
dependencies = ["jupyter-core==5.8.1"]

[tool.uv]
environments = ["implementation_name == 'pypy'"]

Jupyter uses platform_python_implementation != 'PyPy' in its dependency marker. uv treats that condition and the project’s implementation_name == 'pypy' as independent, so it considers a Windows environment where both hold. Jupyter’s dependency

We now teach the marker algebra which value of platform_python_implementation a known implementation_name implies. With pypy, the value is PyPy, so uv can rule out the dependency and omit pywin32 from the resolution. The implication runs in one direction because both cpython and pyston report CPython. For graalpy, the reported value is GraalVM. We also correct the resolver’s inferred values for GraalPy and Pyston wheels so that each wheel covers its own interpreter.

The marker tree already simplifies expressions using known relationships between operating system markers. We extend that logic to the two interpreter keys. Once a branch fixes the implementation name, we can evaluate comparisons against the reported value on that branch. Other implementation names remain unconstrained.

This should land with #23335 and #23310. Once we recognize that Pyston reports CPython, we also need to use implementation_name to distinguish a CPython wheel from a Pyston wheel when choosing a release.

Comment thread crates/uv-pep508/src/marker/algebra.rs Resolved
@charliermarsh
charliermarsh force-pushed the charlie/infer-implementation-markers branch from b7b8181 to a284f7e Compare November 21, 2026 01:10
(literal!("cpython"), literal!("CPython")),
(literal!("pypy"), literal!("PyPy")),
(literal!("graalpy"), literal!("GraalVM")),
(literal!("pyston"), literal!("CPython")),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Keep CPython wheel coverage disjoint from Pyston

If 1.0 ships only a pyston38 wheel and 1.0+local ships only a cp38 wheel for the same platform, fork_version_registry now sees no environment covered only by 1.0. The CPython wheel still emits platform_python_implementation == 'CPython', which this implication makes true for every Pyston environment. The lock can therefore discard the only wheel Pyston can install: uv generates pyston38, not cp38, tags for Pyston. The merge base already overestimated CPython coverage for a Pyston environment, but its two wheel markers were disjoint. Keep the implication and emit implementation_name == 'cpython' for CPython tags in this PR; assert that the two wheels’ inferred markers are disjoint.

key: MarkerValueString::PlatformPythonImplementation,
operator: MarkerOperator::Equal,
value: arcstr::literal!("GraalPy"),
value: arcstr::literal!("GraalVM"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Test the GraalPy wheel-to-marker conversion

Reverting just this literal to GraalPy would make a GraalPy wheel appear incompatible with implementation_name == 'graalpy', but the new algebra tests would still pass: they construct both markers directly. Add one graalpy311-graalpy242_311_native wheel case to the existing test_implied_python_markers so it exercises the resolver conversion as well.

@codspeed

codspeed Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 7 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 89 untouched benchmarks
⏩ 84 skipped benchmarks1


Comparing charlie/infer-implementation-markers (2e0a217) with main (5a96b4c)2

Open in CodSpeed

Footnotes

  1. 84 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (4f3c8b7) during the generation of this report, so 5a96b4c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@charliermarsh
charliermarsh force-pushed the charlie/infer-implementation-markers branch from a284f7e to fc2d3f1 Compare November 21, 2026 01:55
key: MarkerValueString::PlatformPythonImplementation,
operator: MarkerOperator::Equal,
value: arcstr::literal!("GraalPy"),
value: arcstr::literal!("GraalVM"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Keep the GraalPy reported-name mapping in the marker algebra

Tags::from_env selects the GraalPy language tag from the implementation name graalpy. Emitting platform_python_implementation == 'GraalVM' here duplicates the mapping in exclusions() and makes the wheel marker broader: it still overlaps implementation_name != 'graalpy', since the implication is deliberately one-way. Emit implementation_name == 'graalpy' as the Pyston arm does, and let the algebra infer GraalVM. This can follow in the companion wheel-marker change.

"python_full_version == '3.10.*' and platform_python_implementation == 'PyPy'",
);
assert_python_markers(
"example-1.0-pyston38-none-any.whl",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Use an installable Pyston wheel in the marker test

The assertion exercises the new language-tag conversion, but Tags::from_env never emits pyston38-none-any: it pairs pyston38 with the native Pyston ABI, and its ABI-free Pyston tags use py*. Changing just the filename to example-1.0-pyston38-pyston_23_x86_64_linux_gnu-linux_x86_64.whl keeps the same expected Python marker while testing a wheel uv can actually select.

@charliermarsh
charliermarsh force-pushed the charlie/infer-implementation-markers branch from fc2d3f1 to 2e0a217 Compare November 23, 2026 16:04
// The converse is ambiguous. For example, Pyston also reports `CPython`.
for (name, implementation) in [
(literal!("cpython"), literal!("CPython")),
(literal!("pypy"), literal!("PyPy")),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Suggest removing a redundant environment instead of replacing it with false

With environments = ["platform_python_implementation == 'PyPy'", "implementation_name == 'pypy'"], the second selector is now entirely covered by the first. The overlap diagnostic computes !lhs && rhs and suggests replacing the second selector with python_version < '0'. Following that hint makes uv lock fail its Python-requirement check. The merge base already gave this hint for duplicate selectors; the new implication exposes it for these two distinct keys. A follow-up can check hint.is_false() before formatting and suggest removing the redundant selector instead.

[package.optional-dependencies]
binary = [
{ name = "psycopg-binary", marker = "implementation_name != 'pypy'" },
{ name = "psycopg-binary" },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Cover dependency pruning in a PyPy-only lock

This snapshot still locks psycopg-binary; it shows that an edge marker simplifies, not that tool.uv.environments prevents an unreachable package from being resolved. Add one case beside lock_constrained_environment: set implementation_name == 'pypy' as the environment and declare an unavailable dependency guarded by sys_platform == 'win32' and platform_python_implementation != 'PyPy'. With --no-index, the base would try to resolve that dependency and fail; the fixed command should lock only the project. This exercises the reported failure without relying on Jupyter or PyPI.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant