-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
117 lines (98 loc) · 4.13 KB
/
Copy pathsetup.py
File metadata and controls
117 lines (98 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2024, Huawei Technologies Co., Ltd.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import os
import shutil
import subprocess # nosec B404
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from setuptools import find_packages, setup # type: ignore
from msprof_analyze.prof_common.path_manager import PathManager
from msprof_analyze.prof_common.file_manager import FileManager
from msprof_analyze.prof_common.utils import SafeConfigReader
sections = {'URL': ['msprof_analyze_url'], 'EMAIL': ['ms_email']}
requires = FileManager.read_common_file('requirements/build.txt').splitlines()
tests_requires = FileManager.read_common_file('requirements/tests.txt').splitlines()
tests_requires.extend(set(requires))
version = os.getenv("WHL_VERSION", FileManager.read_common_file('version.txt').strip())
def _git_output(*args):
try:
git_path = shutil.which('git')
if git_path is None:
return ''
cmd_result = subprocess.check_output( # nosec B603
[git_path, *args],
cwd=os.path.dirname(os.path.abspath(__file__)),
stderr=subprocess.DEVNULL,
)
return cmd_result.decode('utf-8').strip()
except (OSError, subprocess.CalledProcessError):
return ''
def _generate_buildinfo():
buildinfo_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'msprof_analyze', '__buildinfo__.py')
commit = _git_output('rev-parse', '--short=7', 'HEAD') or 'unknown'
repo = _git_output('remote', 'get-url', 'origin')
if repo.endswith('.git'):
repo = repo[:-4]
build_date = datetime.datetime.now(datetime.timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')
content = (
'# -*- coding: utf-8 -*-\n'
'# This file is auto-generated by setup.py during build. Do not edit manually.\n\n'
'VERSION = {!r}\n'
'COMMIT = {!r}\n'
'BUILD_DATE = {!r}\n'
'REPO = {!r}\n'
).format(version, commit, build_date, repo or 'unknown')
with open(buildinfo_path, 'w', encoding='utf-8') as f:
f.write(content)
_generate_buildinfo()
CONFIG_FILE_PATH = "config/config.ini"
PathManager.check_input_file_path(CONFIG_FILE_PATH)
PathManager.check_file_size(CONFIG_FILE_PATH)
reader = SafeConfigReader(CONFIG_FILE_PATH)
reader.validate(sections)
config = reader.get_config()
try:
url = config.get("URL", "msprof_analyze_url")
except Exception as e:
raise RuntimeError("The configuration file is incomplete and not configured msprof_analyze_url information.") from e
try:
author_email = config.get("EMAIL", "ms_email")
except Exception as e:
raise RuntimeError("The configuration file is incomplete and not configured ms_email information.") from e
setup(
name="msprof-analyze",
version=version,
description="MindStudio Profiler Analyze Tools",
long_description="msprof-analyze provides statistics, analysis, and related tuning suggestions for the "
"performance data collected in training and large model scenarios. The main functional modules"
" include: performance comparison, performance analysis, and cluster analysis.",
url=url,
author="MindStudio",
author_email=author_email,
packages=find_packages(include=["msprof_analyze*"], exclude=["test*", "misc*"]),
include_package_data=True,
python_requires='>=3.7',
install_requires=requires,
extras_require={"test": tests_requires},
license='Apache License 2.0',
entry_points="""
[console_scripts]
msprof-analyze=msprof_analyze.cli.entrance:msprof_analyze_cli
""",
)
# build cmd: pip install --editable .