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

uv should skip parsing non-platform dependencies or sources #12331

Closed
pplmx opened this issue Mar 20, 2025 · 13 comments
Closed

uv should skip parsing non-platform dependencies or sources #12331

pplmx opened this issue Mar 20, 2025 · 13 comments
Labels
question Asking for clarification or support

Comments

@pplmx
Copy link

pplmx commented Mar 20, 2025

Summary

I have a pyproject.toml where I configure platform-specific dependencies and source settings as follows:

[project]
name = "example"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "megatron-core ; sys_platform == 'linux'",
]

[tool.uv.sources]
megatron-core = { git = "https://github.com/NVIDIA/Megatron-LM", marker = "sys_platform == 'linux'" }

On Linux, everything works fine. However, on Windows, running uv sync throws the following error:

uv sync
  × Failed to build `megatron-core @ git+https://github.com/NVIDIA/Megatron-LM`
  ├─▶ The build backend returned an error
  ╰─▶ Call to `setuptools.build_meta:__legacy__.build_wheel` failed (exit code: 1)

      [stderr]
      Traceback (most recent call last):
        ...
      FileNotFoundError: [WinError 3] The system cannot find the path specified.

      hint: This usually indicates a problem with the package or the build environment.

Steps to Reproduce

# run the following commands on Windows
mkdir example
uv init -p 3.12
# copy the above pyproject.toml to this project
uv sync

Expected Behavior

On non-target platforms (e.g., Windows), uv should skip parsing dependencies or sources that have platform-specific markers, thereby avoiding build errors.

FYI

uv 0.6.8
Python 3.12.9
@pplmx pplmx added the enhancement New feature or improvement to existing functionality label Mar 20, 2025
@charliermarsh
Copy link
Member

uv sync performs a universal resolution (see the docs), so we need to resolve metadata for megatron-core even if it won't ultimately be installed.

@charliermarsh charliermarsh added question Asking for clarification or support and removed enhancement New feature or improvement to existing functionality labels Mar 20, 2025
@pplmx
Copy link
Author

pplmx commented Mar 21, 2025

Since Megatron-LM does not support Windows, we use an alternative solution on Windows. In this case, how should the pyproject.toml be configured to work properly on Windows?

@charliermarsh
Copy link
Member

Normally I would recommend adding a [[tool.uv.dependency-metadata]] for Megatron-LM so that the resolver has static metadata available and doesn't need to build the project: https://docs.astral.sh/uv/concepts/resolution/#dependency-metadata. That looks difficult for Megatron-LM since they use dynamic metadata and it seems to vary quite a bit? Your best bet might be to lock on Linux, then use --frozen when installing on Windows.

@pplmx
Copy link
Author

pplmx commented Mar 21, 2025

Thank you, @charliermarsh. Here's what I've tried:

  1. Generated uv.lock on Linux using the provided pyproject.toml.
  2. Copied uv.lock to Windows.
  3. Ran uv sync on Windows—this step worked as expected.
  4. Installed a package (e.g., numpy) on Windows with uv add numpy --frozen and received no error output.
  5. However, when I ran uv tree or uv pip list, no packages were listed.

Could you please help me understand why the package isn’t showing up?

@charliermarsh
Copy link
Member

Can you explain what you mean by "no packages were listed", and/or provide me with exact steps I can take to reproduce?

@pplmx
Copy link
Author

pplmx commented Mar 21, 2025

Steps to Reproduce

# On Linux
mkdir example; cd example
uv init -p 3.12
uv add "git+https://github.com/NVIDIA/Megatron-LM; sys_platform == 'linux'"
# show current packages
uv tree -d2

# On Windows
mkdir example; cd example
uv init -p 3.12
# copy the above pyproject.toml and uv.lock generated on Linux to replace here
uv sync
uv tree -d2
uv add numpy --frozen
uv tree -d2 # This will throw error
uv tree -d2 --frozen # output: example v0.1.0
uv pip list # output nothing

@zanieb
Copy link
Member

zanieb commented Mar 21, 2025

uv add --frozen won't update the lockfile with your new dependency (and uv tree --frozen similarly will not update the lockfile). You need to add your dependencies up-front on the Linux machine (to workaround this specific problem).

@pplmx
Copy link
Author

pplmx commented Mar 22, 2025

Thank you, @zanieb.
I understand the process now. For this case, to use numpy on Windows, I need to run uv add numpy on Linux first to generate the uv.lock file, and then execute uv sync --frozen on Windows using that lock file.

@pplmx
Copy link
Author

pplmx commented Mar 22, 2025

Personally, uv should skip parsing non-platform dependencies or sources is a valid requirement :)

@zanieb
Copy link
Member

zanieb commented Apr 1, 2025

I don't think we'll do that. The point of uv's lockfile is that it's platform independent and the problem is rather that this package is not following best practices for declaring metadata.

@zanieb zanieb closed this as not planned Won't fix, can't repro, duplicate, stale Apr 1, 2025
@pplmx
Copy link
Author

pplmx commented Apr 3, 2025

Thank you for your assistance.
I'm not entirely sure what the best practices are for declaring metadata. Could you please provide some guidance?
Additionally, how should a Linux-only package declare the correct metadata?
Once I have this information, I'll be happy to open an issue on Megatron-LM to further discuss the topic.
Thanks again!

@zanieb
Copy link
Member

zanieb commented Apr 3, 2025

The problem is that we need build the package to determine its metadata, but the package can only be built on Linux. Metadata can be declared statically, so the build does not need to happen. Or, they can build wheels for supported platforms, in which the resolved metadata can be stored.

For background, see

The project is using a pyproject.toml, but specifically defines critical core metadata fields as dynamic: https://github.com/NVIDIA/Megatron-LM/blob/cbc89b322c454a2de46edcbd1fc708669aeafd59/pyproject.toml#L11

@pplmx
Copy link
Author

pplmx commented Apr 3, 2025

Thank you for the detailed explanation and the reference links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for clarification or support
Projects
None yet
Development

No branches or pull requests

3 participants