Skip to content

Commit 0d5895f

Browse files
committed
Purge the remove_if_temporary_notebook function
Not needed if rewrite_notebook always produces temporary files. Just use os.remove to clean up after rewrite_notebook.
1 parent 92477a7 commit 0d5895f

File tree

5 files changed

+9
-44
lines changed

5 files changed

+9
-44
lines changed

dev_tools/notebooks/__init__.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from dev_tools.notebooks.utils import (
16-
filter_notebooks,
17-
list_all_notebooks,
18-
remove_if_temporary_notebook,
19-
rewrite_notebook,
20-
)
15+
from dev_tools.notebooks.utils import filter_notebooks, list_all_notebooks, rewrite_notebook

dev_tools/notebooks/isolated_notebook_test.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@
3333
import pytest
3434

3535
from dev_tools import shell_tools
36-
from dev_tools.notebooks import (
37-
list_all_notebooks,
38-
filter_notebooks,
39-
rewrite_notebook,
40-
remove_if_temporary_notebook,
41-
)
36+
from dev_tools.notebooks import list_all_notebooks, filter_notebooks, rewrite_notebook
4237

4338
# these notebooks rely on features that are not released yet
4439
# after every release we should raise a PR and empty out this list
@@ -213,7 +208,7 @@ def test_notebooks_against_released_cirq(partition, notebook_path, cloned_env):
213208
f"instead of `pip install cirq` to this notebook, and exclude it from "
214209
f"dev_tools/notebooks/isolated_notebook_test.py."
215210
)
216-
remove_if_temporary_notebook(rewritten_notebook_path)
211+
os.remove(rewritten_notebook_path)
217212

218213

219214
@pytest.mark.parametrize("notebook_path", NOTEBOOKS_DEPENDING_ON_UNRELEASED_FEATURES)

dev_tools/notebooks/notebook_test.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@
2424
import pytest
2525

2626
from dev_tools import shell_tools
27-
from dev_tools.notebooks import (
28-
filter_notebooks,
29-
list_all_notebooks,
30-
rewrite_notebook,
31-
remove_if_temporary_notebook,
32-
)
27+
from dev_tools.notebooks import filter_notebooks, list_all_notebooks, rewrite_notebook
3328

3429
SKIP_NOTEBOOKS = [
3530
# skipping vendor notebooks as we don't have auth sorted out
@@ -88,4 +83,4 @@ def test_notebooks_against_released_cirq(notebook_path):
8883
f"notebook (in Github Actions, you can download it from the workflow artifact"
8984
f" 'notebook-outputs')"
9085
)
91-
remove_if_temporary_notebook(rewritten_notebook_path)
86+
os.remove(rewritten_notebook_path)

dev_tools/notebooks/utils.py

-16
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,3 @@ def rewrite_notebook(notebook_path):
120120
new_file.writelines(lines)
121121

122122
return new_file.name
123-
124-
125-
def remove_if_temporary_notebook(notebook_path: str):
126-
"""Delete temporary notebook if written by `rewrite_notebook`.
127-
128-
Do nothing if the specified notebook is not in the temporary directory
129-
or if its filename does not end in '-rewrite.ipynb'
130-
131-
Use this to safely clean up notebooks created by `rewrite_notebook`.
132-
"""
133-
if (
134-
notebook_path.endswith('-rewrite.ipynb')
135-
and os.path.isfile(notebook_path)
136-
and os.path.dirname(notebook_path) == tempfile.gettempdir()
137-
):
138-
os.remove(notebook_path)

dev_tools/notebooks/utils_test.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ def test_rewrite_notebook():
4545
rewritten = f.read()
4646
assert rewritten == 'd = 3\nd = 4'
4747

48-
dt.remove_if_temporary_notebook(path)
49-
assert not os.path.exists(path)
48+
os.remove(path)
5049
shutil.rmtree(directory)
5150

5251

@@ -59,8 +58,7 @@ def test_rewrite_notebook_multiple():
5958
rewritten = f.read()
6059
assert rewritten == 'd = 3\nd = 1'
6160

62-
dt.remove_if_temporary_notebook(path)
63-
assert not os.path.exists(path)
61+
os.remove(path)
6462
shutil.rmtree(directory)
6563

6664

@@ -73,8 +71,7 @@ def test_rewrite_notebook_ignore_non_seperator_lines():
7371
rewritten = f.read()
7472
assert rewritten == 'd = 3\nd = 4'
7573

76-
dt.remove_if_temporary_notebook(path)
77-
assert not os.path.exists(path)
74+
os.remove(path)
7875
shutil.rmtree(directory)
7976

8077

@@ -88,8 +85,7 @@ def test_rewrite_notebook_no_tst_file():
8885
assert path != ipynb_path
8986
assert filecmp.cmp(path, ipynb_path)
9087

91-
dt.remove_if_temporary_notebook(path)
92-
88+
os.remove(path)
9389
shutil.rmtree(directory)
9490

9591

0 commit comments

Comments
 (0)