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 = {tuple (os .path .dirname (f ).rsplit (os .sep , 1 )) for f in glob .glob ('sdk/*/azure*/setup.py' ) + glob .glob ('tools/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
+ }
38
51
# [(base_folder, package_name), ...] to {package_name: base_folder, ...}
39
52
packages = {package_name : base_folder for (base_folder , package_name ) in packages }
40
53
41
54
# keep targeted packages separate. python2 needs the nspkgs to work properly.
42
55
if not args .packageList :
43
56
targeted_packages = list (packages .keys ())
44
57
else :
45
- 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
+ ]
46
61
47
62
# Extract nspkg and sort nspkg by number of "-"
48
- nspkg_packages = [p for p in packages .keys () if ' nspkg' in p ]
49
- 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 == "-" ]))
50
65
51
66
# Manually push meta-packages at the end, in reverse dependency order
52
- meta_packages = [' azure-mgmt' , ' azure' ]
67
+ meta_packages = [" azure-mgmt" , " azure" ]
53
68
54
- 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
+ )
55
76
56
77
# Put azure-common in front
57
- if ' azure-common' in content_packages :
58
- content_packages .remove (' azure-common' )
59
- 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" )
60
81
61
- if ' azure-sdk-tools' in content_packages :
62
- content_packages .remove (' azure-sdk-tools' )
63
- 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" )
64
85
65
- print (' Running dev setup...' )
66
- print (' Root directory \ ' {}\ '\n ' .format (root_dir ))
86
+ print (" Running dev setup..." )
87
+ print (" Root directory '{}'\n " .format (root_dir ))
67
88
68
89
# install private whls if there are any
69
- privates_dir = os .path .join (root_dir , ' privates' )
90
+ privates_dir = os .path .join (root_dir , " privates" )
70
91
if os .path .isdir (privates_dir ) and os .listdir (privates_dir ):
71
- whl_list = ' ' .join ([os .path .join (privates_dir , f ) for f in os .listdir (privates_dir )])
72
- 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 ))
73
96
74
97
# install nspkg only on py2, but in wheel mode (not editable mode)
75
- if sys .version_info < (3 , ):
98
+ if sys .version_info < (3 ,):
76
99
for package_name in nspkg_packages :
77
- pip_command (' install {}/{}/' .format (packages [package_name ], package_name ))
100
+ pip_command (" install {}/{}/" .format (packages [package_name ], package_name ))
78
101
79
102
# install packages
80
103
for package_name in content_packages :
81
104
print ("Installing {}" .format (package_name ))
82
105
# if we are running dev_setup with no arguments. going after dev_requirements will be a pointless exercise
83
106
# and waste of cycles as all the dependencies will be installed regardless.
84
- if os .path .isfile ('{}/{}/dev_requirements.txt' .format (packages [package_name ], package_name )):
85
- pip_command ('install -r dev_requirements.txt' , os .path .join (packages [package_name ], package_name ))
86
- 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
+ )
87
119
88
120
# On Python 3, uninstall azure-nspkg if he got installed
89
- if sys .version_info >= (3 , ):
90
- 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." )
91
125
92
- print ('Finished dev setup.' )
0 commit comments