Skip to content

Intermittent Build Issues Caused by datetime.now() in setup.py #178

@andrej

Description

@andrej

I believe the following line, which makes the wheel build nondeterministic, is causing some intermittent build failures for us:

now = datetime.now()

My understanding is that pip calls setup.py twice. Once to get metadata about the package (and resolve dependencies), and then later again to build the wheel. If enough time elapses between the two, the versions won't match, causing intermittent failures.

A couple ideas:

  • Remove the date/time from the version string entirely.
  • Cache the date/time version string between the first call to setup.py and the second one. Something like writing version_s to a version file if that file does not exist, and reading it from the file if it does exist.
  • Instead of datetime.now() use the "last modified" time of the most recently modified file in the repository. Drawback is I don't know how reliable the last modified timestamp on files is. It might be good enough (would just use the timestamp of when the repository was checked out).
  • Hash all files in the repository (to capture uncomitted changes as well) using something like find . -type f | xargs sha256sum | sha256sum. I don't know if this would work since it yields non-monotonically increasing values, so probably not suitable for a version string.

Let me know what you think. I'd be happy to make any of these changes if you don't have the time.

Detailed error messages I get during intermittent failures
WARNING: Built wheel for aie-python-extras is invalid: Wheel has unexpected file name: expected '0.0.8.2025082823+ba2e6fe', got '0.0.8.2025082900+ba2e6fe'

Unfortunately, pip appears to treat this not just as a warning, but fails due to this:

Failed to build aie-python-extras
error: failed-wheel-build-for-install

× Failed to build installable wheels for some pyproject.toml based projects
╰─> aie-python-extras

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions