Skip to content

Ignore dynamic version in source dist #9549

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
merged 3 commits into from
Dec 4, 2024

Conversation

konstin
Copy link
Member

@konstin konstin commented Dec 1, 2024

When encountering dynamic = ["version"] in the pyproject.toml of a source dist, we can ignore that and treat it as a statically known metadata distribution, since the filename tells us the version and that version must not change on build.

This fixed locking PyGObject 3.50.0 from pygobject-3.50.0.tar.gz (minimized):

[project]
name = "PyGObject"
description = "Python bindings for GObject Introspection"
requires-python = ">=3.9, <4.0"
dependencies = [
    "pycairo>=1.16"
]
dynamic = ["version"]

Afterwards, uv add --no-sync toga passes on Ubuntu 24.04 without the pygobject build deps, when previously it needed { name = "pygobject", version = "3.50.0", requires-dist = [], requires-python = ">=3.9" }.

I've added a check that source distribution versions are respected after build.

Fixes #9548

Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

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

This makes sense.

@charliermarsh
Copy link
Member

Works on macOS (and fails with released uv).

@charliermarsh charliermarsh marked this pull request as ready for review December 2, 2024 19:34
@charliermarsh
Copy link
Member

I think the only downside here is that if the built version doesn't match the declared version, we no longer catch it. Today, we'd raise an error. After this PR, we'd assume the declared version is correct.

@konstin
Copy link
Member Author

konstin commented Dec 4, 2024

At least in uv build, we weren't checking version matching at all: #9633 (though that PR also only checks filenames, not pyproject.toml and METADATA, too; the filename mismatch is something that the installer wouldn't catch).

@konstin konstin added enhancement New feature or improvement to existing functionality performance Potential performance improvement labels Dec 4, 2024
@konstin
Copy link
Member Author

konstin commented Dec 4, 2024

We're also missing the check with static metadata atm, let me see how hard that is.

#[test]
fn test_version_sdist_wrong_version() -> Result<()> {
    let context = TestContext::new("3.12");

    let pyproject_toml = r#"
    [project]
    name = "foo"
    requires-python = ">=3.9"
    dependencies = []
    version = "10.11.12"
    "#;

    let setup_py = indoc! {r#"
    from setuptools import setup

    setup(name="foo", version="10.11.12")
    "#};

    let source_dist = context.temp_dir.child("foo-1.2.3.tar.gz");
    // Flush and close after finishing.
    {
        let file = File::create(source_dist.path())?;
        let enc = GzEncoder::new(file, flate2::Compression::default());
        let mut tar = tar::Builder::new(enc);

        for (path, contents) in [
            ("foo-1.2.3/pyproject.toml", pyproject_toml),
            ("foo-1.2.3/setup.py", setup_py),
        ] {
            let mut header = tar::Header::new_gnu();
            header.set_size(contents.len() as u64);
            header.set_mode(0o644);
            header.set_cksum();
            tar.append_data(&mut header, path, Cursor::new(contents))?;
        }
        tar.finish()?;
    }

    uv_snapshot!(context.filters(), context
        .pip_install()
        .arg(source_dist.path()), @r###"
    success: true
    exit_code: 0
    ----- stdout -----

    ----- stderr -----
    Resolved 1 package in [TIME]
    Prepared 1 package in [TIME]
    Installed 1 package in [TIME]
     + foo==10.11.12 (from file://[TEMP_DIR]/foo-1.2.3.tar.gz)
    "###
    );

    Ok(())
}

When encountering `dynamic = ["version"]` in the pyproject.toml of a source dist, we can ignore that and treat it as a statically known metadata distribution, since the filename tells us the version and that version must not change on build.

This fixed locking PyGObject 3.50.0 from `
pygobject-3.50.0.tar.gz` (minimized):

```toml
[project]
name = "PyGObject"
description = "Python bindings for GObject Introspection"
requires-python = ">=3.9, <4.0"
dependencies = [
    "pycairo>=1.16"
]
dynamic = ["version"]
```

Afterwards, `uv add --no-sync toga` passes on Ubuntu 24.04 without the pygobject build deps, when previously it needed `{ name = "pygobject", version = "3.50.0", requires-dist = [], requires-python = ">=3.9" }`.
@konstin konstin force-pushed the konsti/allow-dynamic-version-in-source-dist branch from 85230b9 to e94a0f6 Compare December 4, 2024 11:24
We may not always have a version, but if we do, we should record it.
@konstin konstin force-pushed the konsti/allow-dynamic-version-in-source-dist branch from e94a0f6 to fb87ce1 Compare December 4, 2024 11:26
@konstin konstin enabled auto-merge (squash) December 4, 2024 11:27
@konstin
Copy link
Member Author

konstin commented Dec 4, 2024

I've added a check and a test

@konstin konstin force-pushed the konsti/allow-dynamic-version-in-source-dist branch from fb87ce1 to c31b37d Compare December 4, 2024 11:31
@konstin konstin merged commit c314c68 into main Dec 4, 2024
64 checks passed
@konstin konstin deleted the konsti/allow-dynamic-version-in-source-dist branch December 4, 2024 11:40
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Dec 9, 2024
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.5.6` -> `0.5.7` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>astral-sh/uv (astral-sh/uv)</summary>

### [`v0.5.7`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#057)

[Compare Source](astral-sh/uv@0.5.6...0.5.7)

##### Enhancements

-   Ignore dynamic version in source dist ([#&#8203;9549](astral-sh/uv#9549))
-   Improve build frontend error handling ([#&#8203;9611](astral-sh/uv#9611))
-   Un-hide `uv build --no-build-logs` option ([#&#8203;9642](astral-sh/uv#9642))
-   Flag version mismatch between sdist and wheel during `uv build` ([#&#8203;9633](astral-sh/uv#9633))
-   Improve message when updater receipt is for a different uv executable ([#&#8203;9487](astral-sh/uv#9487))
-   Add environment variable to disable writing installer metadata files ([#&#8203;8877](astral-sh/uv#8877))
-   Add managed downloads for the latest CPython releases: `3.9.21`, `3.10.16`, `3.11.11`, `3.12.8`, and `3.13.1` ([#&#8203;9696](astral-sh/uv#9696))

##### Preview features

-   Build backend: Add hint on import with preview disabled ([#&#8203;9691](astral-sh/uv#9691))
-   Build backend: Add direct builds to the resolver and installer ([#&#8203;9621](astral-sh/uv#9621))
-   Build backend: Add integration test for scripts ([#&#8203;9635](astral-sh/uv#9635))
-   Build backend: Add template to `uv init` ([#&#8203;9661](astral-sh/uv#9661))
-   Build backend: Add `--list` option ([#&#8203;9610](astral-sh/uv#9610))

##### Bug fixes

-   Create missing parent directories for output file of `uv export` / `uv pip compile` ([#&#8203;9648](astral-sh/uv#9648))
-   Fix missing display of non-freethreaded Python 3.13 in `python list` ([#&#8203;9669](astral-sh/uv#9669))
-   Implement `Ord` and `PartialOrd` without origin for `Requirement` ([#&#8203;9624](astral-sh/uv#9624))
-   Include more sources to avoid lowest bound warning ([#&#8203;9644](astral-sh/uv#9644))
-   Respect build tag priority in `uv.lock` ([#&#8203;9677](astral-sh/uv#9677))

##### Documentation

-   Add `build-essentials` note to build failures doc ([#&#8203;9641](astral-sh/uv#9641))
-   Add entry-point for distroless image in GitLab documentation ([#&#8203;9093](astral-sh/uv#9093))
-   Add documentation for `uv python pin` without a `REQUEST` argument ([#&#8203;9631](astral-sh/uv#9631))
-   Add a link to `uv python pin` reference docs ([#&#8203;9630](astral-sh/uv#9630))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement to existing functionality performance Potential performance improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resolving toga-gtk attempts to build pygobject on MacOS
2 participants