Skip to content

Commit bbb04c3

Browse files
committed
Use rust _platform to version
1 parent 6660b64 commit bbb04c3

File tree

3 files changed

+20
-92
lines changed

3 files changed

+20
-92
lines changed

Lib/platform.py

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -971,14 +971,6 @@ def processor():
971971
r'\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*'
972972
r'\[PyPy [^\]]+\]?')
973973

974-
_rustpython_sys_version_parser = re.compile(
975-
r'RustPython '
976-
r'([\w.+]+)\s*' # "version<space>"
977-
r'\(#?([^,]+)' # "(#buildno"
978-
r'(?:,\s*([\w ]*)' # ", builddate"
979-
r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>"
980-
r'\[([^\]]+)\]?', re.ASCII) # "[compiler]"
981-
982974
_sys_version_cache = {}
983975

984976
def _sys_version(sys_version=None):
@@ -1051,16 +1043,6 @@ def _sys_version(sys_version=None):
10511043
version, buildno, builddate, buildtime = match.groups()
10521044
compiler = ""
10531045

1054-
elif "RustPython" in sys_version:
1055-
# RustPython
1056-
name = "RustPython"
1057-
match = _rustpython_sys_version_parser.match(sys_version)
1058-
if match is None:
1059-
raise ValueError("failed to parse RustPython sys.version: %s" %
1060-
repr(sys_version))
1061-
version, buildno, builddate, buildtime, compiler = \
1062-
match.groups()
1063-
10641046
else:
10651047
# CPython
10661048
match = _sys_version_parser.match(sys_version)
@@ -1095,28 +1077,8 @@ def _sys_version(sys_version=None):
10951077
_sys_version_cache[sys_version] = result
10961078
return result
10971079

1098-
def python_implementation():
1099-
1100-
""" Returns a string identifying the Python implementation.
1101-
1102-
Currently, the following implementations are identified:
1103-
'CPython' (C implementation of Python),
1104-
'IronPython' (.NET implementation of Python),
1105-
'Jython' (Java implementation of Python),
1106-
'PyPy' (Python implementation of Python).
1107-
1108-
"""
1109-
return _sys_version()[0]
1110-
1111-
def python_version():
1112-
1113-
""" Returns the Python version as string 'major.minor.patchlevel'
1114-
1115-
Note that unlike the Python sys.version, the returned value
1116-
will always include the patchlevel (it defaults to 0).
1117-
1118-
"""
1119-
return _sys_version()[1]
1080+
# RustPython specific
1081+
from _platform import *
11201082

11211083
def python_version_tuple():
11221084

@@ -1127,50 +1089,7 @@ def python_version_tuple():
11271089
will always include the patchlevel (it defaults to 0).
11281090
11291091
"""
1130-
return tuple(_sys_version()[1].split('.'))
1131-
1132-
def python_branch():
1133-
1134-
""" Returns a string identifying the Python implementation
1135-
branch.
1136-
1137-
For CPython this is the SCM branch from which the
1138-
Python binary was built.
1139-
1140-
If not available, an empty string is returned.
1141-
1142-
"""
1143-
1144-
return _sys_version()[2]
1145-
1146-
def python_revision():
1147-
1148-
""" Returns a string identifying the Python implementation
1149-
revision.
1150-
1151-
For CPython this is the SCM revision from which the
1152-
Python binary was built.
1153-
1154-
If not available, an empty string is returned.
1155-
1156-
"""
1157-
return _sys_version()[3]
1158-
1159-
def python_build():
1160-
1161-
""" Returns a tuple (buildno, builddate) stating the Python
1162-
build number and date as strings.
1163-
1164-
"""
1165-
return _sys_version()[4:6]
1166-
1167-
def python_compiler():
1168-
1169-
""" Returns a string identifying the compiler used for compiling
1170-
Python.
1171-
1172-
"""
1173-
return _sys_version()[6]
1092+
return tuple(python_version().split('.'))
11741093

11751094
### The Opus Magnum of platform strings :-)
11761095

vm/src/stdlib/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ mod keyword;
1717
mod marshal;
1818
mod math;
1919
mod operator;
20+
mod platform;
2021
mod pystruct;
2122
mod random;
2223
mod re;
@@ -75,6 +76,7 @@ pub fn get_module_inits() -> HashMap<String, StdlibInitFunc> {
7576
"marshal".to_owned() => Box::new(marshal::make_module),
7677
"math".to_owned() => Box::new(math::make_module),
7778
"_operator".to_owned() => Box::new(operator::make_module),
79+
"_platform".to_owned() => Box::new(platform::make_module),
7880
"regex_crate".to_owned() => Box::new(re::make_module),
7981
"_random".to_owned() => Box::new(random::make_module),
8082
"_string".to_owned() => Box::new(string::make_module),

vm/src/version.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::time::{Duration, UNIX_EPOCH};
2323

2424
pub fn get_version() -> String {
2525
format!(
26-
"RustPython {:.80} ({:.80}) {:.80}",
26+
"{:.80} ({:.80}) \n[{:.80}]",
2727
get_version_number(),
2828
get_build_info(),
2929
get_compiler()
@@ -40,16 +40,16 @@ pub fn get_version_info() -> VersionInfo {
4040
}
4141
}
4242

43-
fn get_version_number() -> String {
43+
pub fn get_version_number() -> String {
4444
format!("{}.{}.{}{}", MAJOR, MINOR, MICRO, RELEASELEVEL)
4545
}
4646

47-
fn get_compiler() -> String {
47+
pub fn get_compiler() -> String {
4848
let rustc_version = rustc_version_runtime::version_meta();
49-
format!("\n[rustc {}]", rustc_version.semver)
49+
format!("rustc {}", rustc_version.semver)
5050
}
5151

52-
fn get_build_info() -> String {
52+
pub fn get_build_info() -> String {
5353
// See: https://reproducible-builds.org/docs/timestamps/
5454
let git_revision = get_git_revision();
5555
let separator = if git_revision.is_empty() { "" } else { ":" };
@@ -78,7 +78,7 @@ pub fn get_git_tag() -> String {
7878
option_env!("RUSTPYTHON_GIT_TAG").unwrap_or("").to_owned()
7979
}
8080

81-
fn get_git_branch() -> String {
81+
pub fn get_git_branch() -> String {
8282
option_env!("RUSTPYTHON_GIT_BRANCH")
8383
.unwrap_or("")
8484
.to_owned()
@@ -107,14 +107,21 @@ fn get_git_timestamp_datetime() -> DateTime<Local> {
107107
datetime
108108
}
109109

110-
fn get_git_date() -> String {
110+
pub fn get_git_date() -> String {
111111
let datetime = get_git_timestamp_datetime();
112112

113113
datetime.format("%b %e %Y").to_string()
114114
}
115115

116-
fn get_git_time() -> String {
116+
pub fn get_git_time() -> String {
117117
let datetime = get_git_timestamp_datetime();
118118

119119
datetime.format("%H:%M:%S").to_string()
120120
}
121+
122+
pub fn get_git_datetime() -> String {
123+
let date = get_git_date();
124+
let time = get_git_time();
125+
126+
format!("{} {}", date, time)
127+
}

0 commit comments

Comments
 (0)