2017-08-09 22:09:35 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------------------------------
|
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
# Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
|
# --------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import glob
|
|
|
|
import os
|
2018-12-20 22:46:08 +03:00
|
|
|
import argparse
|
|
|
|
from collections import Counter
|
2017-08-09 22:09:35 +03:00
|
|
|
from subprocess import check_call, CalledProcessError
|
|
|
|
|
2019-06-08 01:46:24 +03:00
|
|
|
root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", ".."))
|
2017-08-09 22:09:35 +03:00
|
|
|
|
2019-06-08 01:46:24 +03:00
|
|
|
|
|
|
|
def pip_command(command, additional_dir=".", error_ok=False):
|
2017-08-09 22:09:35 +03:00
|
|
|
try:
|
2019-06-08 01:46:24 +03:00
|
|
|
print("Executing: {} from {}".format(command, additional_dir))
|
|
|
|
check_call(
|
|
|
|
[sys.executable, "-m", "pip"] + command.split(),
|
|
|
|
cwd=os.path.join(root_dir, additional_dir),
|
|
|
|
)
|
2017-08-09 22:09:35 +03:00
|
|
|
print()
|
|
|
|
except CalledProcessError as err:
|
|
|
|
print(err, file=sys.stderr)
|
2018-09-25 20:05:10 +03:00
|
|
|
if not error_ok:
|
|
|
|
sys.exit(1)
|
2017-08-09 22:09:35 +03:00
|
|
|
|
2019-09-12 00:05:09 +03:00
|
|
|
def select_install_type(pkg, run_develop, exceptions):
|
|
|
|
# the default for disable_develop will be false, which means `run_develop` will be true
|
|
|
|
argument = ""
|
|
|
|
if run_develop:
|
|
|
|
argument = "-e"
|
|
|
|
|
|
|
|
if pkg in exceptions:
|
|
|
|
# opposite of whatever our decision was
|
|
|
|
if argument == "":
|
|
|
|
argument = "-e"
|
|
|
|
elif argument == "-e":
|
|
|
|
argument = ""
|
|
|
|
|
|
|
|
return argument
|
2019-06-08 01:46:24 +03:00
|
|
|
|
2019-01-23 02:38:14 +03:00
|
|
|
# optional argument in a situation where we want to build a variable subset of packages
|
2019-06-08 01:46:24 +03:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="Set up the dev environment for selected packages."
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--packageList",
|
|
|
|
"-p",
|
|
|
|
dest="packageList",
|
|
|
|
default="",
|
|
|
|
help="Comma separated list of targeted packages. Used to limit the number of packages that dependencies will be installed for.",
|
|
|
|
)
|
2019-09-11 06:02:48 +03:00
|
|
|
parser.add_argument(
|
|
|
|
"--disabledevelop",
|
2019-09-12 00:05:09 +03:00
|
|
|
dest="install_in_develop_mode",
|
|
|
|
default=True,
|
|
|
|
action="store_false",
|
2019-09-11 06:02:48 +03:00
|
|
|
help="Add this argument if you would prefer to install the package with a simple `pip install` versus `pip install -e`",
|
|
|
|
)
|
2019-11-01 22:03:12 +03:00
|
|
|
# this is a hack to support generating docs for the single package that doesn't support develop mode. It will be removed when we
|
2019-09-12 00:05:09 +03:00
|
|
|
# migrate to generating docs on a per-package cadence.
|
|
|
|
parser.add_argument(
|
|
|
|
"--exceptionlist",
|
|
|
|
"-e",
|
|
|
|
dest="exception_list",
|
|
|
|
default="",
|
|
|
|
help="Comma separated list of packages that we want to take the 'opposite' installation method for.",
|
|
|
|
)
|
2019-09-11 06:02:48 +03:00
|
|
|
|
2018-12-20 22:46:08 +03:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2019-06-08 01:46:24 +03:00
|
|
|
packages = {
|
|
|
|
tuple(os.path.dirname(f).rsplit(os.sep, 1))
|
2021-01-19 00:06:16 +03:00
|
|
|
for f in glob.glob(os.path.join(root_dir, "sdk/*/azure-*/setup.py")) + glob.glob(os.path.join(root_dir, "tools/azure-*/setup.py"))
|
2019-06-08 01:46:24 +03:00
|
|
|
}
|
2019-05-14 23:34:04 +03:00
|
|
|
# [(base_folder, package_name), ...] to {package_name: base_folder, ...}
|
|
|
|
packages = {package_name: base_folder for (base_folder, package_name) in packages}
|
2017-08-09 22:09:35 +03:00
|
|
|
|
2019-09-12 00:05:09 +03:00
|
|
|
exceptions = [p.strip() for p in args.exception_list.split(',')]
|
|
|
|
|
2018-12-20 22:46:08 +03:00
|
|
|
# keep targeted packages separate. python2 needs the nspkgs to work properly.
|
2019-01-23 02:38:14 +03:00
|
|
|
if not args.packageList:
|
2019-05-14 23:34:04 +03:00
|
|
|
targeted_packages = list(packages.keys())
|
2019-01-23 02:38:14 +03:00
|
|
|
else:
|
2019-06-08 01:46:24 +03:00
|
|
|
targeted_packages = [
|
|
|
|
os.path.relpath(x.strip()) for x in args.packageList.split(",")
|
|
|
|
]
|
2018-12-20 22:46:08 +03:00
|
|
|
|
2017-08-09 22:09:35 +03:00
|
|
|
# Extract nspkg and sort nspkg by number of "-"
|
2019-06-08 01:46:24 +03:00
|
|
|
nspkg_packages = [p for p in packages.keys() if "nspkg" in p]
|
|
|
|
nspkg_packages.sort(key=lambda x: len([c for c in x if c == "-"]))
|
2017-08-09 22:09:35 +03:00
|
|
|
|
2020-04-08 03:00:45 +03:00
|
|
|
# Meta-packages to ignore
|
2019-11-01 22:03:12 +03:00
|
|
|
meta_packages = ["azure-keyvault", "azure-mgmt", "azure"]
|
2017-08-09 22:09:35 +03:00
|
|
|
|
2019-06-08 01:46:24 +03:00
|
|
|
content_packages = sorted(
|
|
|
|
[
|
|
|
|
p
|
|
|
|
for p in packages.keys()
|
|
|
|
if p not in nspkg_packages + meta_packages and p in targeted_packages
|
|
|
|
]
|
|
|
|
)
|
2018-12-20 22:46:08 +03:00
|
|
|
|
2019-06-10 20:15:46 +03:00
|
|
|
# Install tests dep first
|
2019-06-08 01:46:24 +03:00
|
|
|
if "azure-sdk-tools" in content_packages:
|
|
|
|
content_packages.remove("azure-sdk-tools")
|
|
|
|
content_packages.insert(1, "azure-sdk-tools")
|
2017-08-09 22:09:35 +03:00
|
|
|
|
2019-06-10 20:15:46 +03:00
|
|
|
# Put azure-common in front of content package
|
|
|
|
if "azure-common" in content_packages:
|
|
|
|
content_packages.remove("azure-common")
|
|
|
|
content_packages.insert(2, "azure-common")
|
|
|
|
|
2019-07-02 19:11:48 +03:00
|
|
|
if 'azure-core' in content_packages:
|
|
|
|
content_packages.remove('azure-core')
|
|
|
|
content_packages.insert(3, 'azure-core')
|
|
|
|
|
|
|
|
|
2019-06-08 01:46:24 +03:00
|
|
|
print("Running dev setup...")
|
|
|
|
print("Root directory '{}'\n".format(root_dir))
|
2017-08-09 22:09:35 +03:00
|
|
|
|
2018-09-01 01:29:10 +03:00
|
|
|
# install private whls if there are any
|
2019-06-08 01:46:24 +03:00
|
|
|
privates_dir = os.path.join(root_dir, "privates")
|
2018-09-01 01:29:10 +03:00
|
|
|
if os.path.isdir(privates_dir) and os.listdir(privates_dir):
|
2019-06-08 01:46:24 +03:00
|
|
|
whl_list = " ".join(
|
|
|
|
[os.path.join(privates_dir, f) for f in os.listdir(privates_dir)]
|
|
|
|
)
|
|
|
|
pip_command("install {}".format(whl_list))
|
2018-09-01 01:29:10 +03:00
|
|
|
|
2018-09-25 20:05:10 +03:00
|
|
|
# install nspkg only on py2, but in wheel mode (not editable mode)
|
2019-06-08 01:46:24 +03:00
|
|
|
if sys.version_info < (3,):
|
2018-09-25 20:05:10 +03:00
|
|
|
for package_name in nspkg_packages:
|
2019-06-08 01:46:24 +03:00
|
|
|
pip_command("install {}/{}/".format(packages[package_name], package_name))
|
2018-09-25 20:05:10 +03:00
|
|
|
|
2019-09-12 00:05:09 +03:00
|
|
|
|
|
|
|
|
2017-08-09 22:09:35 +03:00
|
|
|
# install packages
|
2019-06-10 20:15:46 +03:00
|
|
|
print("Packages to install: {}".format(content_packages))
|
2018-09-25 20:05:10 +03:00
|
|
|
for package_name in content_packages:
|
2019-06-10 20:15:46 +03:00
|
|
|
print("\nInstalling {}".format(package_name))
|
2018-12-20 22:46:08 +03:00
|
|
|
# if we are running dev_setup with no arguments. going after dev_requirements will be a pointless exercise
|
2019-03-20 01:05:09 +03:00
|
|
|
# and waste of cycles as all the dependencies will be installed regardless.
|
2019-06-08 01:46:24 +03:00
|
|
|
if os.path.isfile(
|
|
|
|
"{}/{}/dev_requirements.txt".format(packages[package_name], package_name)
|
|
|
|
):
|
|
|
|
pip_command(
|
|
|
|
"install -r dev_requirements.txt",
|
|
|
|
os.path.join(packages[package_name], package_name),
|
|
|
|
)
|
2019-09-11 06:02:48 +03:00
|
|
|
|
2019-06-08 01:46:24 +03:00
|
|
|
pip_command(
|
2019-09-11 06:02:48 +03:00
|
|
|
"install --ignore-requires-python {} {}".format(
|
2019-09-12 00:05:09 +03:00
|
|
|
select_install_type(package_name, args.install_in_develop_mode, exceptions),
|
2019-06-08 01:46:24 +03:00
|
|
|
os.path.join(packages[package_name], package_name)
|
|
|
|
)
|
|
|
|
)
|
2018-09-25 20:05:10 +03:00
|
|
|
|
|
|
|
# On Python 3, uninstall azure-nspkg if he got installed
|
2019-06-08 01:46:24 +03:00
|
|
|
if sys.version_info >= (3,):
|
|
|
|
pip_command("uninstall -y azure-nspkg", error_ok=True)
|
|
|
|
|
|
|
|
print("Finished dev setup.")
|
2018-09-25 20:05:10 +03:00
|
|
|
|