This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sysconfig returns the git commands for GITBRANCH, GITVERSION and GITTAG
Type: Stage: resolved
Components: Versions: Python 3.8
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: matrixise, ned.deily, vstinner
Priority: normal Keywords: patch

Created on 2018-10-15 20:10 by matrixise, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9895 closed matrixise, 2018-10-15 20:17
Messages (6)
msg327779 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-10-15 20:10
> ./configure --prefix=$PWD-build --with-pydebug --quiet
> make -j 4 -s
> git --git-dir ./.git rev-parse --short HEAD
ee171a26c1
> ./python -m sysconfig | grep GIT
GITBRANCH = "git --git-dir ./.git name-rev --name-only HEAD"
GITTAG = "git --git-dir ./.git describe --all --always --dirty"
GITVERSION = "git --git-dir ./.git rev-parse --short HEAD"

Normally, I should get the real values in these variables and not the git commands.
I don't understand why there are the git commands, I don't want to execute the commands, just get the git information.

The result should be
GITBRANCH = "master"
GITTAG = "heads/master"
GITVERSION = "ee171a26c1"

I think there is an issue. Is it right?
msg327780 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-10-15 20:30
Git informations are available as:

>>> sys._git
('CPython', 'heads/fakerepr', 'd353239f83')
>>> sys.version
'3.8.0a0 (heads/fakerepr:d353239f83, Oct 15 2018, 13:20:43) \n[GCC 8.1.1 20180712 (Red Hat 8.1.1-5)]'
msg327781 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-10-15 20:31
sure, but you can also get these info from sysconfig. and for me, there is a problem with sysconfig. two solutions, remove GIT* from sysconfig or fix sysconfig with the right values.
msg327783 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-10-15 20:37
It seems like you misunderstood the purpose of these variables. They are only used to build getbuildinfo which is used to fill sys._git. Depending on the platform and git version, there are different ways to get the version, branch and tag. These variables should not be used to get the Git version, branch and tag: sys._git is here for that. Hum, sadly it's not documented. Or you can parse sys.version.
msg327785 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-10-15 21:01
Victor is correct.  Those GIT* variable are there to communicate between ./configure and the Makefile; they are *not* intended to have actual values for change ids or branch names. Many variables in the Makefile are not intended to be used outside of the build except for those that are explicitly documented or are well-known autoconf variables, like CFLAGS.

While any Git VCS info for the build is captured in sys._git, the _ prefix indicates it is a Python private attribute and thus is not documented.  The documented way to get any VCS info is via the platform module:

$ /usr/local/bin/python3.7
Python 3.7.1rc2 (v3.7.1rc2:6c06ef7dc3, Oct 13 2018, 05:10:29)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.python_branch()
'v3.7.1rc2'
>>> platform.python_revision()
'6c06ef7dc3'
>>> platform.python_build()
('v3.7.1rc2:6c06ef7dc3', 'Oct 13 2018 05:10:29')

https://docs.python.org/3/library/platform.html#platform.python_revision
msg327786 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2018-10-15 21:03
yep, sure and now, after your explanations (you and victor) I just closed my PR, but to be honnest with your, I was really surprised when I have seen the git commands in the GIT* variables.

Thanks for your review and your time.
History
Date User Action Args
2022-04-11 14:59:07adminsetgithub: 79175
2018-10-15 21:03:29matrixisesetstatus: open -> closed
stage: resolved
2018-10-15 21:03:23matrixisesetstatus: closed -> open
resolution: not a bug ->
messages: + msg327786

stage: resolved -> (no value)
2018-10-15 21:01:47ned.deilysetstatus: open -> closed

nosy: + ned.deily
messages: + msg327785

resolution: not a bug
stage: resolved
2018-10-15 20:37:01vstinnersetmessages: + msg327783
2018-10-15 20:31:49matrixisesetmessages: + msg327781
stage: patch review -> (no value)
2018-10-15 20:30:09vstinnersetnosy: + vstinner
messages: + msg327780
2018-10-15 20:17:55matrixisesetkeywords: + patch
stage: patch review
pull_requests: + pull_request9257
2018-10-15 20:10:06matrixisecreate