Skip to content
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
21 changes: 11 additions & 10 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
# ============
* text=auto
* text=auto eol=lf

# Source files
# ============
*.pxd text eol=crlf diff=python
*.py text eol=crlf diff=python
*.py3 text eol=crlf diff=python
*.pyw text eol=crlf diff=python
*.pyx text eol=crlf diff=python
*.pyz text eol=crlf diff=python
*.pyi text eol=crlf diff=python
*.pxd text diff=python
*.py text diff=python
*.py3 text diff=python
*.pyw text diff=python
*.pyx text diff=python
*.pyz text diff=python
*.pyi text diff=python

# Binary files
# ============
Expand All @@ -26,7 +26,8 @@
*.pyo binary

# MarkDown
*.md text eol=crlf
*.md text

*.bat text eol=crlf
*.ps1 text eol=crlf
*.cmd text eol=crlf
*.ps1 text eol=crlf
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,14 @@ plugins/webui/frontend/test-results/

docs
documentation

# Temporary files
tmp
temp
*.bak

# AI
.omo/
.opencode/
AGENTS.md
CONTEXT.md
6 changes: 4 additions & 2 deletions cmds/cmd_package/cmd_package_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# 2020-04-08 SummerGift Optimize program structure
# 2020-04-13 SummerGift refactoring
# 2026-05-12 CYFS share hal-sdk packages in libraries and create bridge SConscript for hal-sdk packages in BSP packages
# 2026-09-12 Dongly Resolve submodule mirror urls via info.get_submodule_mirror_url
#

import json
Expand All @@ -43,6 +44,7 @@
import pkgsdb
from package import PackageOperation, Bridge_SConscript
from vars import Import, Export
from info import get_submodule_mirror_url
from .cmd_package_utils import (
get_url_from_mirror_server,
execute_command,
Expand Down Expand Up @@ -319,7 +321,7 @@ def get_mirror_giturl(submodule_name):
Retrurn the download address of the submodule on the mirror server from the submod_name.
"""

mirror_url = 'https://gitee.com/RT-Thread-Mirror/submod_' + submodule_name + '.git'
mirror_url = get_submodule_mirror_url('rt-thread', submodule_name)
return mirror_url


Expand All @@ -328,7 +330,7 @@ def get_esp_mirror_giturl(submodule_name):
submodule_name = "CException"
elif submodule_name == "unity":
submodule_name = "Unity"
mirror_url = 'https://gitee.com/esp-submodules/' + submodule_name + '.git'
mirror_url = get_submodule_mirror_url('esp', submodule_name)
return mirror_url


Expand Down
38 changes: 13 additions & 25 deletions cmds/cmd_package/cmd_package_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
# Change Logs:
# Date Author Notes
# 2020-04-08 SummerGift Optimize program structure
# 2026-09-12 Dongly Resolve packages/env repo URLs and statistics endpoint
# via env.json (info.get_source / info.get_api_url); logical
# repos no longer query the mirror server
#

import os
import uuid
from vars import Import
from .cmd_package_utils import execute_command, git_pull_repo, get_url_from_mirror_server, find_bool_macro_in_config
from info import get_source, get_api_url
from .cmd_package_utils import execute_command, git_pull_repo, find_bool_macro_in_config
from .cmd_package_update import need_using_mirror_download

try:
Expand All @@ -49,16 +53,8 @@ def upgrade_packages_index(force_upgrade=False):

pkgs_root = Import('pkgs_root')

if need_using_mirror_download():
get_package_url, get_ver_sha = get_url_from_mirror_server('packages', 'latest')

if get_package_url is not None:
git_repo = get_package_url
else:
print("Failed to get url from mirror server. Using default url.")
git_repo = 'https://gitee.com/RT-Thread-Mirror/packages.git'
else:
git_repo = 'https://github.com/RT-Thread/packages.git'
src = get_source('packages', use_mirror=need_using_mirror_download())
git_repo = src.url

packages_root = pkgs_root
pkgs_path = os.path.join(packages_root, 'packages')
Expand All @@ -70,7 +66,7 @@ def upgrade_packages_index(force_upgrade=False):
else:
if force_upgrade:
execute_command('git fetch --all', cwd=pkgs_path)
execute_command('git reset --hard origin/master', cwd=pkgs_path)
execute_command('git reset --hard origin/%s' % src.branch, cwd=pkgs_path)
print("Begin to upgrade env packages.")
git_pull_repo(pkgs_path, git_repo)
print("==============================> Env packages upgrade done \n")
Expand All @@ -96,23 +92,14 @@ def upgrade_env_script(force_upgrade=False):

env_root = Import('env_root')

if need_using_mirror_download():
get_package_url, get_ver_sha = get_url_from_mirror_server('env', 'latest')

if get_package_url is not None:
env_scripts_repo = get_package_url
else:
print("Failed to get url from mirror server. Using default url.")
env_scripts_repo = 'https://gitee.com/RT-Thread-Mirror/env.git'
else:
env_scripts_repo = 'https://github.com/RT-Thread/env.git'
src = get_source('env', use_mirror=need_using_mirror_download())

env_scripts_root = os.path.join(env_root, 'tools', 'scripts')
if force_upgrade:
execute_command('git fetch --all', cwd=env_scripts_root)
execute_command('git reset --hard origin/master', cwd=env_scripts_root)
execute_command('git reset --hard origin/%s' % src.branch, cwd=env_scripts_root)
print("Begin to upgrade env scripts.")
git_pull_repo(env_scripts_root, env_scripts_repo)
git_pull_repo(env_scripts_root, src.url)
print("==============================> Env scripts upgrade done \n")


Expand All @@ -130,7 +117,8 @@ def Information_statistics():
if os.path.isfile(env_config_file) and find_bool_macro_in_config(env_config_file, 'SYS_PKGS_USING_STATISTICS'):
mac_addr = get_mac_address()
response = requests.get(
'https://www.rt-thread.org/studio/statistics/api/envuse?userid='
get_api_url('statistics')
+ '?userid='
+ str(mac_addr)
+ '&username='
+ str(mac_addr)
Expand Down
4 changes: 3 additions & 1 deletion cmds/cmd_package/cmd_package_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# Change Logs:
# Date Author Notes
# 2020-04-08 SummerGift Optimize program structure
# 2026-09-12 Dongly Resolve mirror query endpoint via info.get_api_url
#

import json
Expand All @@ -34,6 +35,7 @@
import requests
import logging
from vars import Import
from info import get_api_url


def get_git_root_path(repo_path):
Expand Down Expand Up @@ -220,7 +222,7 @@ def get_url_from_mirror_server(package_name, package_version):
payload["packages"][0]['name'] = package_name

try:
r = requests.post("https://api.rt-thread.org/packages/queries", data=json.dumps(payload))
r = requests.post(get_api_url('mirror_query'), data=json.dumps(payload))

if r.status_code == requests.codes.ok:
package_info = json.loads(r.text)
Expand Down
35 changes: 33 additions & 2 deletions env.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,38 @@
"name": "RT-Thread Env Tool",
"version": "v2.0.2",
"description": "A command-line toolkit for RT-Thread development.",
"repository": {
"url": "https://github.com/RT-Thread/env"
"repositories": {
"env": {
"url": "https://github.com/RT-Thread/env.git",
"branch": "master",
"mirror": {
"url": "https://gitee.com/RT-Thread-Mirror/env.git",
"branch": "master"
}
},
"sdk": {
"url": "https://github.com/RT-Thread/sdk.git",
"branch": "main",
"mirror": {
"url": "https://gitee.com/RT-Thread-Mirror/sdk.git",
"branch": "main"
}
},
"packages": {
"url": "https://github.com/RT-Thread/packages.git",
"branch": "master",
"mirror": {
"url": "https://gitee.com/RT-Thread-Mirror/packages.git",
"branch": "master"
}
}
},
"submodule_mirrors": {
"rt-thread": "https://gitee.com/RT-Thread-Mirror/submod_{name}.git",
"esp": "https://gitee.com/esp-submodules/{name}.git"
},
"apis": {
"mirror_query": "https://api.rt-thread.org/packages/queries",
"statistics": "https://www.rt-thread.org/studio/statistics/api/envuse"
}
}
5 changes: 5 additions & 0 deletions env.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ if (Test-Path -Path $ActivateScript -PathType Leaf) {
Write-Error "Failed to activate the RT-Thread Env Python venv: $_"
$ActivateStatus = 1
}

# Show welcome message using rt-env command
if (Get-Command rt-env -ErrorAction SilentlyContinue) {
rt-env --info
}
} else {
Write-Error "Cannot activate the RT-Thread Env Python venv: $ActivateScript was not found."
$ActivateStatus = 1
Expand Down
62 changes: 46 additions & 16 deletions env.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# 2019-1-16 SummerGift Add chinese detection
# 2020-4-13 SummerGift refactoring
# 2025-1-27 bernard Add env.json for env information
# 2026-09-12 Dongly Add show_version banner with --info flag; migrate to info accessors

import os
import sys
Expand All @@ -38,17 +39,31 @@

from cmds import *
from vars import Export
from version import get_rt_env_version
from info import get_name, get_version

def show_version_warning():
def show_version():
rtt_ver = get_rtt_verion()
rt_env_name, rt_env_ver = get_name(), get_version()

print('\033[1;36m===================================================================\033[0m')
print('\033[1;36m Welcome to %s %s\033[0m' % (rt_env_name, rt_env_ver))
print('\033[1;36m===================================================================\033[0m')
print('Environment Information:')
print(' - ENV_ROOT : %s' % get_env_root())
print(' - PKGS_ROOT: %s' % get_package_root())

if rtt_ver != (0, 0, 0):
print(' - RTT_ROOT : %s' % get_rtt_root())
print(' - BSP_ROOT : %s' % get_bsp_root())
print(' - RT-Thread Version: %d.%d.%d' % rtt_ver)
print('\033[1;36m===================================================================\033[0m')

def show_version_warning(is_show_version=True):
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 %s' % (rt_env_name, rt_env_ver))
print('===================================================================')
# print('')
if is_show_version:
show_version()
print('env v2.0 has made the following important changes:')
print('1. Upgrading Python version from v2 to v3')
print('2. Replacing kconfig-frontends with Python kconfiglib')
Expand All @@ -67,12 +82,14 @@ def show_version_warning():


def init_argparse():
parser = argparse.ArgumentParser(description=__doc__)
# 'rt-env' mirrors the [project.scripts] entry in pyproject.toml
parser = argparse.ArgumentParser(prog='rt-env', description=__doc__)
subs = parser.add_subparsers()

rt_env_name, rt_env_ver = get_rt_env_version()
rt_env_name, rt_env_ver = get_name(), get_version()
env_ver_str = '%s %s' % (rt_env_name, rt_env_ver)
parser.add_argument('-v', '--version', action='version', version=env_ver_str)
parser.add_argument('--info', action='store_true', help='Show environment information')

cmd_system.add_parser(subs)
cmd_menuconfig.add_parser(subs)
Expand Down Expand Up @@ -219,18 +236,31 @@ def exec_arg(arg):
args.func(args)


def main():
show_version_warning()
export_environment_variable()
init_logger(get_env_root())
def cmd_env_info(args):
"""Handle environment information display."""
show_version()
show_version_warning(False)
sys.exit(0)


def main():
parser = init_argparse()
args = parser.parse_args()

if not vars(args):
if args.info:
cmd_env_info(args)

# Check if any subcommand was provided
if not hasattr(args, 'func'):
# No subcommand provided, show help
parser.print_help()
else:
args.func(args)
sys.exit(0)

show_version_warning()
export_environment_variable()
init_logger(get_env_root())

args.func(args)


def menuconfig():
Expand Down
5 changes: 5 additions & 0 deletions env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ if [ -f "$ENV_ACTIVATE" ]; then
echo "Failed to activate the RT-Thread Env Python venv." >&2
activate_status=1
fi

# Show welcome message using rt-env command
if command -v rt-env >/dev/null 2>&1; then
rt-env --info
fi
else
echo "Cannot activate the RT-Thread Env Python venv: $ENV_ACTIVATE was not found." >&2
activate_status=1
Expand Down
4 changes: 4 additions & 0 deletions env_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def source_fingerprint(source_root):
return digest.hexdigest()


# NOTE: deliberately NOT using info.load_env_json() — this reads the SOURCE
# tree being installed (the source_root parameter), not the running copy, and
# env_venv must stay self-contained so degraded installs can still bootstrap.
# Do not "fix" this duplication without considering the reasons above.
def read_env_version(source_root):
path = _normalized(source_root) / 'env.json'
try:
Expand Down
Loading