Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Resolve more race conditions potentially happening during directory creation (#4589)

Sachac8db165825ac
diff --git a/manim/cli/cfg/group.py b/manim/cli/cfg/group.py
index 3945499f8..fd09c0dc8 100644
--- a/manim/cli/cfg/group.py
+++ b/manim/cli/cfg/group.py
@@ -308,7 +308,7 @@ Are you sure you want to continue? (y/n)""",
if proceed:
if not directory_path.is_dir():
console.print(f"Creating folder: {directory}.", style="red bold")
- directory_path.mkdir(parents=True)
+ directory_path.mkdir(parents=True, exist_ok=True)
ctx.invoke(write)
from_path = Path.cwd() / "manim.cfg"
diff --git a/scripts/extract_frames.py b/scripts/extract_frames.py
index a8900de5c..b56e7b290 100644
--- a/scripts/extract_frames.py
+++ b/scripts/extract_frames.py
@@ -13,8 +13,7 @@ def main():
sys.exit(1)
npz_file = sys.argv[1]
output_folder = pathlib.Path(sys.argv[2])
- if not output_folder.exists():
- output_folder.mkdir(parents=True)
+ output_folder.mkdir(parents=True, exist_ok=True)
data = np.load(npz_file)
if "frame_data" not in data:
diff --git a/tests/helpers/graphical_units.py b/tests/helpers/graphical_units.py
index 1395559e5..232a6510e 100644
--- a/tests/helpers/graphical_units.py
+++ b/tests/helpers/graphical_units.py
@@ -53,7 +53,6 @@ def set_test_scene(scene_object: type[Scene], module_name: str, config):
tests_directory = Path(__file__).absolute().parent.parent
path_control_data = Path(tests_directory) / "control_data" / "graphical_units_data"
path = Path(path_control_data) / module_name
- if not path.is_dir():
- path.mkdir(parents=True)
+ path.mkdir(parents=True, exist_ok=True)
np.savez_compressed(path / str(scene), frame_data=data)
logger.info(f"Test data for {str(scene)} saved in {path}\n")
diff --git a/tests/module/mobject/mobject/test_copy.py b/tests/module/mobject/mobject/test_copy.py
index 39c6afd94..e772a0ff1 100644
--- a/tests/module/mobject/mobject/test_copy.py
+++ b/tests/module/mobject/mobject/test_copy.py
@@ -27,7 +27,7 @@ def test_bracelabel_copy(tmp_path, config):
config["text_dir"] = str(mediadir.joinpath("Text"))
config["tex_dir"] = str(mediadir.joinpath("Tex"))
for el in ["text_dir", "tex_dir"]:
- Path(config[el]).mkdir(parents=True)
+ Path(config[el]).mkdir(parents=True, exist_ok=True)
# Before the refactoring of Mobject.copy(), the class BraceLabel was the
# only one to have a non-trivial definition of copy. Here we test that it
diff --git a/tests/module/mobject/text/test_texmobject.py b/tests/module/mobject/text/test_texmobject.py
index 26631b97c..0206b0771 100644
--- a/tests/module/mobject/text/test_texmobject.py
+++ b/tests/module/mobject/text/test_texmobject.py
@@ -38,7 +38,7 @@ def test_tex_temp_directory(tmpdir, monkeypatch):
# tempconfig to change media directory to temporary directory by default
# we partially, revert that change here.
monkeypatch.chdir(tmpdir)
- Path(tmpdir, "media").mkdir()
+ Path(tmpdir, "media").mkdir(exist_ok=True)
with tempconfig({"media_dir": "media"}):
Tex("The horse does not eat cucumber salad.")
assert Path("media", "Tex").exists()
@@ -215,7 +215,7 @@ def test_tempconfig_resetting_tex_template(config):
def test_tex_garbage_collection(tmpdir, monkeypatch, config):
monkeypatch.chdir(tmpdir)
- Path(tmpdir, "media").mkdir()
+ Path(tmpdir, "media").mkdir(exist_ok=True)
config.media_dir = "media"
tex_without_log = Tex("Hello World!") # d771330b76d29ffb.tex
diff --git a/tests/opengl/test_copy_opengl.py b/tests/opengl/test_copy_opengl.py
index 504b7f26a..7f1232bec 100644
--- a/tests/opengl/test_copy_opengl.py
+++ b/tests/opengl/test_copy_opengl.py
@@ -28,7 +28,7 @@ def test_bracelabel_copy(config, using_opengl_renderer, tmp_path):
config["text_dir"] = str(mediadir.joinpath("Text"))
config["tex_dir"] = str(mediadir.joinpath("Tex"))
for el in ["text_dir", "tex_dir"]:
- Path(config[el]).mkdir(parents=True)
+ Path(config[el]).mkdir(parents=True, exist_ok=True)
# Before the refactoring of OpenGLMobject.copy(), the class BraceLabel was the
# only one to have a non-trivial definition of copy. Here we test that it
diff --git a/tests/test_plugins/test_plugins.py b/tests/test_plugins/test_plugins.py
index d5fc0a01f..54f2bddd3 100644
--- a/tests/test_plugins/test_plugins.py
+++ b/tests/test_plugins/test_plugins.py
@@ -105,7 +105,7 @@ def create_plugin(tmp_path, python_version, random_string):
def _create_plugin(entry_point, class_name, function_name, all_dec=""):
entry_point = entry_point.format(plugin_name=plugin_name)
module_dir = plugin_dir / plugin_name
- module_dir.mkdir(parents=True)
+ module_dir.mkdir(parents=True, exist_ok=True)
(module_dir / "__init__.py").write_text(
plugin_init_template.format(
class_name=class_name,