Skip to content

从 env.json 中获取版本号 #260

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions env.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,15 @@

from cmds import *
from vars import Export

__version__ = ''

# try to read env.json to get information
try:
with open('env.json', 'r') as file:
env_data = json.load(file)
__version__ = env_data['name'] + ' '+ env_data['version']
except Exception as e:
# use the default 'v2.0.1'
__version__ = 'RT-Thread Env Tool v2.0.1'
from version import get_rt_env_version

def show_version_warning():
rtt_ver = get_rtt_verion()
rt_env_name, rt_env_ver = get_rt_env_version()

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

parser.add_argument('-v', '--version', action='version', version=__version__)
rt_env_name, rt_env_ver = get_rt_env_version()
env_ver_str = '%s %s' % (rt_env_name, rt_env_ver)
parser.add_argument('-v', '--version', action='version', version=env_ver_str)

cmd_system.add_parser(subs)
cmd_menuconfig.add_parser(subs)
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from setuptools import setup
from version import get_rt_env_version

env_name, env_ver = get_rt_env_version()
setup(
name='env',
version='2.0.1',
description='RT-Thread Env',
version=env_ver,
description=env_name,
url='https://github.com/RT-Thread/env.git',
author='RT-Thread Development Team',
author_email='rt-thread@rt-thread.org',
Expand Down
46 changes: 46 additions & 0 deletions version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- coding:utf-8 -*-
#
# File : version.py
# This file is part of RT-Thread RTOS
# COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Change Logs:
# Date Author Notes
# 2025-06-23 Dongly Add get_rt_env_version function

import json

def get_rt_env_version():
rt_env_ver = None
rt_env_name = None

# try to read env.json to get information
try:
with open('env.json', 'r') as file:
env_data = json.load(file)
rt_env_name = env_data['name']
rt_env_ver = env_data['version']
except Exception as e:
print("Failed to read env.json: %s" % str(e))

if rt_env_name is None:
rt_env_name = 'RT-Thread Env Tool'
if rt_env_ver is None:
# use the default 'v2.0.1'
rt_env_ver = 'v2.0.1'

return rt_env_name, rt_env_ver