FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Doc/tools/extensions/patchlevel.py at 3.5 · python/cpython · GitHub
python
cpython
Repository navigation
Code
Issues
5k+
(5k+)
Pull requests
2.4k
(2.4k)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython
/
Doc
/
tools
/
extensions
/
patchlevel.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
71 lines (57 loc) · 1.94 KB
Breadcrumbs
cpython
/
Doc
/
tools
/
extensions
/
patchlevel.py
Copy path
File metadata and controls
71 lines (57 loc) · 1.94 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
"""
patchlevel.py
~~~~~~~~~~~~~
Extract version info from Include/patchlevel.h.
Adapted from Doc/tools/getversioninfo.
:copyright: 2007-2008 by Georg Brandl.
:license: Python license.
"""
from
__future__
import
print_function
import
os
import
re
import
sys
def
get_header_version_info
(
srcdir
):
patchlevel_h
=
os
.
path
.
join
(
srcdir
,
'..'
,
'Include'
,
'patchlevel.h'
)
# This won't pick out all #defines, but it will pick up the ones we
# care about.
rx
=
re
.
compile
(
r'\s*#define\s+([a-zA-Z][a-zA-Z_0-9]*)\s+([a-zA-Z_0-9]+)'
)
d
=
{}
f
=
open
(
patchlevel_h
)
try
:
for
line
in
f
:
m
=
rx
.
match
(
line
)
if
m
is
not
None
:
name
,
value
=
m
.
group
(
1
,
2
)
d
[
name
]
=
value
finally
:
f
.
close
()
release
=
version
=
'%s.%s'
%
(
d
[
'PY_MAJOR_VERSION'
],
d
[
'PY_MINOR_VERSION'
])
micro
=
int
(
d
[
'PY_MICRO_VERSION'
])
release
+=
'.'
+
str
(
micro
)
level
=
d
[
'PY_RELEASE_LEVEL'
]
suffixes
=
{
'PY_RELEASE_LEVEL_ALPHA'
:
'a'
,
'PY_RELEASE_LEVEL_BETA'
:
'b'
,
'PY_RELEASE_LEVEL_GAMMA'
:
'rc'
,
}
if
level
!=
'PY_RELEASE_LEVEL_FINAL'
:
release
+=
suffixes
[
level
]
+
str
(
int
(
d
[
'PY_RELEASE_SERIAL'
]))
return
version
,
release
def
get_sys_version_info
():
major
,
minor
,
micro
,
level
,
serial
=
sys
.
version_info
release
=
version
=
'%s.%s'
%
(
major
,
minor
)
release
+=
'.%s'
%
micro
if
level
!=
'final'
:
release
+=
'%s%s'
%
(
level
[
0
],
serial
)
return
version
,
release
def
get_version_info
():
try
:
return
get_header_version_info
(
'.'
)
except
(
IOError
,
OSError
):
version
,
release
=
get_sys_version_info
()
print
(
'Can
\'
t get version info from Include/patchlevel.h, '
\
'using version of this interpreter (%s).'
%
release
,
file
=
sys
.
stderr
)
return
version
,
release
if
__name__
==
'__main__'
:
print
(
get_header_version_info
(
'.'
)[
1
])
Back
|
FazBrowse Home
|
New Git URL