Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Closed
mkoeppe opened this issue Aug 23, 2023 · 16 comments · Fixed by #24511
Closed

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

mkoeppe opened this issue Aug 23, 2023 · 16 comments · Fixed by #24511
Assignees
Labels

Comments

@mkoeppe
Copy link
Contributor

mkoeppe commented Aug 23, 2023

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

@rgommers rgommers added this to the 1.26.0 release milestone Aug 23, 2023
@rgommers
Copy link
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?

@mattip
Copy link
Member

mattip commented Aug 23, 2023

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

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Aug 23, 2023

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

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Aug 23, 2023

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

@stefanv
Copy link
Contributor

stefanv commented Aug 24, 2023

Thanks for handling it, @mattip

@stefanv
Copy link
Contributor

stefanv commented Aug 24, 2023

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.

@mattip
Copy link
Member

mattip commented Aug 24, 2023

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

@mattip mattip reopened this Aug 24, 2023
@mattip mattip 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 Aug 24, 2023
@rgommers
Copy link
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.

@rgommers rgommers 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 Aug 24, 2023
@rgommers
Copy link
Member

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

@mattip
Copy link
Member

mattip commented Aug 24, 2023

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

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Aug 24, 2023

@mattip Just using python3 -m pip wheel.

@stefanv
Copy link
Contributor

stefanv commented Aug 24, 2023

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.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Aug 24, 2023

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

@rgommers
Copy link
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.

@mattip
Copy link
Member

mattip commented Aug 25, 2023

That makes sense. Thanks for the explanation.

@stefanv
Copy link
Contributor

stefanv commented Aug 25, 2023

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
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants