Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
5feb5693
Commit
5feb5693
authored
Jun 18, 2025
by
limm
Browse files
modify the whl package nameing convention
parent
753afb07
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
6 deletions
+122
-6
get_version.py
get_version.py
+114
-0
mmcv/version.py
mmcv/version.py
+2
-1
setup.py
setup.py
+6
-5
No files found.
get_version.py
0 → 100644
View file @
5feb5693
import
os
import
re
import
subprocess
from
pathlib
import
Path
import
torch
ROOT_DIR
=
Path
(
__file__
).
parent
.
resolve
()
def
_run_cmd
(
cmd
,
shell
=
False
):
try
:
return
subprocess
.
check_output
(
cmd
,
cwd
=
ROOT_DIR
,
stderr
=
subprocess
.
DEVNULL
,
shell
=
shell
).
decode
(
"ascii"
).
strip
()
except
Exception
:
return
None
def
_get_version
():
if
os
.
path
.
exists
(
ROOT_DIR
/
"mmcv/version.py"
):
with
open
(
ROOT_DIR
/
"mmcv/version.py"
,
"r"
)
as
f
:
content
=
f
.
read
().
strip
()
version_match
=
re
.
search
(
"__version__\s*=\s*['
\"
]([^'
\"
]+)['
\"
]"
,
content
)
if
version_match
:
print
(
f
"version_match.group(1) =
{
version_match
.
group
(
1
)
}
"
)
print
(
f
"version_match.group(0) =
{
version_match
.
group
(
0
)
}
"
)
version
=
version_match
.
group
(
1
)
else
:
version
=
'2.2.0'
if
os
.
getenv
(
"BUILD_VERSION"
):
version
=
os
.
getenv
(
"BUILD_VERSION"
)
return
version
def
_update_hcu_version
(
version
,
das_version
,
sha
,
abi
,
dtk
,
torch_version
,
branch
):
"""
修改 __hcu_version__ 的值,不改变其他内容。
:param file_path: 要修改的 .py 文件路径
:param new_value: 新的版本号字符串,比如 '2.2.0+das.opt1.dtk25041'
"""
sha
=
"Unknown"
if
sha
is
None
else
sha
hcu_version
=
f
"
{
das_version
}
"
file_path
=
ROOT_DIR
/
"mmcv"
/
"version.py"
# 读取整个文件内容
with
open
(
file_path
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
content
=
f
.
read
()
# 正则匹配 __hcu_version__ 行,并替换引号内的值
pattern
=
r
"(__hcu_version__\s*=\s*)['\"]([^'\"]*)['\"]"
replacement
=
rf
"\g<1>'
{
hcu_version
}
'"
# 执行替换
updated_content
=
re
.
sub
(
pattern
,
replacement
,
content
)
# 写回文件
with
open
(
file_path
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
f
.
write
(
updated_content
)
return
hcu_version
def
get_origin_version
():
version_file
=
ROOT_DIR
/
'mmcv/version.py'
with
open
(
version_file
,
encoding
=
'utf-8'
)
as
f
:
exec
(
compile
(
f
.
read
(),
version_file
,
'exec'
))
return
locals
()[
'__version__'
]
def
_make_version_file
(
version
,
das_version
,
sha
,
abi
,
dtk
,
torch_version
,
branch
):
sha
=
"Unknown"
if
sha
is
None
else
sha
# torch_version = '.'.join(torch_version.split('.')[:2])
# hcu_version = f"{das_version}.git{sha}.abi{abi}.dtk{dtk}.torch{torch_version}"
hcu_version
=
f
"
{
das_version
}
"
version_path
=
ROOT_DIR
/
"mmcv"
/
"version.py"
with
open
(
version_path
,
"a"
,
encoding
=
"utf-8"
)
as
f
:
#f.write(f"version = '{version}'\n")
#f.write(f"git_hash = '{sha}'\n")
#f.write(f"git_branch = '{branch}'\n")
#f.write(f"abi = 'abi{abi}'\n")
#f.write(f"dtk = '{dtk}'\n")
#f.write(f"torch_version = '{torch_version}'\n")
f
.
write
(
f
"__hcu_version__ = '
{
hcu_version
}
'
\n
"
)
return
hcu_version
def
_get_pytorch_version
():
if
"PYTORCH_VERSION"
in
os
.
environ
:
return
f
"
{
os
.
environ
[
'PYTORCH_VERSION'
]
}
"
return
torch
.
__version__
def
get_version
():
ROCM_HOME
=
os
.
getenv
(
"ROCM_PATH"
)
print
(
"ROCM_HOME = {ROCM_HOME}"
)
if
not
ROCM_HOME
:
return
get_origin_version
()
sha
=
_run_cmd
([
"git"
,
"rev-parse"
,
"HEAD"
])
sha
=
sha
[:
7
]
branch
=
_run_cmd
([
"git"
,
"rev-parse"
,
"--abbrev-ref"
,
"HEAD"
])
tag
=
_run_cmd
([
"git"
,
"describe"
,
"--tags"
,
"--exact-match"
,
"@"
])
das_tag
=
_run_cmd
([
"git"
,
"describe"
,
"--abbrev=0"
])
print
(
"-- Git branch:"
,
branch
)
print
(
"-- Git SHA:"
,
sha
)
print
(
"-- Git tag:"
,
tag
)
torch_version
=
_get_pytorch_version
()
print
(
"-- PyTorch:"
,
torch_version
)
version
=
_get_version
()
print
(
"-- Building version"
,
version
)
# das_version = tag
das_version
=
version
+
"+das.opt1"
print
(
"-- Building das_version"
,
das_version
)
abi
=
_run_cmd
([
"echo '#include <string>' | gcc -x c++ -E -dM - | fgrep _GLIBCXX_USE_CXX11_ABI | awk '{print $3}'"
],
shell
=
True
)
print
(
"-- _GLIBCXX_USE_CXX11_ABI:"
,
abi
)
dtk
=
_run_cmd
([
"cat"
,
os
.
path
.
join
(
ROCM_HOME
,
'.info/rocm_version'
)])
dtk
=
''
.
join
(
dtk
.
split
(
'.'
))
print
(
"-- DTK:"
,
dtk
)
das_version
+=
".dtk"
+
dtk
#return _make_version_file(version, das_version, sha, abi, dtk, torch_version, branch)
return
_update_hcu_version
(
version
,
das_version
,
sha
,
abi
,
dtk
,
torch_version
,
branch
)
mmcv/version.py
View file @
5feb5693
# Copyright (c) OpenMMLab. All rights reserved.
# Copyright (c) OpenMMLab. All rights reserved.
__version__
=
'2.2.0'
__version__
=
'2.2.0'
__hcu_version__
=
'2.2.0'
def
parse_version_info
(
version_str
:
str
,
length
:
int
=
4
)
->
tuple
:
def
parse_version_info
(
version_str
:
str
,
length
:
int
=
4
)
->
tuple
:
...
@@ -32,4 +33,4 @@ def parse_version_info(version_str: str, length: int = 4) -> tuple:
...
@@ -32,4 +33,4 @@ def parse_version_info(version_str: str, length: int = 4) -> tuple:
version_info
=
tuple
(
int
(
x
)
for
x
in
__version__
.
split
(
'.'
)[:
3
])
version_info
=
tuple
(
int
(
x
)
for
x
in
__version__
.
split
(
'.'
)[:
3
])
__all__
=
[
'__version__'
,
'version_info'
,
'parse_version_info'
]
__all__
=
[
'__version__'
,
'__hcu_version__'
,
'version_info'
,
'parse_version_info'
]
setup.py
View file @
5feb5693
...
@@ -4,6 +4,7 @@ import platform
...
@@ -4,6 +4,7 @@ import platform
import
re
import
re
from
pkg_resources
import
DistributionNotFound
,
get_distribution
,
parse_version
from
pkg_resources
import
DistributionNotFound
,
get_distribution
,
parse_version
from
setuptools
import
find_packages
,
setup
from
setuptools
import
find_packages
,
setup
from
get_version
import
get_version
EXT_TYPE
=
''
EXT_TYPE
=
''
try
:
try
:
...
@@ -36,11 +37,11 @@ def choose_requirement(primary, secondary):
...
@@ -36,11 +37,11 @@ def choose_requirement(primary, secondary):
return
str
(
primary
)
return
str
(
primary
)
def
get_version
():
#
def get_version():
version_file
=
'mmcv/version.py'
#
version_file = 'mmcv/version.py'
with
open
(
version_file
,
encoding
=
'utf-8'
)
as
f
:
#
with open(version_file, encoding='utf-8') as f:
exec
(
compile
(
f
.
read
(),
version_file
,
'exec'
))
#
exec(compile(f.read(), version_file, 'exec'))
return
locals
()[
'__version__'
]
#
return locals()['__version__']
def
parse_requirements
(
fname
=
'requirements/runtime.txt'
,
with_version
=
True
):
def
parse_requirements
(
fname
=
'requirements/runtime.txt'
,
with_version
=
True
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment