Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support py3.9 #12

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
2 changes: 2 additions & 0 deletions blambda/blambda-env
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ elif [[ ${BLAMBDA_ENV} == 'blambda-3.7' ]]; then
PYENV_PATH = '.pyenv/versions/3.7.5/lib/python3.7/'
elif [[ ${BLAMBDA_ENV} == 'blambda-3.8' ]]; then
PYENV_PATH = '.pyenv/versions/3.8.1/lib/python3.8/'
elif [[ ${BLAMBDA_ENV} == 'blambda-3.9' ]]; then
PYENV_PATH = '.pyenv/versions/3.9.13/lib/python3.9/'
else
echo "blambda couldn't read the python environment from manifest, aborting!"
return 1
Expand Down
12 changes: 11 additions & 1 deletion blambda/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,23 @@ def publish(name, role, zipfile, options, dryrun):
print("Function Package: {} bytes".format(len(file_bytes)))
if not dryrun:
try:
# TODO: Remove this once all py 3.8 lambdas are deployed on prod
# Added below code to update lambda runtime first and then deploy it
# cprint("Updating lambda function configuration - todo: remove", 'yellow')
# response = client.update_function_configuration(
# FunctionName=name,
# **options
# )

# time.sleep(15)

cprint("Updating lambda function code", 'yellow')
response = client.update_function_code(
FunctionName=name,
ZipFile=file_bytes
)

time.sleep(5)
time.sleep(15)

cprint("Updating lambda function configuration", 'yellow')
response = client.update_function_configuration(
Expand Down
1 change: 1 addition & 0 deletions blambda/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'python36': LambdaRuntime('python3.6', '.py', 'python/src'),
'python37': LambdaRuntime('python3.7', '.py', 'python/src'),
'python38': LambdaRuntime('python3.8', '.py', 'python/src'),
'python39': LambdaRuntime('python3.9', '.py', 'python/src'),
'coffee': LambdaRuntime('nodejs4.3', '.coffee', 'node/src')
}

Expand Down
2 changes: 1 addition & 1 deletion blambda/update_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_py_version(dep):
def get_node_version(module):
try:
version = check_output(['npm', 'view', module, 'version'], universal_newlines=True).strip()
print("{}: {}".format(module, version))
print("node_version_check {}: {}".format(module, version))
return module, version
except Exception as e:
cprint("{}: {}".format(module, str(e)), 'red')
Expand Down
6 changes: 6 additions & 0 deletions blambda/utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ def spawn(cmd, show=False, working_directory=None, raise_on_fail=False):
if working_directory == "":
working_directory = None

cprint(f"working_directory -> {working_directory} cmd -> {cmd}", 'blue')

p = Popen(cmd, cwd=working_directory, shell=True, stderr=PIPE, stdout=PIPE)
(stdout, stderr) = (normalize(out) for out in p.communicate())

if show:
if p.returncode == 0:
import os
files = os.listdir(working_directory)
cprint("List of files")
print(files)
cprint(" {} -> [OK]".format(cmd), 'blue')
else:
cprint(" {} -> [FAIL]\n{}".format(cmd, "\n".join(stderr + stdout)), 'red')
Expand Down
6 changes: 5 additions & 1 deletion blambda/utils/env_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
py36 = LambdaRuntime('python3.6', '3.6.1', 'blambda-3.6')
py37 = LambdaRuntime('python3.7', '3.7.5', 'blambda-3.7')
py38 = LambdaRuntime('python3.8', '3.8.1', 'blambda-3.8')
py39 = LambdaRuntime('python3.9', '3.9.13', 'blambda-3.9')

runtimes = {
py27.name: py27,
py36.name: py36,
py37.name: py37,
py38.name: py38
py38.name: py38,
py39.name: py39
}

DEFAULT_RUNTIME = py36
Expand Down Expand Up @@ -78,6 +80,8 @@ def create_virtualenv(self, clean=True):

cprint("Creating {} virtualenv...".format(self.runtime.env_name), "yellow")

cprint(f"current_runtime env {self.runtime.env_name} current_runtime version {self.runtime.version}", "yellow")

args = ['pyenv', 'virtualenv', '--clear', self.runtime.version, self.runtime.env_name]
sp.check_call(args)
tools_upgrade = [self.pip, 'install', '--upgrade']
Expand Down
29 changes: 26 additions & 3 deletions blambda/utils/lambda_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,40 @@ def process_manifest(self, clean=False, prod=False):

tempdir = tempfile.mkdtemp()
node_modules = Path(tempdir) / "node_modules"
node_modules.symlink_to(self.node_dir)

# import os
# cprint("List of node dir")
# print(os.listdir(self.node_dir))

# node_modules.symlink_to(self.node_dir)
# print("symlinked" , node_modules.resolve())
os.system(f"ln -s {node_modules} {self.node_dir}")

if clean and self.node_dir.exists():
shutil.rmtree(self.node_dir)

self.node_dir.mkdir(exist_ok=True)
# os.system(f"ls -al {node_modules}")
# os.system(f"ls -al {self.node_dir}")

# cprint(f"current_node_dir {self.node_dir}", 'blue')
# cprint(f"node_modules {node_modules}", 'blue')
# cprint(f"tempdir {tempdir}",'blue')

# Commenting below line as of now, because it throws error if dir is already exists
# Which should not be the case.
# self.node_dir.mkdir(exist_ok=True)

# install node dependencies 1 at a time to avoid race condition issues
for dependency, version in deps_to_install.items():
cprint(f"npm install {dependency}@{version}",'blue')
spawn(f"npm install {dependency}@{version}", show=True, working_directory=tempdir)

shutil.rmtree(tempdir)
cprint("List of node_dir")
print(os.listdir(self.node_dir))

# Commenting below line because symlink is created to temp directory and
# While deploying lambda it is trying to copy content from symlinked dir.
# shutil.rmtree(tempdir)

else:
raise RuntimeError("Unknown runtime: " + self.runtime)
Expand All @@ -217,6 +239,7 @@ def process_manifest(self, clean=False, prod=False):

# check for files that are to be moved and link them
for src, dst in self.source_files():
cprint(f"in loop src {src} dst {dst}")
dst.parent.mkdir(parents=True, exist_ok=True)

if not dst.exists():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
author='Balihoo Developers',
author_email='devall@balihoo.com',
license='MIT',
url='git@github.com:balihoo/fulfillment-lambda-functions.git',
url='git+https://github.com/balihoo/fulfillment-lambda-functions.git',
install_requires=['boto3', 'python-dateutil', 'requests', 'termcolor', 'lxml', 'beautifulsoup4'],
packages=find_packages(exclude=['tests']),
include_package_data=True,
Expand Down