Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows Container] Use windows home dir as temp dir location #3951

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/system/temporary_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from types import FunctionType
from typing import Any

from system.os import current_platform


def g__handleRemoveReadonly(func: FunctionType, path: str, exc: Any) -> Any:
excvalue = exc[1]
Expand All @@ -38,7 +40,12 @@
class TemporaryDirectory:
def __init__(self, keep: bool = False, chdir: bool = False) -> None:
self.keep = keep
self.name = tempfile.mkdtemp()
if current_platform() == "windows":
windows_home_dir = os.path.expanduser('~')
self.name = tempfile.mkdtemp(dir=windows_home_dir)

Check warning on line 45 in src/system/temporary_directory.py

View check run for this annotation

Codecov / codecov/patch

src/system/temporary_directory.py#L44-L45

Added lines #L44 - L45 were not covered by tests
else:
self.name = tempfile.mkdtemp()

if chdir:
self.curdir = os.getcwd()
os.chdir(self.name)
Expand Down
10 changes: 10 additions & 0 deletions tests/tests_system/test_temporary_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

import os
import stat
import tempfile
import unittest
from pathlib import Path

from system.os import current_platform
from system.temporary_directory import TemporaryDirectory


Expand Down Expand Up @@ -51,3 +53,11 @@ def test_path(self) -> None:
with TemporaryDirectory() as work_dir:
self.assertIsInstance(work_dir.path, Path)
self.assertTrue(work_dir.path.exists())

def test_path_windows(self) -> None:
with TemporaryDirectory() as work_dir:
if current_platform() == "windows":
windows_home_dir = os.path.expanduser('~')
self.assertTrue(str(work_dir.path).startswith(windows_home_dir))
else:
self.assertTrue(str(work_dir.path).startswith(tempfile.gettempdir()))
Loading