Skip to content

Commit c9a63a4

Browse files
authored
Merge pull request #260 from dongly/ver
从 env.json 中获取版本号
2 parents 501626f + 1eb5bfe commit c9a63a4

File tree

3 files changed

+56
-15
lines changed

3 files changed

+56
-15
lines changed

env.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,15 @@
3838

3939
from cmds import *
4040
from vars import Export
41-
42-
__version__ = ''
43-
44-
# try to read env.json to get information
45-
try:
46-
with open('env.json', 'r') as file:
47-
env_data = json.load(file)
48-
__version__ = env_data['name'] + ' '+ env_data['version']
49-
except Exception as e:
50-
# use the default 'v2.0.1'
51-
__version__ = 'RT-Thread Env Tool v2.0.1'
41+
from version import get_rt_env_version
5242

5343
def show_version_warning():
5444
rtt_ver = get_rtt_verion()
45+
rt_env_name, rt_env_ver = get_rt_env_version()
5546

5647
if rtt_ver <= (5, 1, 0) and rtt_ver != (0, 0, 0):
5748
print('===================================================================')
58-
print('Welcome to %s' % __version__)
49+
print('Welcome to %s %s' % (rt_env_name, rt_env_ver))
5950
print('===================================================================')
6051
# print('')
6152
print('env v2.0 has made the following important changes:')
@@ -79,7 +70,9 @@ def init_argparse():
7970
parser = argparse.ArgumentParser(description=__doc__)
8071
subs = parser.add_subparsers()
8172

82-
parser.add_argument('-v', '--version', action='version', version=__version__)
73+
rt_env_name, rt_env_ver = get_rt_env_version()
74+
env_ver_str = '%s %s' % (rt_env_name, rt_env_ver)
75+
parser.add_argument('-v', '--version', action='version', version=env_ver_str)
8376

8477
cmd_system.add_parser(subs)
8578
cmd_menuconfig.add_parser(subs)

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from setuptools import setup
2+
from version import get_rt_env_version
23

4+
env_name, env_ver = get_rt_env_version()
35
setup(
46
name='env',
5-
version='2.0.1',
6-
description='RT-Thread Env',
7+
version=env_ver,
8+
description=env_name,
79
url='https://github.com/RT-Thread/env.git',
810
author='RT-Thread Development Team',
911
author_email='[email protected]',

version.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- coding:utf-8 -*-
2+
#
3+
# File : version.py
4+
# This file is part of RT-Thread RTOS
5+
# COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
6+
#
7+
# This program is free software; you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation; either version 2 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License along
18+
# with this program; if not, write to the Free Software Foundation, Inc.,
19+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20+
#
21+
# Change Logs:
22+
# Date Author Notes
23+
# 2025-06-23 Dongly Add get_rt_env_version function
24+
25+
import json
26+
27+
def get_rt_env_version():
28+
rt_env_ver = None
29+
rt_env_name = None
30+
31+
# try to read env.json to get information
32+
try:
33+
with open('env.json', 'r') as file:
34+
env_data = json.load(file)
35+
rt_env_name = env_data['name']
36+
rt_env_ver = env_data['version']
37+
except Exception as e:
38+
print("Failed to read env.json: %s" % str(e))
39+
40+
if rt_env_name is None:
41+
rt_env_name = 'RT-Thread Env Tool'
42+
if rt_env_ver is None:
43+
# use the default 'v2.0.1'
44+
rt_env_ver = 'v2.0.1'
45+
46+
return rt_env_name, rt_env_ver

0 commit comments

Comments
 (0)