Skip to content

Commit

Permalink
Attempt to workaround Windows temporary files permission issue
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed May 28, 2019
1 parent 0928967 commit 43179a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 18 additions & 9 deletions jupyter_manim/__init__.py
@@ -1,14 +1,18 @@
from IPython.core.magic import Magics, magics_class, cell_magic
from unittest.mock import patch
from tempfile import NamedTemporaryFile
import manimlib
from IPython.display import HTML
import os
import sys
from io import StringIO
from contextlib import ExitStack, suppress, redirect_stdout, redirect_stderr
from io import StringIO
from pathlib import Path
from tempfile import NamedTemporaryFile
from unittest.mock import patch
from warnings import warn

import manimlib
from IPython import get_ipython
from pathlib import Path
from IPython.core.magic import Magics, magics_class, cell_magic
from IPython.display import HTML

__version__ = 0.11

std_out = sys.stdout

Expand Down Expand Up @@ -103,9 +107,12 @@ def catch_path_and_forward(lines):
if line.startswith(self.path_line_start):
path = line[len(self.path_line_start):].strip()

with NamedTemporaryFile('w', suffix='.py') as f:
# Using a workaround for Windows permissions issue as in this questions:
# https://stackoverflow.com/q/15169101
f = NamedTemporaryFile('w', suffix='.py', delete=False)
try:
f.write(cell)
f.flush()
f.close()

args = ['manim', f.name, *user_args]

Expand All @@ -124,6 +131,8 @@ def catch_path_and_forward(lines):
enter(redirect_stderr(stderr))

manimlib.main()
finally:
os.remove(f.name)

if path:
path = Path(path)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -19,7 +19,7 @@ def get_long_description(file_name):
setup(
name='jupyter_manim',
packages=find_packages(),
version='0.1',
version='0.11',
license='MIT',
description='Cell magic rendering displaying videos in Jupyter/IPython',
long_description=get_long_description('README.md'),
Expand Down

0 comments on commit 43179a2

Please sign in to comment.