|
a |
|
b/ViTPose/setup.py |
|
|
1 |
import os |
|
|
2 |
import os.path as osp |
|
|
3 |
import platform |
|
|
4 |
import shutil |
|
|
5 |
import sys |
|
|
6 |
import warnings |
|
|
7 |
from setuptools import find_packages, setup |
|
|
8 |
|
|
|
9 |
|
|
|
10 |
def readme(): |
|
|
11 |
with open('README.md', encoding='utf-8') as f: |
|
|
12 |
content = f.read() |
|
|
13 |
return content |
|
|
14 |
|
|
|
15 |
|
|
|
16 |
version_file = 'mmpose/version.py' |
|
|
17 |
|
|
|
18 |
|
|
|
19 |
def get_version(): |
|
|
20 |
with open(version_file, 'r') as f: |
|
|
21 |
exec(compile(f.read(), version_file, 'exec')) |
|
|
22 |
import sys |
|
|
23 |
|
|
|
24 |
# return short version for sdist |
|
|
25 |
if 'sdist' in sys.argv or 'bdist_wheel' in sys.argv: |
|
|
26 |
return locals()['short_version'] |
|
|
27 |
else: |
|
|
28 |
return locals()['__version__'] |
|
|
29 |
|
|
|
30 |
|
|
|
31 |
def parse_requirements(fname='requirements.txt', with_version=True): |
|
|
32 |
"""Parse the package dependencies listed in a requirements file but strips |
|
|
33 |
specific versioning information. |
|
|
34 |
|
|
|
35 |
Args: |
|
|
36 |
fname (str): path to requirements file |
|
|
37 |
with_version (bool, default=False): if True include version specs |
|
|
38 |
|
|
|
39 |
Returns: |
|
|
40 |
List[str]: list of requirements items |
|
|
41 |
|
|
|
42 |
CommandLine: |
|
|
43 |
python -c "import setup; print(setup.parse_requirements())" |
|
|
44 |
""" |
|
|
45 |
import re |
|
|
46 |
import sys |
|
|
47 |
from os.path import exists |
|
|
48 |
require_fpath = fname |
|
|
49 |
|
|
|
50 |
def parse_line(line): |
|
|
51 |
"""Parse information from a line in a requirements text file.""" |
|
|
52 |
if line.startswith('-r '): |
|
|
53 |
# Allow specifying requirements in other files |
|
|
54 |
target = line.split(' ')[1] |
|
|
55 |
for info in parse_require_file(target): |
|
|
56 |
yield info |
|
|
57 |
else: |
|
|
58 |
info = {'line': line} |
|
|
59 |
if line.startswith('-e '): |
|
|
60 |
info['package'] = line.split('#egg=')[1] |
|
|
61 |
elif '@git+' in line: |
|
|
62 |
info['package'] = line |
|
|
63 |
else: |
|
|
64 |
# Remove versioning from the package |
|
|
65 |
pat = '(' + '|'.join(['>=', '==', '>']) + ')' |
|
|
66 |
parts = re.split(pat, line, maxsplit=1) |
|
|
67 |
parts = [p.strip() for p in parts] |
|
|
68 |
|
|
|
69 |
info['package'] = parts[0] |
|
|
70 |
if len(parts) > 1: |
|
|
71 |
op, rest = parts[1:] |
|
|
72 |
if ';' in rest: |
|
|
73 |
# Handle platform specific dependencies |
|
|
74 |
# http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-platform-specific-dependencies |
|
|
75 |
version, platform_deps = map(str.strip, |
|
|
76 |
rest.split(';')) |
|
|
77 |
info['platform_deps'] = platform_deps |
|
|
78 |
else: |
|
|
79 |
version = rest # NOQA |
|
|
80 |
info['version'] = (op, version) |
|
|
81 |
yield info |
|
|
82 |
|
|
|
83 |
def parse_require_file(fpath): |
|
|
84 |
with open(fpath, 'r') as f: |
|
|
85 |
for line in f.readlines(): |
|
|
86 |
line = line.strip() |
|
|
87 |
if line and not line.startswith('#'): |
|
|
88 |
for info in parse_line(line): |
|
|
89 |
yield info |
|
|
90 |
|
|
|
91 |
def gen_packages_items(): |
|
|
92 |
if exists(require_fpath): |
|
|
93 |
for info in parse_require_file(require_fpath): |
|
|
94 |
parts = [info['package']] |
|
|
95 |
if with_version and 'version' in info: |
|
|
96 |
parts.extend(info['version']) |
|
|
97 |
if not sys.version.startswith('3.4'): |
|
|
98 |
# apparently package_deps are broken in 3.4 |
|
|
99 |
platform_deps = info.get('platform_deps') |
|
|
100 |
if platform_deps is not None: |
|
|
101 |
parts.append(';' + platform_deps) |
|
|
102 |
item = ''.join(parts) |
|
|
103 |
yield item |
|
|
104 |
|
|
|
105 |
packages = list(gen_packages_items()) |
|
|
106 |
return packages |
|
|
107 |
|
|
|
108 |
|
|
|
109 |
def add_mim_extension(): |
|
|
110 |
"""Add extra files that are required to support MIM into the package. |
|
|
111 |
|
|
|
112 |
These files will be added by creating a symlink to the originals if the |
|
|
113 |
package is installed in `editable` mode (e.g. pip install -e .), or by |
|
|
114 |
copying from the originals otherwise. |
|
|
115 |
""" |
|
|
116 |
|
|
|
117 |
# parse installment mode |
|
|
118 |
if 'develop' in sys.argv: |
|
|
119 |
# installed by `pip install -e .` |
|
|
120 |
if platform.system() == 'Windows': |
|
|
121 |
mode = 'copy' |
|
|
122 |
else: |
|
|
123 |
mode = 'symlink' |
|
|
124 |
elif 'sdist' in sys.argv or 'bdist_wheel' in sys.argv: |
|
|
125 |
# installed by `pip install .` |
|
|
126 |
# or create source distribution by `python setup.py sdist` |
|
|
127 |
mode = 'copy' |
|
|
128 |
else: |
|
|
129 |
return |
|
|
130 |
|
|
|
131 |
filenames = ['tools', 'configs', 'demo', 'model-index.yml'] |
|
|
132 |
repo_path = osp.dirname(__file__) |
|
|
133 |
mim_path = osp.join(repo_path, 'mmpose', '.mim') |
|
|
134 |
os.makedirs(mim_path, exist_ok=True) |
|
|
135 |
|
|
|
136 |
for filename in filenames: |
|
|
137 |
if osp.exists(filename): |
|
|
138 |
src_path = osp.join(repo_path, filename) |
|
|
139 |
tar_path = osp.join(mim_path, filename) |
|
|
140 |
|
|
|
141 |
if osp.isfile(tar_path) or osp.islink(tar_path): |
|
|
142 |
os.remove(tar_path) |
|
|
143 |
elif osp.isdir(tar_path): |
|
|
144 |
shutil.rmtree(tar_path) |
|
|
145 |
|
|
|
146 |
if mode == 'symlink': |
|
|
147 |
src_relpath = osp.relpath(src_path, osp.dirname(tar_path)) |
|
|
148 |
os.symlink(src_relpath, tar_path) |
|
|
149 |
elif mode == 'copy': |
|
|
150 |
if osp.isfile(src_path): |
|
|
151 |
shutil.copyfile(src_path, tar_path) |
|
|
152 |
elif osp.isdir(src_path): |
|
|
153 |
shutil.copytree(src_path, tar_path) |
|
|
154 |
else: |
|
|
155 |
warnings.warn(f'Cannot copy file {src_path}.') |
|
|
156 |
else: |
|
|
157 |
raise ValueError(f'Invalid mode {mode}') |
|
|
158 |
|
|
|
159 |
|
|
|
160 |
if __name__ == '__main__': |
|
|
161 |
add_mim_extension() |
|
|
162 |
setup( |
|
|
163 |
name='mmpose', |
|
|
164 |
version=get_version(), |
|
|
165 |
description='OpenMMLab Pose Estimation Toolbox and Benchmark.', |
|
|
166 |
author='MMPose Contributors', |
|
|
167 |
author_email='openmmlab@gmail.com', |
|
|
168 |
keywords='computer vision, pose estimation', |
|
|
169 |
long_description=readme(), |
|
|
170 |
long_description_content_type='text/markdown', |
|
|
171 |
packages=find_packages(exclude=('configs', 'tools', 'demo')), |
|
|
172 |
include_package_data=True, |
|
|
173 |
package_data={'mmpose.ops': ['*/*.so']}, |
|
|
174 |
classifiers=[ |
|
|
175 |
'Development Status :: 4 - Beta', |
|
|
176 |
'License :: OSI Approved :: Apache Software License', |
|
|
177 |
'Operating System :: OS Independent', |
|
|
178 |
'Programming Language :: Python :: 3', |
|
|
179 |
'Programming Language :: Python :: 3.5', |
|
|
180 |
'Programming Language :: Python :: 3.6', |
|
|
181 |
'Programming Language :: Python :: 3.7', |
|
|
182 |
'Programming Language :: Python :: 3.8', |
|
|
183 |
'Programming Language :: Python :: 3.9', |
|
|
184 |
], |
|
|
185 |
url='https://github.com/open-mmlab/mmpose', |
|
|
186 |
license='Apache License 2.0', |
|
|
187 |
install_requires=parse_requirements('requirements/runtime.txt'), |
|
|
188 |
extras_require={ |
|
|
189 |
'tests': parse_requirements('requirements/tests.txt'), |
|
|
190 |
'build': parse_requirements('requirements/build.txt'), |
|
|
191 |
'runtime': parse_requirements('requirements/runtime.txt') |
|
|
192 |
}, |
|
|
193 |
zip_safe=False) |