|
9 | 9 | import time
|
10 | 10 | from imp import load_source
|
11 | 11 | from shutil import copy
|
12 |
| -from shutil import copyfile |
| 12 | +from shutil import copyfile, copytree |
13 | 13 | from tempfile import mkdtemp
|
| 14 | +from collections import defaultdict |
14 | 15 |
|
15 | 16 | import boto3
|
16 | 17 | import botocore
|
@@ -242,24 +243,32 @@ def build(src, requirements=False, local_package=None):
|
242 | 243 | else output_filename
|
243 | 244 | )
|
244 | 245 |
|
| 246 | + # Allow definition of source code directories we want to build into our zipped package. |
| 247 | + build_config = defaultdict(**cfg.get('build', {})) |
| 248 | + source_directories = [d.strip() for d in build_config.get('source_directories', '').split(',')] |
| 249 | + |
245 | 250 | files = []
|
246 | 251 | for filename in os.listdir(src):
|
247 | 252 | if os.path.isfile(filename):
|
248 | 253 | if filename == '.DS_Store':
|
249 | 254 | continue
|
250 | 255 | if filename == 'config.yaml':
|
251 | 256 | continue
|
252 |
| - # TODO: Check subdirectories for '.DS_Store' files |
253 |
| - print('Bundling: %r' % filename) |
254 |
| - files.append(os.path.join(src, filename)) |
| 257 | + elif os.path.isdir(filename) and filename in source_directories: |
| 258 | + print('Bundling directory: %r' % filename) |
| 259 | + files.append(os.path.join(src, filename)) |
255 | 260 |
|
256 | 261 | # "cd" into `temp_path` directory.
|
257 | 262 | os.chdir(path_to_temp)
|
258 | 263 | for f in files:
|
259 |
| - _, filename = os.path.split(f) |
260 |
| - |
261 |
| - # Copy handler file into root of the packages folder. |
262 |
| - copyfile(f, os.path.join(path_to_temp, filename)) |
| 264 | + if os.path.isfile(f): |
| 265 | + _, filename = os.path.split(f) |
| 266 | + |
| 267 | + # Copy handler file into root of the packages folder. |
| 268 | + copyfile(f, os.path.join(path_to_temp, filename)) |
| 269 | + elif os.path.isdir(f): |
| 270 | + destination_folder = os.path.join(path_to_temp, f[len(src) + 1:]) |
| 271 | + copytree(f, destination_folder) |
263 | 272 |
|
264 | 273 | # Zip them together into a single file.
|
265 | 274 | # TODO: Delete temp directory created once the archive has been compiled.
|
|
0 commit comments