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

Remove extra duplication from lockfile #4888

Closed
Tracked by #4893 ...
konstin opened this issue Jul 8, 2024 · 3 comments · Fixed by #5181
Closed
Tracked by #4893 ...

Remove extra duplication from lockfile #4888

konstin opened this issue Jul 8, 2024 · 3 comments · Fixed by #5181
Assignees
Labels
preview Experimental behavior

Comments

@konstin
Copy link
Member

konstin commented Jul 8, 2024

When declaring a dependency pandas[excel,html,plot], the lockfile shows:

dependencies = [
    { name = "pandas" },
    { name = "pandas", extra = "excel" },
    { name = "pandas", extra = "html" },
    { name = "pandas", extra = "plot" },
]

We should collapse those entries:

dependencies = [
    { name = "pandas", extra = ["excel", "html", "plot"] },
]

This makes more sense to the user (we don't install pandas four times, we install it once and then those extra packages, that's our internal abstraction into virtual packages leaking) and makes the lockfile more concise.

@konstin konstin added the preview Experimental behavior label Jul 8, 2024
@BurntSushi
Copy link
Member

Is this limited to the specific example shown here, or in general? In general, each of those dependency entries can have other fields on them that are different. For example, markers. In theory, I think, other fields could be different too, such as version and source. Or at least, that's what our data model supports. But I think the markers really could be different?

@konstin
Copy link
Member Author

konstin commented Jul 8, 2024

This should only collapse entries with the same markers. Say we have

dependencies = [
    "pandas[excel,html]; python_version == '3.13'",
    "pandas[excel,plot]",
]

we currently get

dependencies = [
    { name = "pandas" },
    { name = "pandas", extra = "excel" },
    { name = "pandas", extra = "html", marker = "python_version == '3.13'" },
    { name = "pandas", extra = "plot" },
]

which we could collapse to

dependencies = [
    { name = "pandas", extras = ["excel", "plot"] },
    { name = "pandas", extras = ["html"], marker = "python_version == '3.13'" },
]

@BurntSushi
Copy link
Member

Right, okay. I think this LGTM. Although I don't totally mind our existing format, I am very sympathetic to the fact that it leaks our "virtual package" abstraction. So I think I would on balance favor your suggestion here to the status quo.

@konstin konstin self-assigned this Jul 18, 2024
konstin added a commit that referenced this issue Jul 18, 2024
As user, you specify a list of extras. Internally, we decompose this into one virtual package per extra. We currently leak this abstraction by writing one entry per extra to the lockfile:

```toml
[[distribution]]
name = "foo"
version = "4.39.0.dev0"
source = { editable = "." }
dependencies = [
    { name = "pandas" },
    { name = "pandas", extra = "excel" },
    { name = "pandas", extra = "hdf5" },
    { name = "pandas", extra = "html", marker = "os_name != 'posix'" },
    { name = "pandas", extra = "output-formatting", marker = "os_name == 'posix'" },
    { name = "pandas", extra = "plot", marker = "os_name == 'posix'" },
]
```

Instead, we should merge the extras into a list of extras, creating a more concise lockfile:

```toml
[[distribution]]
name = "foo"
version = "4.39.0.dev0"
source = { editable = "." }
dependencies = [
    { name = "pandas", extra = ["excel", "hdf5"] },
    { name = "pandas", extra = ["html"], marker = "os_name != 'posix'" },
    { name = "pandas", extra = ["output-formatting", "plot"], marker = "os_name == 'posix'" },
]
```

Fixes #4888
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Experimental behavior
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants