Skip to content

BUG: numpy 1.26.0b1 fails to build from sdist when no git is present #24503

Closed

Description

@mkoeppe

Describe the issue:


<edit>: (@mattip) Adding the root cause:

The version is missing from the sdist for 1.26b1, resulting in an attempt to get it via git. But that does not work because ...

<edit>


The gitversion.py script introduced in #24196 is broken when no git binary is available.

Reproduce the code example:

$ python3 numpy/_build_utils/gitversion.py

Error message:

$ python3 numpy/_build_utils/gitversion.py 
Traceback (most recent call last):
  File "/sage/local/var/lib/sage/venv-python3.11/var/tmp/sage/build/numpy-1.26.0b1/src/numpy/_build_utils/gitversion.py", line 68, in <module>
    version, git_hash = git_version(init_version())
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/sage/local/var/lib/sage/venv-python3.11/var/tmp/sage/build/numpy-1.26.0b1/src/numpy/_build_utils/gitversion.py", line 53, in git_version
    return version, git_hash
                    ^^^^^^^^
UnboundLocalError: cannot access local variable 'git_hash' where it is not associated with a value

Runtime information:

N/A

Context for the issue:

sagemath/sage#36123

Activity

  1. added this to the 1.26.0 release milestone on Aug 23, 2023
  2. rgommers commented on Aug 23, 2023

    @rgommers
    Member

    Thanks for the report @mkoeppe. That's a bug indeed. The gitversion.py script should check for a file containing the needed git hash (as was done with if fs.exists('_version_meson.py') before gh-24196). Building from an sdist should work when git is not installed.

    @stefanv can you please have a look at this?

  3. mattip commented on Aug 23, 2023

    @mattip
    Member

    While #24511, the sage build of 1.26b1 should not be hitting this. Are you building from the sdist or from a github archive?

  4. mkoeppe commented on Aug 23, 2023

    @mkoeppe
    ContributorAuthor

    Building from the sdist from PyPI. I've just added #24511 as a patch. Tests running at https://github.com/mkoeppe/sage/actions/runs/5954216252, I'll report back when finished

  5. mkoeppe commented on Aug 23, 2023

    @mkoeppe
    ContributorAuthor

    I confirm that this fixes the problem. Thanks for the quick fix @mattip

  6. stefanv commented on Aug 24, 2023

    @stefanv
    Contributor

    Thanks for handling it, @mattip

  7. stefanv commented on Aug 24, 2023

    @stefanv
    Contributor

    Note that the idea is to always generate the version and distribute it as part of the sdist. That way, the git hash should never be empty.

  8. mattip commented on Aug 24, 2023

    @mattip
    Member

    So if the version is not in the sdist, I guess we should reopen this and figure out why it is missing.

  9. reopened this on Aug 24, 2023
  10. changed the title [-]BUG: numpy 1.26.0b1 fails to build from sdist when no git is present[/-] [+]BUG: numpy 1.26.0b1 sdist is misssing the git version[/+] on Aug 24, 2023
  11. rgommers commented on Aug 24, 2023

    @rgommers
    Member

    It is present, Stefan's comment was only clarifying. I just checked it when working on the next fix (gh-24515), version.py is part of the sdist.

  12. changed the title [-]BUG: numpy 1.26.0b1 sdist is misssing the git version[/-] [+]BUG: numpy 1.26.0b1 fails to build from sdist when no git is present[/+] on Aug 24, 2023
  13. rgommers commented on Aug 24, 2023

    @rgommers
    Member

    The meson.add_dist_script call takes care of this. It should be robust.

  14. mattip commented on Aug 24, 2023

    @mattip
    Member

    Weird. @mkoeppe how did the sage build not find it? What is the command you are using to build NumPy 1.26b1?

  15. mkoeppe commented on Aug 24, 2023

    @mkoeppe
    ContributorAuthor

    @mattip Just using python3 -m pip wheel.

  16. stefanv commented on Aug 24, 2023

    @stefanv
    Contributor

    Does the above command go via setuptools? When I run:

    python3 -m build -s
    

    it invokes Meson and builds the sdist that contains version.py.

  17. mkoeppe commented on Aug 24, 2023

    @mkoeppe
    ContributorAuthor

    No, python3 -m pip wheel does not invoke setuptools. It runs the build system declared in pyproject.toml

  18. rgommers commented on Aug 25, 2023

    @rgommers
    Member

    The problem here was simply that gitversion.py is unconditionally triggered right at the top of meson.build, and the git_hash = '' for when git is not installed was in the wrong place. It was fixed with Matti's one-line patch, and nothing else was wrong.

  19. mattip commented on Aug 25, 2023

    @mattip
    Member

    That makes sense. Thanks for the explanation.

  20. stefanv commented on Aug 25, 2023

    @stefanv
    Contributor

    Thanks for checking that; I wasn't able to look at the time, but that sets my mind at ease.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions