text
stringlengths
0
14.1k
blacklist = [""-i"", ""#"", ""Python=="", ""python-lambda==""]
return all(package.startswith(entry) is False for entry in blacklist)
filtered_packages = filter(_filter_blacklist, packages)
for package in filtered_packages:
if package.startswith(""-e ""):
package = package.replace(""-e "", """")
print(""Installing {package}"".format(package=package))
subprocess.check_call(
[
sys.executable,
""-m"",
""pip"",
""install"",
package,
""-t"",
path,
""--ignore-installed"",
]
)
print(
""Install directory contents are now: {directory}"".format(
directory=os.listdir(path)
)
)
def pip_install_to_target(path, requirements=None, local_package=None):
""""""For a given active virtualenv, gather all installed pip packages then
copy (re-install) them to the path provided.
:param str path:
Path to copy installed pip packages to.
:param str requirements:
If set, only the packages in the supplied requirements file are
installed.
If not set then installs all packages found via pip freeze.
:param str local_package:
The path to a local package with should be included in the deploy as
well (and/or is not available on PyPi)
""""""
packages = []
if not requirements:
print(""Gathering pip packages"")
pkgStr = subprocess.check_output(
[sys.executable, ""-m"", ""pip"", ""freeze""]
)
packages.extend(pkgStr.decode(""utf-8"").splitlines())
else:
if os.path.exists(requirements):
print(""Gathering requirement packages"")
data = read(requirements)
packages.extend(data.splitlines())
if not packages:
print(""No dependency packages installed!"")
if local_package is not None:
if not isinstance(local_package, (list, tuple)):
local_package = [local_package]
for l_package in local_package:
packages.append(l_package)
_install_packages(path, packages)
def get_role_name(region, account_id, role):
""""""Shortcut to insert the `account_id` and `role` into the iam string.""""""
prefix = ARN_PREFIXES.get(region, ""aws"")
return ""arn:{0}:iam::{1}:role/{2}"".format(prefix, account_id, role)
def get_account_id(
profile_name, aws_access_key_id, aws_secret_access_key, region=None,
):
""""""Query STS for a users' account_id""""""
client = get_client(
""sts"", profile_name, aws_access_key_id, aws_secret_access_key, region,
)
return client.get_caller_identity().get(""Account"")
def get_client(
client,
profile_name,
aws_access_key_id,
aws_secret_access_key,
region=None,
):
""""""Shortcut for getting an initialized instance of the boto3 client.""""""
boto3.setup_default_session(
profile_name=profile_name,
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
region_name=region,
)
return boto3.client(client)