Skip to content

Commit 380392c

Browse files
committed
refactor: allow for trailing slashes in folder upload
1 parent e5b2171 commit 380392c

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

lighthouse/deploy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ def deploy(source: str, token: str) -> t.Deploy:
2121
# check if source is a directory
2222
if is_dir(source):
2323
# walk directory tree and add files to list
24-
file_dict["files"] = walk_dir_tree(source)
24+
file_dict["files"], root = walk_dir_tree(source)
2525
file_dict["is_dir"] = True
26-
file_dict["path"] = source
26+
file_dict["path"] = root
2727
else:
2828
# add file to list
2929
file_dict["files"] = [source]

lighthouse/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
from . import types as t
77

88
# walk path and return list of file paths
9-
def walk_dir_tree(path: str) -> List[str]:
9+
def walk_dir_tree(path: str) -> Tuple[List[str], str]:
1010
file_list = []
11+
roots = []
1112
for root, dirs, files in os.walk(path):
13+
roots.append(root)
1214
for file in files:
1315
file_list.append(os.path.join(root, file))
14-
return file_list
16+
return file_list, roots[0]
1517

1618

1719
# check if file is a directory
@@ -24,6 +26,8 @@ def extract_file_name(file: str) -> str:
2426

2527

2628
def extract_file_name_with_source(file: str, source: str) -> str:
29+
if source.endswith("/"):
30+
source = source[: len(source) - 1]
2731
base = source.split("/")[-1]
2832
return base + file.split(base)[-1]
2933

tests/test_deploy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_deploy_file(self):
2121
def test_deploy_dir(self):
2222
"""test deploy function"""
2323
l = Lighthouse(os.environ["LH_TOKEN"])
24-
res = l.deploy("tests/testdir")
24+
res = l.deploy("tests/testdir/")
2525
self.assertNotEqual(res.get("data"), None, "data is None")
2626
self.assertIsInstance(res.get("data"), str, "data is a string")
2727
self.assertIn("Hash", res.get("data"), "Hash is in data")

0 commit comments

Comments
 (0)