Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/python_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ def scan_manifest(self, manifest):
if local_path is None:
stored_resources[stored_path] = stored_resource.EmptyFile(
stored_path, self.timestamp_tuple)
elif os.path.isdir(local_path):
for local_root, dirs, files in os.walk(local_path):
for f in files:
stored_root = local_root.replace(local_path, stored_path, 1)
stored_fpath = os.path.join(stored_root, f)
local_fpath = os.path.join(local_root, f)
stored_resources[stored_fpath] = stored_resource.StoredFile(
stored_fpath, self.timestamp_tuple, local_fpath)
else:
stored_resources[stored_path] = stored_resource.StoredFile(
stored_path, self.timestamp_tuple, local_path)
Expand Down
18 changes: 18 additions & 0 deletions compiler/python_archive_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import os
import shutil
import subprocess
import sys
import time
Expand Down Expand Up @@ -216,6 +217,23 @@ def test_scan_manifest_has_collision(self):
resources['subpar/runtime/support.py'].local_filename,
shadowing_support_file.name)

def test_scan_manifest_directory(self):
par = self._construct()
try:
some_dir = test_utils.temp_dir()
with open(os.path.join(some_dir, "foo.py"), "w") as f:
f.write("foo\n")
with open(os.path.join(some_dir, "bar.py"), "w") as f:
f.write("bar\n")
manifest = {
'somedir': some_dir
}
resources = par.scan_manifest(manifest)
self.assertIn('somedir/foo.py', resources)
self.assertIn('somedir/bar.py', resources)
finally:
shutil.rmtree(some_dir)

def test_write_bootstrap(self):
par = self._construct()
with par.create_temp_parfile() as t:
Expand Down
5 changes: 5 additions & 0 deletions compiler/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ def temp_file(contents, suffix=''):
t.write(contents)
t.flush()
return t


def temp_dir():
tmpdir = get_test_tmpdir()
return tempfile.mkdtemp(dir=tmpdir)