uv/crates/uv-python
konsti 2f5a64a8b3
Unify cargo features (#9267)
When building only a single crate in the workspace to run its tests, we
often recompile a lot of other, unrelated crates. Whenever cargo has a
different set of crate features, it needs to recompile. By moving some
features (non-exhaustive for now) to the workspace level, we always
activate them an avoid recompiling.

The cargo docs mismatch the behavior of cargo around default-deps, so I
filed that upstream and left most `default-features` mismatches:
https://github.com/rust-lang/cargo/issues/14841.

Reference script:

```python
import tomllib
from collections import defaultdict
from pathlib import Path

uv = Path("/home/konsti/projects/uv")
skip_list = ["uv-trampoline", "uv-dev", "uv-performance-flate2-backend", "uv-performance-memory-allocator"]

root_feature_map = defaultdict(set)
root_default_features = defaultdict(bool)
cargo_toml = tomllib.loads(uv.joinpath("Cargo.toml").read_text())
for dep, declaration in cargo_toml["workspace"]["dependencies"].items():
    root_default_features[dep] = root_default_features[dep] or declaration.get("default-features", True)
    root_feature_map[dep].update(declaration.get("features", []))

feature_map = defaultdict(set)
default_features = defaultdict(bool)
for crate in uv.joinpath("crates").iterdir():
    if crate.name in skip_list:
        continue
    if not crate.joinpath("Cargo.toml").is_file():
        continue
    cargo_toml = tomllib.loads(crate.joinpath("Cargo.toml").read_text())
    for dep, declaration in cargo_toml.get("dependencies", {}).items():
        # If any item uses default features, they are used everywhere
        default_features[dep] = default_features[dep] or declaration.get("default-features", True)
        feature_map[dep].update(declaration.get("features", []))

for dep, features in sorted(feature_map.items()):
    features = features - root_feature_map.get(dep, set())
    if not features and default_features[dep] == root_default_features[dep]:
        continue
    print(dep, default_features[dep], sorted(features))
```
2024-11-20 16:11:24 +01:00
..
python Use base executable to set virtualenv Python path (#8481) 2024-11-07 14:29:54 -06:00
src Add retries for Python downloads (#9274) 2024-11-20 09:42:42 -05:00
Cargo.toml Unify cargo features (#9267) 2024-11-20 16:11:24 +01:00
download-metadata.json Fix a typo in fetch-download-metadata.py (#8515) 2024-10-24 07:33:14 -05:00
fetch-download-metadata.py Fix a typo in fetch-download-metadata.py (#8515) 2024-10-24 07:33:14 -05:00
template-download-metadata.py Add support for managed installs of free-threaded Python (#8100) 2024-10-14 15:18:52 -05:00