Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
plietar committed Apr 24, 2024
1 parent f124a20 commit a926521
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/outpack/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from outpack.schema import outpack_schema_version, validate
from outpack.search import as_query, search_unique
from outpack.tools import git_info
from outpack.util import all_normal_files
from outpack.util import all_normal_files, as_posix_path


# TODO: most of these fields should be private.
Expand Down Expand Up @@ -78,7 +78,7 @@ def end(self, *, insert=True):
self.time["end"] = time.time()
hash_algorithm = self.root.config.core.hash_algorithm
self.files = [
PacketFile.from_file(self.path, Path(f).as_posix(), hash_algorithm)
PacketFile.from_file(self.path, as_posix_path(f), hash_algorithm)
for f in all_normal_files(self.path)
]
_check_immutable_files(self.files, self.immutable)
Expand Down
6 changes: 3 additions & 3 deletions src/outpack/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def all_normal_files(path):
result = []
for root, dirs, files in os.walk(path):
base = Path(root).relative_to(path)
result.extend(base.joinpath(f).as_posix() for f in files)
result.extend(str(base.joinpath(f)) for f in files)

if "__pycache__" in dirs:
dirs.remove("__pycache__")
Expand Down Expand Up @@ -111,9 +111,9 @@ def expand_dirs(paths, *, workdir=None):
with transient_working_directory(workdir):
for p in paths:
if os.path.isdir(p):
ret += [as_posix_path(p, f) for f in all_normal_files(p)]
ret += [os.path.join(p, f) for f in all_normal_files(p)]
else:
ret.append(as_posix_path(p))
ret.append(p)
return ret


Expand Down
19 changes: 11 additions & 8 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def test_all_normal_files_recurses(tmp_path):

assert set(all_normal_files(tmp_path)) == {
"foo.txt",
"a/bar.txt",
"a/b/baz.txt",
"a/b/c/quux.txt",
os.path.join("a/bar.txt"),
os.path.join("a/b/baz.txt"),
os.path.join("a/b/c/quux.txt"),
}


Expand All @@ -126,15 +126,18 @@ def test_all_normal_files_excludes_pycache(tmp_path):

assert set(all_normal_files(tmp_path)) == {
"a.txt",
"a/d.txt",
os.path.join("a", "d.txt"),
}


def test_can_expand_paths(tmp_path):
helpers.touch_files(tmp_path / "a" / "x", tmp_path / "a" / "y")
(tmp_path / "b").mkdir()

expected_ax_ay = {"a/x", "a/y"}
expected_ax_ay = {
os.path.join("a", "x"),
os.path.join("a", "y"),
}

assert expand_dirs([], workdir=tmp_path) == []
assert set(expand_dirs(["a"], workdir=tmp_path)) == expected_ax_ay
Expand All @@ -143,9 +146,9 @@ def test_can_expand_paths(tmp_path):
helpers.touch_files(tmp_path / "b" / "x")

expected_ax_ay_bx = {
"a/x",
"a/y",
"b/x",
os.path.join("a", "x"),
os.path.join("a", "y"),
os.path.join("b", "x"),
}
assert set(expand_dirs(["a", "b"], workdir=tmp_path)) == expected_ax_ay_bx

Expand Down

0 comments on commit a926521

Please sign in to comment.