Skip to content

Commit 161db42

Browse files
committed
Blackened
1 parent baf2c26 commit 161db42

File tree

1 file changed

+67
-34
lines changed

1 file changed

+67
-34
lines changed

scripts/dev_setup.py

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,79 +14,112 @@
1414
from collections import Counter
1515
from subprocess import check_call, CalledProcessError
1616

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__), "..", ".."))
1818

19-
def pip_command(command, additional_dir='.', error_ok=False):
19+
20+
def pip_command(command, additional_dir=".", error_ok=False):
2021
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+
)
2327
print()
2428
except CalledProcessError as err:
2529
print(err, file=sys.stderr)
2630
if not error_ok:
2731
sys.exit(1)
2832

33+
2934
# 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+
)
3545
args = parser.parse_args()
3646

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+
}
3851
# [(base_folder, package_name), ...] to {package_name: base_folder, ...}
3952
packages = {package_name: base_folder for (base_folder, package_name) in packages}
4053

4154
# keep targeted packages separate. python2 needs the nspkgs to work properly.
4255
if not args.packageList:
4356
targeted_packages = list(packages.keys())
4457
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+
]
4661

4762
# 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 == "-"]))
5065

5166
# Manually push meta-packages at the end, in reverse dependency order
52-
meta_packages = ['azure-mgmt', 'azure']
67+
meta_packages = ["azure-mgmt", "azure"]
5368

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+
)
5576

5677
# 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")
6081

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")
6485

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))
6788

6889
# 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")
7091
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))
7396

7497
# install nspkg only on py2, but in wheel mode (not editable mode)
75-
if sys.version_info < (3, ):
98+
if sys.version_info < (3,):
7699
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))
78101

79102
# install packages
80103
for package_name in content_packages:
81104
print("Installing {}".format(package_name))
82105
# if we are running dev_setup with no arguments. going after dev_requirements will be a pointless exercise
83106
# 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+
)
87119

88120
# 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.")
91125

92-
print('Finished dev setup.')

0 commit comments

Comments
 (0)