sdg-hub 0.5.1__py3-none-any.whl → 0.6.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,57 +0,0 @@
1
- # SPDX-License-Identifier: Apache-2.0
2
- """Utilities for managing temporary files and directories used by the flow."""
3
-
4
- from __future__ import annotations
5
-
6
- from pathlib import Path
7
- from typing import Optional, Union
8
-
9
- # Standard
10
- import os
11
- import shutil
12
- import tempfile
13
-
14
- TEMP_ROOT_DIR_NAME = ".tmp_sdg_buffer"
15
-
16
-
17
- def _get_temp_root() -> Path:
18
- root = Path.cwd() / TEMP_ROOT_DIR_NAME
19
- root.mkdir(parents=True, exist_ok=True)
20
- return root
21
-
22
-
23
- def _format_prefix(prefix: str) -> str:
24
- return f"{prefix}_" if prefix and not prefix.endswith("_") else prefix
25
-
26
-
27
- def create_temp_dir(prefix: str = "tmp", suffix: str = "") -> Path:
28
- """Create a unique temporary directory."""
29
- root = _get_temp_root()
30
- name = tempfile.mkdtemp(prefix=_format_prefix(prefix), suffix=suffix, dir=root)
31
- return Path(name)
32
-
33
-
34
- def create_temp_file(prefix: str = "tmp", suffix: str = "") -> Path:
35
- """Create a unique temporary file."""
36
- root = _get_temp_root()
37
- fd, name = tempfile.mkstemp(prefix=_format_prefix(prefix), suffix=suffix, dir=root)
38
- os.close(fd)
39
- return Path(name)
40
-
41
-
42
- def cleanup_path(path: Optional[Union[str, os.PathLike]]) -> None:
43
- """Remove a temporary file or directory if it exists."""
44
- if not path:
45
- return
46
-
47
- target = Path(path)
48
- if not target.exists():
49
- return
50
-
51
- if target.is_dir():
52
- shutil.rmtree(target, ignore_errors=True)
53
- else:
54
- try:
55
- target.unlink()
56
- except FileNotFoundError:
57
- pass