14
14
from collections import Counter
15
15
from subprocess import check_call , CalledProcessError
16
16
17
- root_dir = os .path .abspath (os .path .join (os .path .abspath (__file__ ), '..' , '..' ))
17
+ root_dir = os .path .abspath (os .path .join (os .path .abspath (__file__ ), ".." , ".." ))
18
18
19
- def pip_command (command , additional_dir = '.' , error_ok = False ):
19
+
20
+ def pip_command (command , additional_dir = "." , error_ok = False ):
20
21
try :
21
- print ('Executing: {} from {}' .format (command , additional_dir ))
22
- check_call ([sys .executable , '-m' , 'pip' ] + command .split (), cwd = os .path .join (root_dir , additional_dir ))
22
+ print ("Executing: {} from {}" .format (command , additional_dir ))
23
+ check_call (
24
+ [sys .executable , "-m" , "pip" ] + command .split (),
25
+ cwd = os .path .join (root_dir , additional_dir ),
26
+ )
23
27
print ()
24
28
except CalledProcessError as err :
25
29
print (err , file = sys .stderr )
26
30
if not error_ok :
27
31
sys .exit (1 )
28
32
33
+
29
34
# optional argument in a situation where we want to build a variable subset of packages
30
- parser = argparse .ArgumentParser (description = 'Set up the dev environment for selected packages.' )
31
- parser .add_argument ('--packageList' , '-p' ,
32
- dest = 'packageList' ,
33
- default = '' ,
34
- help = 'Comma separated list of targeted packages. Used to limit the number of packages that dependencies will be installed for.' )
35
+ parser = argparse .ArgumentParser (
36
+ description = "Set up the dev environment for selected packages."
37
+ )
38
+ parser .add_argument (
39
+ "--packageList" ,
40
+ "-p" ,
41
+ dest = "packageList" ,
42
+ default = "" ,
43
+ help = "Comma separated list of targeted packages. Used to limit the number of packages that dependencies will be installed for." ,
44
+ )
35
45
args = parser .parse_args ()
36
46
37
- packages = {('.' , os .path .dirname (p )) for p in glob .glob ('azure*/setup.py' )}
38
- # Handle the SDK folder as well
39
- packages .update ({tuple (os .path .dirname (f ).rsplit (os .sep , 1 )) for f in glob .glob ('sdk/*/azure*/setup.py' )})
47
+ packages = {
48
+ tuple (os .path .dirname (f ).rsplit (os .sep , 1 ))
49
+ for f in glob .glob ("sdk/*/azure*/setup.py" ) + glob .glob ("tools/azure*/setup.py" )
50
+ }
40
51
# [(base_folder, package_name), ...] to {package_name: base_folder, ...}
41
52
packages = {package_name : base_folder for (base_folder , package_name ) in packages }
42
53
43
54
# keep targeted packages separate. python2 needs the nspkgs to work properly.
44
55
if not args .packageList :
45
56
targeted_packages = list (packages .keys ())
46
57
else :
47
- targeted_packages = [os .path .relpath (x .strip ()) for x in args .packageList .split (',' )]
58
+ targeted_packages = [
59
+ os .path .relpath (x .strip ()) for x in args .packageList .split ("," )
60
+ ]
48
61
49
62
# Extract nspkg and sort nspkg by number of "-"
50
- nspkg_packages = [p for p in packages .keys () if ' nspkg' in p ]
51
- nspkg_packages .sort (key = lambda x : len ([c for c in x if c == '-' ]))
63
+ nspkg_packages = [p for p in packages .keys () if " nspkg" in p ]
64
+ nspkg_packages .sort (key = lambda x : len ([c for c in x if c == "-" ]))
52
65
53
66
# Manually push meta-packages at the end, in reverse dependency order
54
- meta_packages = [' azure-mgmt' , ' azure' ]
67
+ meta_packages = [" azure-mgmt" , " azure" ]
55
68
56
- content_packages = sorted ([p for p in packages .keys () if p not in nspkg_packages + meta_packages and p in targeted_packages ])
69
+ content_packages = sorted (
70
+ [
71
+ p
72
+ for p in packages .keys ()
73
+ if p not in nspkg_packages + meta_packages and p in targeted_packages
74
+ ]
75
+ )
57
76
58
77
# Put azure-common in front
59
- if ' azure-common' in content_packages :
60
- content_packages .remove (' azure-common' )
61
- content_packages .insert (0 , ' azure-common' )
78
+ if " azure-common" in content_packages :
79
+ content_packages .remove (" azure-common" )
80
+ content_packages .insert (0 , " azure-common" )
62
81
63
- if ' azure-sdk-tools' in content_packages :
64
- content_packages .remove (' azure-sdk-tools' )
65
- content_packages .insert (1 , ' azure-sdk-tools' )
82
+ if " azure-sdk-tools" in content_packages :
83
+ content_packages .remove (" azure-sdk-tools" )
84
+ content_packages .insert (1 , " azure-sdk-tools" )
66
85
67
- print (' Running dev setup...' )
68
- print (' Root directory \ ' {}\ '\n ' .format (root_dir ))
86
+ print (" Running dev setup..." )
87
+ print (" Root directory '{}'\n " .format (root_dir ))
69
88
70
89
# install private whls if there are any
71
- privates_dir = os .path .join (root_dir , ' privates' )
90
+ privates_dir = os .path .join (root_dir , " privates" )
72
91
if os .path .isdir (privates_dir ) and os .listdir (privates_dir ):
73
- whl_list = ' ' .join ([os .path .join (privates_dir , f ) for f in os .listdir (privates_dir )])
74
- pip_command ('install {}' .format (whl_list ))
92
+ whl_list = " " .join (
93
+ [os .path .join (privates_dir , f ) for f in os .listdir (privates_dir )]
94
+ )
95
+ pip_command ("install {}" .format (whl_list ))
75
96
76
97
# install nspkg only on py2, but in wheel mode (not editable mode)
77
- if sys .version_info < (3 , ):
98
+ if sys .version_info < (3 ,):
78
99
for package_name in nspkg_packages :
79
- pip_command (' install {}/{}/' .format (packages [package_name ], package_name ))
100
+ pip_command (" install {}/{}/" .format (packages [package_name ], package_name ))
80
101
81
102
# install packages
82
103
for package_name in content_packages :
83
104
print ("Installing {}" .format (package_name ))
84
105
# if we are running dev_setup with no arguments. going after dev_requirements will be a pointless exercise
85
106
# and waste of cycles as all the dependencies will be installed regardless.
86
- if os .path .isfile ('{}/{}/dev_requirements.txt' .format (packages [package_name ], package_name )):
87
- pip_command ('install -r dev_requirements.txt' , os .path .join (packages [package_name ], package_name ))
88
- pip_command ('install --ignore-requires-python -e {}' .format (os .path .join (packages [package_name ], package_name )))
107
+ if os .path .isfile (
108
+ "{}/{}/dev_requirements.txt" .format (packages [package_name ], package_name )
109
+ ):
110
+ pip_command (
111
+ "install -r dev_requirements.txt" ,
112
+ os .path .join (packages [package_name ], package_name ),
113
+ )
114
+ pip_command (
115
+ "install --ignore-requires-python -e {}" .format (
116
+ os .path .join (packages [package_name ], package_name )
117
+ )
118
+ )
89
119
90
120
# On Python 3, uninstall azure-nspkg if he got installed
91
- if sys .version_info >= (3 , ):
92
- pip_command ('uninstall -y azure-nspkg' , error_ok = True )
121
+ if sys .version_info >= (3 ,):
122
+ pip_command ("uninstall -y azure-nspkg" , error_ok = True )
123
+
124
+ print ("Finished dev setup." )
93
125
94
- print ('Finished dev setup.' )
0 commit comments