Skip to content

Commit 89d5583

Browse files
authored
Fix an issue with pycache ignore for live reload (#273)
1 parent c6d9990 commit 89d5583

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "truss"
3-
version = "0.4.4dev4"
3+
version = "0.4.4"
44
description = "A seamless bridge from model development to model delivery"
55
license = "MIT"
66
readme = "README.md"

truss/patch/calc_patch.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,22 @@ def _calc_changed_paths(
134134
"""
135135
TODO(pankaj) add support for directory creation in patch
136136
"""
137-
unignored_paths = _calc_unignored_paths(root, ignore_patterns)
137+
root_relative_new_paths = set(
138+
(str(path.relative_to(root)) for path in root.glob("**/*"))
139+
)
140+
unignored_new_paths = _calc_unignored_paths(
141+
root, root_relative_new_paths, ignore_patterns
142+
)
138143
previous_root_relative_paths = set(previous_root_path_content_hashes.keys())
144+
unignored_prev_paths = _calc_unignored_paths(
145+
root, previous_root_relative_paths, ignore_patterns
146+
)
139147

140-
added_paths = unignored_paths - previous_root_relative_paths
141-
removed_paths = previous_root_relative_paths - unignored_paths
148+
added_paths = unignored_new_paths - unignored_prev_paths
149+
removed_paths = unignored_prev_paths - unignored_new_paths
142150

143151
updated_paths = set()
144-
common_paths = unignored_paths.intersection(previous_root_relative_paths)
152+
common_paths = unignored_new_paths.intersection(unignored_prev_paths)
145153
for path in common_paths:
146154
full_path: Path = root / path
147155
if full_path.is_file():
@@ -158,7 +166,9 @@ def _calc_changed_paths(
158166

159167

160168
def _calc_unignored_paths(
161-
root: Path, ignore_patterns: Optional[List[str]] = None
169+
root: Path,
170+
root_relative_paths: Set[str],
171+
ignore_patterns: Optional[List[str]] = None,
162172
) -> Set[str]:
163173
root_relative_ignored_paths = set()
164174
if ignore_patterns is not None:
@@ -168,9 +178,6 @@ def _calc_unignored_paths(
168178
)
169179
root_relative_ignored_paths.update(ignored_paths_for_pattern)
170180

171-
root_relative_paths = set(
172-
(str(path.relative_to(root)) for path in root.glob("**/*"))
173-
)
174181
return root_relative_paths - root_relative_ignored_paths
175182

176183

truss/tests/patch/test_calc_patch.py

+17
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@ def test_calc_truss_ignore_pycache(custom_model_truss_dir: Path):
119119
assert len(patches) == 0
120120

121121

122+
def test_calc_truss_ignore_pycache_existing(custom_model_truss_dir: Path):
123+
# If __pycache__ existed before and there are no changes, there should be no
124+
# patches.
125+
top_pycache_path = custom_model_truss_dir / "__pycache__"
126+
top_pycache_path.mkdir()
127+
(top_pycache_path / "bla.pyc").touch()
128+
model_pycache_path = custom_model_truss_dir / "model" / "__pycache__"
129+
model_pycache_path.mkdir()
130+
(model_pycache_path / "foo.pyo").touch()
131+
sign = calc_truss_signature(custom_model_truss_dir)
132+
patches = calc_truss_patch(
133+
custom_model_truss_dir,
134+
sign,
135+
)
136+
assert len(patches) == 0
137+
138+
122139
def test_calc_truss_ignore_changes_outside_patch_relevant_dirs(
123140
custom_model_truss_dir: Path,
124141
):

0 commit comments

Comments
 (0)