1
1
import os
2
2
import os .path as osp
3
+ import platform
3
4
import shutil
4
5
import sys
5
6
import warnings
@@ -13,67 +14,6 @@ def readme():
13
14
14
15
15
16
version_file = 'mmpose/version.py'
16
- is_windows = sys .platform == 'win32'
17
-
18
-
19
- def add_mim_extention ():
20
- """Add extra files that are required to support MIM into the package.
21
-
22
- These files will be added by creating a symlink to the originals if the
23
- package is installed in `editable` mode (e.g. pip install -e .), or by
24
- copying from the originals otherwise.
25
- """
26
-
27
- # parse installment mode
28
- if 'develop' in sys .argv :
29
- # installed by `pip install -e .`
30
- mode = 'symlink'
31
- elif 'sdist' in sys .argv or 'bdist_wheel' in sys .argv :
32
- # installed by `pip install .`
33
- # or create source distribution by `python setup.py sdist`
34
- mode = 'copy'
35
- else :
36
- return
37
-
38
- filenames = ['tools' , 'configs' , 'model-index.yml' ]
39
- repo_path = osp .dirname (__file__ )
40
- mim_path = osp .join (repo_path , 'mmpose' , '.mim' )
41
- os .makedirs (mim_path , exist_ok = True )
42
-
43
- for filename in filenames :
44
- if osp .exists (filename ):
45
- src_path = osp .join (repo_path , filename )
46
- tar_path = osp .join (mim_path , filename )
47
-
48
- if osp .isfile (tar_path ) or osp .islink (tar_path ):
49
- os .remove (tar_path )
50
- elif osp .isdir (tar_path ):
51
- shutil .rmtree (tar_path )
52
-
53
- if mode == 'symlink' :
54
- src_relpath = osp .relpath (src_path , osp .dirname (tar_path ))
55
- try :
56
- os .symlink (src_relpath , tar_path )
57
- except OSError :
58
- # Creating a symbolic link on windows may raise an
59
- # `OSError: [WinError 1314]` due to privilege. If
60
- # the error happens, the src file will be copied
61
- mode = 'copy'
62
- warnings .warn (
63
- f'Failed to create a symbolic link for { src_relpath } , '
64
- f'and it will be copied to { tar_path } ' )
65
- else :
66
- continue
67
-
68
- if mode == 'copy' :
69
- if osp .isfile (src_path ):
70
- shutil .copyfile (src_path , tar_path )
71
- elif osp .isdir (src_path ):
72
- shutil .copytree (src_path , tar_path )
73
- else :
74
- warnings .warn (f'Cannot copy file { src_path } .' )
75
- else :
76
- raise ValueError (f'Invalid mode { mode } ' )
77
17
78
18
79
19
def get_version ():
@@ -89,14 +29,16 @@ def get_version():
89
29
90
30
91
31
def parse_requirements (fname = 'requirements.txt' , with_version = True ):
92
- """Parse the package dependencies listed in a requirements file but strip
93
- specific version information.
32
+ """Parse the package dependencies listed in a requirements file but strips
33
+ specific versioning information.
94
34
95
35
Args:
96
- fname (str): Path to requirements file.
97
- with_version (bool, default=False): If True, include version specs.
36
+ fname (str): path to requirements file
37
+ with_version (bool, default=False): if True include version specs
38
+
98
39
Returns:
99
- info (list[str]): List of requirements items.
40
+ List[str]: list of requirements items
41
+
100
42
CommandLine:
101
43
python -c "import setup; print(setup.parse_requirements())"
102
44
"""
@@ -116,6 +58,8 @@ def parse_line(line):
116
58
info = {'line' : line }
117
59
if line .startswith ('-e ' ):
118
60
info ['package' ] = line .split ('#egg=' )[1 ]
61
+ elif '@git+' in line :
62
+ info ['package' ] = line
119
63
else :
120
64
# Remove versioning from the package
121
65
pat = '(' + '|' .join (['>=' , '==' , '>' ]) + ')'
@@ -162,12 +106,59 @@ def gen_packages_items():
162
106
return packages
163
107
164
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
+
165
160
if __name__ == '__main__' :
166
- add_mim_extention ()
167
- library_dirs = [
168
- lp for lp in os .environ .get ('LD_LIBRARY_PATH' , '' ).split (':' )
169
- if len (lp ) > 1
170
- ]
161
+ add_mim_extension ()
171
162
setup (
172
163
name = 'mmpose' ,
173
164
version = get_version (),
@@ -197,7 +188,7 @@ def gen_packages_items():
197
188
extras_require = {
198
189
'all' : parse_requirements ('requirements.txt' ),
199
190
'tests' : parse_requirements ('requirements/tests.txt' ),
200
- 'build ' : parse_requirements ('requirements/build .txt' ),
201
- 'optional ' : parse_requirements ('requirements/optional .txt' )
191
+ 'optional ' : parse_requirements ('requirements/optional .txt' ),
192
+ 'mim ' : parse_requirements ('requirements/mminstall .txt' ),
202
193
},
203
194
zip_safe = False )
0 commit comments