text
stringlengths
0
14.1k
# Gracefully handle whether "".zip"" was included in the filename or not.
output_filename = (
""{0}.zip"".format(output_filename)
if not output_filename.endswith("".zip"")
else output_filename
)
# Allow definition of source code directories we want to build into our
# zipped package.
build_config = defaultdict(**cfg.get(""build"", {}))
build_source_directories = build_config.get(""source_directories"", """")
build_source_directories = (
build_source_directories
if build_source_directories is not None
else """"
)
source_directories = [
d.strip() for d in build_source_directories.split("","")
]
files = []
for filename in os.listdir(src):
if os.path.isfile(filename):
if filename == "".DS_Store"":
continue
if filename == config_file:
continue
print(""Bundling: %r"" % filename)
files.append(os.path.join(src, filename))
elif os.path.isdir(filename) and filename in source_directories:
print(""Bundling directory: %r"" % filename)
files.append(os.path.join(src, filename))
# ""cd"" into `temp_path` directory.
os.chdir(path_to_temp)
for f in files:
if os.path.isfile(f):
_, filename = os.path.split(f)
# Copy handler file into root of the packages folder.
copyfile(f, os.path.join(path_to_temp, filename))
copystat(f, os.path.join(path_to_temp, filename))
elif os.path.isdir(f):
src_path_length = len(src) + 1
destination_folder = os.path.join(
path_to_temp, f[src_path_length:]
)
copytree(f, destination_folder)
# Zip them together into a single file.
# TODO: Delete temp directory created once the archive has been compiled.
path_to_zip_file = archive(""./"", path_to_dist, output_filename)
return path_to_zip_file
def get_callable_handler_function(src, handler):
""""""Translate a string of the form ""module.function"" into a callable
function.
:param str src:
The path to your Lambda project containing a valid handler file.
:param str handler:
A dot delimited string representing the `<module>.<function name>`.
""""""
# ""cd"" into `src` directory.
os.chdir(src)
module_name, function_name = handler.split(""."")
filename = get_handler_filename(handler)
path_to_module_file = os.path.join(src, filename)
module = load_source(module_name, path_to_module_file)
return getattr(module, function_name)
def get_handler_filename(handler):
""""""Shortcut to get the filename from the handler string.
:param str handler:
A dot delimited string representing the `<module>.<function name>`.
""""""
module_name, _ = handler.split(""."")
return ""{0}.py"".format(module_name)
def _install_packages(path, packages):
""""""Install all packages listed to the target directory.
Ignores any package that includes Python itself and python-lambda as well
since its only needed for deploying and not running the code
:param str path:
Path to copy installed pip packages to.
:param list packages:
A list of packages to be installed via pip.
""""""
def _filter_blacklist(package):