dazzle-filekit 0.2.0__tar.gz → 0.2.2__tar.gz

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.
Files changed (27) hide show
  1. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/PKG-INFO +21 -5
  2. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/README.md +20 -4
  3. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit/__init__.py +6 -2
  4. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit/operations.py +141 -0
  5. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit/utils/__init__.py +4 -2
  6. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit/utils/compat.py +83 -2
  7. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit.egg-info/PKG-INFO +21 -5
  8. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit.egg-info/SOURCES.txt +1 -0
  9. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/pyproject.toml +1 -1
  10. dazzle_filekit-0.2.2/tests/test_auto_naming.py +115 -0
  11. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/LICENSE +0 -0
  12. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit/paths.py +0 -0
  13. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit/platform/__init__.py +0 -0
  14. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit/platform/unix.py +0 -0
  15. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit/platform/windows.py +0 -0
  16. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit/utils/disk.py +0 -0
  17. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit/utils/logger.py +0 -0
  18. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit/utils/validation.py +0 -0
  19. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit/verification.py +0 -0
  20. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit.egg-info/dependency_links.txt +0 -0
  21. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit.egg-info/requires.txt +0 -0
  22. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/dazzle_filekit.egg-info/top_level.txt +0 -0
  23. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/setup.cfg +0 -0
  24. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/setup.py +0 -0
  25. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/tests/test_compat.py +0 -0
  26. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/tests/test_disk.py +0 -0
  27. {dazzle_filekit-0.2.0 → dazzle_filekit-0.2.2}/tests/test_smoke.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dazzle-filekit
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Cross-platform file operations toolkit with path handling, verification, and metadata preservation
5
5
  Author: Dustin
6
6
  Author-email: Dustin Darcy <6962246+djdarcy@users.noreply.github.com>
@@ -41,7 +41,7 @@ Dynamic: requires-python
41
41
 
42
42
  # dazzle-filekit
43
43
 
44
- [![PyPI version](https://badge.fury.io/py/dazzle-filekit.svg)](https://badge.fury.io/py/dazzle-filekit)
44
+ [![PyPI version](https://img.shields.io/pypi/v/dazzle-filekit.svg)](https://pypi.org/project/dazzle-filekit/)
45
45
  [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
46
46
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
47
47
  [![Platform](https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20macOS%20%7C%20BSD-lightgrey.svg)](docs/platform-support.md)
@@ -94,7 +94,11 @@ pip install dazzle-filekit[dev]
94
94
  ### Cross-Platform Path Handling
95
95
 
96
96
  ```python
97
- from dazzle_filekit import normalize_cross_platform_path, path_exists_cross_platform
97
+ from dazzle_filekit import (
98
+ normalize_cross_platform_path,
99
+ resolve_cross_platform_path,
100
+ path_exists_cross_platform,
101
+ )
98
102
 
99
103
  # Convert Git Bash style paths to native format
100
104
  # On Windows: /c/Users/foo -> C:\Users\foo
@@ -104,7 +108,11 @@ path = normalize_cross_platform_path("/c/Users/foo/file.txt")
104
108
  # Also handles WSL paths: /mnt/c/Users/...
105
109
  path = normalize_cross_platform_path("/mnt/c/Users/foo/file.txt")
106
110
 
107
- # Check if a cross-platform path exists
111
+ # Resolve with probing: if the normalized path doesn't exist,
112
+ # tries alternate platform formats (WSL, MSYS, Windows)
113
+ path = resolve_cross_platform_path("/mnt/c/Users/foo/file.txt")
114
+
115
+ # Check if a cross-platform path exists (uses resolve internally)
108
116
  if path_exists_cross_platform("/c/Users/foo/file.txt"):
109
117
  print("File exists!")
110
118
  ```
@@ -129,7 +137,7 @@ if is_unc_path(r"\\server\share"):
129
137
  ### File Operations
130
138
 
131
139
  ```python
132
- from dazzle_filekit import copy_file, collect_file_metadata
140
+ from dazzle_filekit import copy_file, collect_file_metadata, create_symlink
133
141
 
134
142
  # Copy file with metadata preservation
135
143
  success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
@@ -137,6 +145,12 @@ success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
137
145
  # Collect file metadata
138
146
  metadata = collect_file_metadata("file.txt")
139
147
  print(f"Size: {metadata['size']}, Modified: {metadata['mtime']}")
148
+
149
+ # Create symbolic link (cross-platform)
150
+ success = create_symlink("/path/to/target", "/path/to/link")
151
+
152
+ # Force replace existing link
153
+ success = create_symlink("/new/target", "/path/to/link", force=True)
140
154
  ```
141
155
 
142
156
  ### Disk Space Checking
@@ -179,6 +193,7 @@ is_valid = verify_file_hash("file.txt", expected_hash, algorithm="sha256")
179
193
  ### Cross-Platform Utilities
180
194
 
181
195
  - `normalize_cross_platform_path(path)` - Normalize Git Bash/WSL/Windows paths to native format
196
+ - `resolve_cross_platform_path(path)` - Normalize and probe alternate platform formats if path not found
182
197
  - `path_exists_cross_platform(path)` - Check path existence across formats
183
198
  - `is_windows()` / `is_unix()` - Platform detection
184
199
 
@@ -201,6 +216,7 @@ is_valid = verify_file_hash("file.txt", expected_hash, algorithm="sha256")
201
216
  - `create_directory_structure(path)` - Create directory tree
202
217
  - `remove_file(path)` - Remove file safely
203
218
  - `remove_directory(path, recursive)` - Remove directory
219
+ - `create_symlink(target, link, force)` - Create symbolic link with cross-platform support
204
220
 
205
221
  ### Disk Space Functions
206
222
 
@@ -1,6 +1,6 @@
1
1
  # dazzle-filekit
2
2
 
3
- [![PyPI version](https://badge.fury.io/py/dazzle-filekit.svg)](https://badge.fury.io/py/dazzle-filekit)
3
+ [![PyPI version](https://img.shields.io/pypi/v/dazzle-filekit.svg)](https://pypi.org/project/dazzle-filekit/)
4
4
  [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
6
  [![Platform](https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20macOS%20%7C%20BSD-lightgrey.svg)](docs/platform-support.md)
@@ -53,7 +53,11 @@ pip install dazzle-filekit[dev]
53
53
  ### Cross-Platform Path Handling
54
54
 
55
55
  ```python
56
- from dazzle_filekit import normalize_cross_platform_path, path_exists_cross_platform
56
+ from dazzle_filekit import (
57
+ normalize_cross_platform_path,
58
+ resolve_cross_platform_path,
59
+ path_exists_cross_platform,
60
+ )
57
61
 
58
62
  # Convert Git Bash style paths to native format
59
63
  # On Windows: /c/Users/foo -> C:\Users\foo
@@ -63,7 +67,11 @@ path = normalize_cross_platform_path("/c/Users/foo/file.txt")
63
67
  # Also handles WSL paths: /mnt/c/Users/...
64
68
  path = normalize_cross_platform_path("/mnt/c/Users/foo/file.txt")
65
69
 
66
- # Check if a cross-platform path exists
70
+ # Resolve with probing: if the normalized path doesn't exist,
71
+ # tries alternate platform formats (WSL, MSYS, Windows)
72
+ path = resolve_cross_platform_path("/mnt/c/Users/foo/file.txt")
73
+
74
+ # Check if a cross-platform path exists (uses resolve internally)
67
75
  if path_exists_cross_platform("/c/Users/foo/file.txt"):
68
76
  print("File exists!")
69
77
  ```
@@ -88,7 +96,7 @@ if is_unc_path(r"\\server\share"):
88
96
  ### File Operations
89
97
 
90
98
  ```python
91
- from dazzle_filekit import copy_file, collect_file_metadata
99
+ from dazzle_filekit import copy_file, collect_file_metadata, create_symlink
92
100
 
93
101
  # Copy file with metadata preservation
94
102
  success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
@@ -96,6 +104,12 @@ success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
96
104
  # Collect file metadata
97
105
  metadata = collect_file_metadata("file.txt")
98
106
  print(f"Size: {metadata['size']}, Modified: {metadata['mtime']}")
107
+
108
+ # Create symbolic link (cross-platform)
109
+ success = create_symlink("/path/to/target", "/path/to/link")
110
+
111
+ # Force replace existing link
112
+ success = create_symlink("/new/target", "/path/to/link", force=True)
99
113
  ```
100
114
 
101
115
  ### Disk Space Checking
@@ -138,6 +152,7 @@ is_valid = verify_file_hash("file.txt", expected_hash, algorithm="sha256")
138
152
  ### Cross-Platform Utilities
139
153
 
140
154
  - `normalize_cross_platform_path(path)` - Normalize Git Bash/WSL/Windows paths to native format
155
+ - `resolve_cross_platform_path(path)` - Normalize and probe alternate platform formats if path not found
141
156
  - `path_exists_cross_platform(path)` - Check path existence across formats
142
157
  - `is_windows()` / `is_unix()` - Platform detection
143
158
 
@@ -160,6 +175,7 @@ is_valid = verify_file_hash("file.txt", expected_hash, algorithm="sha256")
160
175
  - `create_directory_structure(path)` - Create directory tree
161
176
  - `remove_file(path)` - Remove file safely
162
177
  - `remove_directory(path, recursive)` - Remove directory
178
+ - `create_symlink(target, link, force)` - Create symbolic link with cross-platform support
163
179
 
164
180
  ### Disk Space Functions
165
181
 
@@ -40,6 +40,7 @@ from .paths import (
40
40
 
41
41
  from .utils.compat import (
42
42
  normalize_cross_platform_path,
43
+ resolve_cross_platform_path,
43
44
  path_exists_cross_platform,
44
45
  is_windows,
45
46
  is_unix
@@ -63,7 +64,8 @@ from .operations import (
63
64
  move_files_with_path,
64
65
  create_directory_structure,
65
66
  remove_file,
66
- remove_directory
67
+ remove_directory,
68
+ create_symlink
67
69
  )
68
70
 
69
71
  from .verification import (
@@ -77,7 +79,7 @@ from .verification import (
77
79
  verify_copied_files
78
80
  )
79
81
 
80
- __version__ = '0.2.0'
82
+ __version__ = '0.2.1'
81
83
 
82
84
  def configure_logging(level=logging.INFO, log_file=None):
83
85
  """
@@ -159,6 +161,7 @@ __all__ = [
159
161
 
160
162
  # Cross-platform path utilities
161
163
  'normalize_cross_platform_path',
164
+ 'resolve_cross_platform_path',
162
165
  'path_exists_cross_platform',
163
166
  'is_windows',
164
167
  'is_unix',
@@ -181,6 +184,7 @@ __all__ = [
181
184
  'create_directory_structure',
182
185
  'remove_file',
183
186
  'remove_directory',
187
+ 'create_symlink',
184
188
 
185
189
  # Verification functions
186
190
  'calculate_file_hash',
@@ -668,3 +668,144 @@ def remove_directory(path: Union[str, Path], recursive: bool = False, force: boo
668
668
  else:
669
669
  logger.error(f"Error removing directory {path}: {e}")
670
670
  return False
671
+
672
+
673
+ def create_symlink(
674
+ target: Union[str, Path],
675
+ link: Union[str, Path],
676
+ force: bool = False,
677
+ target_is_directory: Optional[bool] = None
678
+ ) -> bool:
679
+ """
680
+ Create a symbolic link with cross-platform handling.
681
+
682
+ On Unix systems, uses os.symlink directly.
683
+ On Windows, attempts multiple methods:
684
+ 1. os.symlink (requires Developer Mode or admin on Windows 10+)
685
+ 2. dazzlelink library if available (handles elevation gracefully)
686
+ 3. mklink command as fallback
687
+
688
+ Args:
689
+ target: The target path the symlink will point to
690
+ link: The path where the symlink will be created
691
+ force: If True, remove existing file/symlink at link path first
692
+ target_is_directory: Whether target is a directory (auto-detected if None)
693
+
694
+ Returns:
695
+ True if symlink was created successfully, False otherwise
696
+
697
+ Example:
698
+ >>> create_symlink('/path/to/file.txt', '/path/to/link.txt')
699
+ True
700
+ >>> create_symlink('C:\\data\\folder', 'C:\\links\\folder_link', target_is_directory=True)
701
+ True
702
+ """
703
+ target_path = Path(target)
704
+ link_path = Path(link)
705
+
706
+ # Handle existing link
707
+ if link_path.exists() or link_path.is_symlink():
708
+ if not force:
709
+ logger.warning(f"Link path already exists: {link_path}")
710
+ return False
711
+ try:
712
+ if link_path.is_dir() and not link_path.is_symlink():
713
+ shutil.rmtree(link_path)
714
+ else:
715
+ link_path.unlink()
716
+ logger.debug(f"Removed existing path: {link_path}")
717
+ except Exception as e:
718
+ logger.error(f"Failed to remove existing path {link_path}: {e}")
719
+ return False
720
+
721
+ # Create parent directories if needed
722
+ try:
723
+ link_path.parent.mkdir(parents=True, exist_ok=True)
724
+ except Exception as e:
725
+ logger.error(f"Failed to create parent directories for {link_path}: {e}")
726
+ return False
727
+
728
+ # Auto-detect if target is a directory
729
+ if target_is_directory is None:
730
+ target_is_directory = target_path.is_dir()
731
+
732
+ # Try to create symlink
733
+ if platform.system() != 'Windows':
734
+ # Unix: straightforward symlink
735
+ try:
736
+ os.symlink(target_path, link_path)
737
+ logger.debug(f"Created symlink: {link_path} -> {target_path}")
738
+ return True
739
+ except Exception as e:
740
+ logger.error(f"Failed to create symlink on Unix: {e}")
741
+ return False
742
+
743
+ # Windows: try multiple methods
744
+ return _create_windows_symlink(target_path, link_path, target_is_directory)
745
+
746
+
747
+ def _create_windows_symlink(target: Path, link: Path, is_directory: bool) -> bool:
748
+ """
749
+ Create a symbolic link on Windows using multiple fallback methods.
750
+
751
+ Args:
752
+ target: Target path
753
+ link: Link path to create
754
+ is_directory: Whether target is a directory
755
+
756
+ Returns:
757
+ True if successful, False otherwise
758
+ """
759
+ # Method 1: Try os.symlink (works with Developer Mode enabled)
760
+ try:
761
+ os.symlink(target, link, target_is_directory=is_directory)
762
+ logger.debug(f"Created Windows symlink using os.symlink: {link} -> {target}")
763
+ return True
764
+ except OSError as e:
765
+ # Error 1314 = "A required privilege is not held by the client"
766
+ if getattr(e, 'winerror', 0) == 1314:
767
+ logger.debug("os.symlink failed (Developer Mode not enabled), trying alternatives")
768
+ else:
769
+ logger.warning(f"os.symlink failed: {e}")
770
+
771
+ # Method 2: Try dazzlelink if available
772
+ try:
773
+ from dazzlelink.operations import create_windows_symlink as dazzle_create_symlink
774
+ result = dazzle_create_symlink(str(target), str(link), is_directory)
775
+ if result:
776
+ logger.debug(f"Created Windows symlink using dazzlelink: {link} -> {target}")
777
+ return True
778
+ except ImportError:
779
+ logger.debug("dazzlelink not available, trying mklink fallback")
780
+ except Exception as e:
781
+ logger.warning(f"dazzlelink symlink creation failed: {e}")
782
+
783
+ # Method 3: Try mklink command (may require elevation)
784
+ try:
785
+ import subprocess
786
+ dir_flag = '/D ' if is_directory else ''
787
+ cmd = f'mklink {dir_flag}"{link}" "{target}"'
788
+
789
+ result = subprocess.run(
790
+ ['cmd', '/c', cmd],
791
+ text=True,
792
+ capture_output=True,
793
+ check=False
794
+ )
795
+
796
+ if result.returncode == 0:
797
+ logger.debug(f"Created Windows symlink using mklink: {link} -> {target}")
798
+ return True
799
+ else:
800
+ logger.warning(f"mklink failed: {result.stderr.strip()}")
801
+ except Exception as e:
802
+ logger.warning(f"mklink command failed: {e}")
803
+
804
+ # All methods failed
805
+ logger.error(
806
+ f"Failed to create symlink on Windows. This typically requires either:\n"
807
+ f" 1. Developer Mode enabled (Settings > Update & Security > For developers)\n"
808
+ f" 2. Running as Administrator\n"
809
+ f" 3. Install dazzlelink: pip install dazzlelink"
810
+ )
811
+ return False
@@ -15,7 +15,8 @@ from .compat import (
15
15
  is_windows, is_unix, is_admin, is_root,
16
16
  fix_path_separators, fix_path_case, get_system_encoding,
17
17
  get_system_temp_dir, get_home_dir, get_app_data_dir,
18
- normalize_cross_platform_path, path_exists_cross_platform
18
+ normalize_cross_platform_path, resolve_cross_platform_path,
19
+ path_exists_cross_platform
19
20
  )
20
21
 
21
22
  from .validation import (
@@ -40,7 +41,8 @@ __all__ = [
40
41
  'is_windows', 'is_unix', 'is_admin', 'is_root',
41
42
  'fix_path_separators', 'fix_path_case', 'get_system_encoding',
42
43
  'get_system_temp_dir', 'get_home_dir', 'get_app_data_dir',
43
- 'normalize_cross_platform_path', 'path_exists_cross_platform',
44
+ 'normalize_cross_platform_path', 'resolve_cross_platform_path',
45
+ 'path_exists_cross_platform',
44
46
 
45
47
  # Validation functions
46
48
  'is_valid_path', 'is_safe_path', 'validate_path_chars',
@@ -248,6 +248,84 @@ def normalize_cross_platform_path(path: Union[str, Path]) -> Path:
248
248
  return Path(path_str)
249
249
 
250
250
 
251
+ def resolve_cross_platform_path(path: Union[str, Path]) -> Path:
252
+ """
253
+ Resolve a path by normalizing it and probing alternate platform formats.
254
+
255
+ First normalizes using normalize_cross_platform_path(). If the result
256
+ doesn't exist, tries alternate platform representations:
257
+
258
+ On Windows:
259
+ /mnt/c/Users/... -> C:\\Users\\... (WSL mount)
260
+ /c/Users/... -> C:\\Users\\... (MSYS/Git Bash)
261
+ .../mnt/c/Users/... -> C:\\Users\\... (MSYS-mangled WSL)
262
+
263
+ On Linux/macOS:
264
+ C:\\Users\\... -> /mnt/c/Users/... (WSL)
265
+ C:\\Users\\... -> /c/Users/... (MSYS)
266
+
267
+ Returns the first existing candidate, or the normalized form if none exist.
268
+
269
+ Args:
270
+ path: Path string in any supported format
271
+
272
+ Returns:
273
+ Path object for the best match found
274
+
275
+ Examples:
276
+ # On Windows, if C:\\Users\\foo\\file.txt exists:
277
+ resolve_cross_platform_path("/mnt/c/Users/foo/file.txt")
278
+ # -> Path("C:/Users/foo/file.txt")
279
+ """
280
+ import re
281
+
282
+ normalized = normalize_cross_platform_path(path)
283
+
284
+ if normalized.exists():
285
+ return normalized
286
+
287
+ path_str = str(normalized)
288
+
289
+ if is_windows():
290
+ # Try WSL /mnt/c/ -> C:\ (in case normalization didn't catch it)
291
+ wsl_match = re.match(r'^/mnt/([a-zA-Z])(/.*)?$', str(path))
292
+ if wsl_match:
293
+ drive = wsl_match.group(1).upper()
294
+ rest = (wsl_match.group(2) or '').replace('/', '\\')
295
+ candidate = Path(f"{drive}:{rest}")
296
+ if candidate.exists():
297
+ return candidate
298
+
299
+ # Check for MSYS-mangled WSL paths
300
+ # Git Bash converts /mnt/c/... to C:\Program Files\Git\mnt\c\...
301
+ mangled = re.search(r'[/\\]mnt[/\\]([a-zA-Z])[/\\](.*)', path_str)
302
+ if mangled:
303
+ drive = mangled.group(1).upper()
304
+ rest = mangled.group(2).replace('/', '\\')
305
+ candidate = Path(f"{drive}:\\{rest}")
306
+ if candidate.exists():
307
+ return candidate
308
+
309
+ else:
310
+ # On Linux/macOS: try Windows path -> WSL or MSYS format
311
+ win_match = re.match(r'^([a-zA-Z]):[/\\](.*)', path_str)
312
+ if win_match:
313
+ drive = win_match.group(1).lower()
314
+ rest = win_match.group(2).replace('\\', '/')
315
+
316
+ # Try WSL mount
317
+ candidate = Path(f"/mnt/{drive}/{rest}")
318
+ if candidate.exists():
319
+ return candidate
320
+
321
+ # Try MSYS/Git Bash style
322
+ candidate = Path(f"/{drive}/{rest}")
323
+ if candidate.exists():
324
+ return candidate
325
+
326
+ return normalized
327
+
328
+
251
329
  def path_exists_cross_platform(path: Union[str, Path]) -> bool:
252
330
  """
253
331
  Check if a path exists, handling cross-platform path formats.
@@ -255,6 +333,9 @@ def path_exists_cross_platform(path: Union[str, Path]) -> bool:
255
333
  This is useful when receiving paths from external sources (like Claude Code)
256
334
  that may be in a different format than the current platform expects.
257
335
 
336
+ Uses resolve_cross_platform_path() to try alternate platform formats
337
+ if the normalized path doesn't exist.
338
+
258
339
  Args:
259
340
  path: Path string in any supported format
260
341
 
@@ -262,8 +343,8 @@ def path_exists_cross_platform(path: Union[str, Path]) -> bool:
262
343
  True if the path exists, False otherwise
263
344
  """
264
345
  try:
265
- normalized = normalize_cross_platform_path(path)
266
- return normalized.exists()
346
+ resolved = resolve_cross_platform_path(path)
347
+ return resolved.exists()
267
348
  except Exception:
268
349
  return False
269
350
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dazzle-filekit
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Cross-platform file operations toolkit with path handling, verification, and metadata preservation
5
5
  Author: Dustin
6
6
  Author-email: Dustin Darcy <6962246+djdarcy@users.noreply.github.com>
@@ -41,7 +41,7 @@ Dynamic: requires-python
41
41
 
42
42
  # dazzle-filekit
43
43
 
44
- [![PyPI version](https://badge.fury.io/py/dazzle-filekit.svg)](https://badge.fury.io/py/dazzle-filekit)
44
+ [![PyPI version](https://img.shields.io/pypi/v/dazzle-filekit.svg)](https://pypi.org/project/dazzle-filekit/)
45
45
  [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
46
46
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
47
47
  [![Platform](https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20macOS%20%7C%20BSD-lightgrey.svg)](docs/platform-support.md)
@@ -94,7 +94,11 @@ pip install dazzle-filekit[dev]
94
94
  ### Cross-Platform Path Handling
95
95
 
96
96
  ```python
97
- from dazzle_filekit import normalize_cross_platform_path, path_exists_cross_platform
97
+ from dazzle_filekit import (
98
+ normalize_cross_platform_path,
99
+ resolve_cross_platform_path,
100
+ path_exists_cross_platform,
101
+ )
98
102
 
99
103
  # Convert Git Bash style paths to native format
100
104
  # On Windows: /c/Users/foo -> C:\Users\foo
@@ -104,7 +108,11 @@ path = normalize_cross_platform_path("/c/Users/foo/file.txt")
104
108
  # Also handles WSL paths: /mnt/c/Users/...
105
109
  path = normalize_cross_platform_path("/mnt/c/Users/foo/file.txt")
106
110
 
107
- # Check if a cross-platform path exists
111
+ # Resolve with probing: if the normalized path doesn't exist,
112
+ # tries alternate platform formats (WSL, MSYS, Windows)
113
+ path = resolve_cross_platform_path("/mnt/c/Users/foo/file.txt")
114
+
115
+ # Check if a cross-platform path exists (uses resolve internally)
108
116
  if path_exists_cross_platform("/c/Users/foo/file.txt"):
109
117
  print("File exists!")
110
118
  ```
@@ -129,7 +137,7 @@ if is_unc_path(r"\\server\share"):
129
137
  ### File Operations
130
138
 
131
139
  ```python
132
- from dazzle_filekit import copy_file, collect_file_metadata
140
+ from dazzle_filekit import copy_file, collect_file_metadata, create_symlink
133
141
 
134
142
  # Copy file with metadata preservation
135
143
  success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
@@ -137,6 +145,12 @@ success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
137
145
  # Collect file metadata
138
146
  metadata = collect_file_metadata("file.txt")
139
147
  print(f"Size: {metadata['size']}, Modified: {metadata['mtime']}")
148
+
149
+ # Create symbolic link (cross-platform)
150
+ success = create_symlink("/path/to/target", "/path/to/link")
151
+
152
+ # Force replace existing link
153
+ success = create_symlink("/new/target", "/path/to/link", force=True)
140
154
  ```
141
155
 
142
156
  ### Disk Space Checking
@@ -179,6 +193,7 @@ is_valid = verify_file_hash("file.txt", expected_hash, algorithm="sha256")
179
193
  ### Cross-Platform Utilities
180
194
 
181
195
  - `normalize_cross_platform_path(path)` - Normalize Git Bash/WSL/Windows paths to native format
196
+ - `resolve_cross_platform_path(path)` - Normalize and probe alternate platform formats if path not found
182
197
  - `path_exists_cross_platform(path)` - Check path existence across formats
183
198
  - `is_windows()` / `is_unix()` - Platform detection
184
199
 
@@ -201,6 +216,7 @@ is_valid = verify_file_hash("file.txt", expected_hash, algorithm="sha256")
201
216
  - `create_directory_structure(path)` - Create directory tree
202
217
  - `remove_file(path)` - Remove file safely
203
218
  - `remove_directory(path, recursive)` - Remove directory
219
+ - `create_symlink(target, link, force)` - Create symbolic link with cross-platform support
204
220
 
205
221
  ### Disk Space Functions
206
222
 
@@ -19,6 +19,7 @@ dazzle_filekit/utils/compat.py
19
19
  dazzle_filekit/utils/disk.py
20
20
  dazzle_filekit/utils/logger.py
21
21
  dazzle_filekit/utils/validation.py
22
+ tests/test_auto_naming.py
22
23
  tests/test_compat.py
23
24
  tests/test_disk.py
24
25
  tests/test_smoke.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "dazzle-filekit"
7
- version = "0.2.0"
7
+ version = "0.2.2"
8
8
  description = "Cross-platform file operations toolkit with path handling, verification, and metadata preservation"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -0,0 +1,115 @@
1
+ """Test the auto-naming logic."""
2
+ import re
3
+
4
+ # Mock the dependencies
5
+ class MockPath:
6
+ def __init__(self, path_str):
7
+ self._path = path_str.replace('\\', '/')
8
+ self._parts = tuple(p for p in self._path.split('/') if p)
9
+
10
+ @property
11
+ def name(self):
12
+ return self._parts[-1] if self._parts else ''
13
+
14
+ @property
15
+ def parts(self):
16
+ return self._parts
17
+
18
+ @property
19
+ def parent(self):
20
+ if len(self._parts) <= 1:
21
+ return self
22
+ return MockPath('/'.join(self._parts[:-1]))
23
+
24
+ def __eq__(self, other):
25
+ return self._path == other._path if isinstance(other, MockPath) else False
26
+
27
+ def __str__(self):
28
+ return self._path
29
+
30
+ def normalize_cross_platform_path(p):
31
+ return MockPath(p)
32
+
33
+ def debug_log(msg):
34
+ pass
35
+
36
+ GENERIC_FOLDER_NAMES = {
37
+ 'home', 'user', 'users', 'code', 'projects', 'project', 'work',
38
+ 'dev', 'development', 'src', 'source', 'app', 'apps', 'local',
39
+ 'current', 'main', 'master', 'opt', 'var', 'tmp', 'temp',
40
+ 'desktop', 'documents', 'downloads', 'repos', 'repository',
41
+ 'github', 'gitlab', 'bitbucket', 'workspace', 'workspaces',
42
+ }
43
+ DRIVE_LETTERS = {'c', 'd', 'e', 'f', 'g', 'h', 'z'}
44
+
45
+ def _sanitize_folder_name(name):
46
+ sanitized = re.sub(r'[^a-zA-Z0-9_-]', '-', name.lower())
47
+ sanitized = re.sub(r'-+', '-', sanitized)
48
+ return sanitized.strip('-')
49
+
50
+ def derive_session_name_from_cwd(cwd):
51
+ """Strategy: non-generic folder -> use it; otherwise -> path from nearest non-generic ancestor (with drive letter)"""
52
+ if not cwd:
53
+ return None
54
+ path = normalize_cross_platform_path(cwd)
55
+
56
+ # Use path.parts to get all components including drive letter
57
+ try:
58
+ all_parts = path.parts
59
+ except AttributeError:
60
+ path_str = str(path).replace('\\', '/')
61
+ all_parts = [p for p in path_str.split('/') if p]
62
+
63
+ # Collect last 4 meaningful parts with metadata
64
+ parts = [] # (sanitized, raw, is_drive)
65
+ for part in all_parts[-4:]:
66
+ raw = part.rstrip(':\\/')
67
+ sanitized = _sanitize_folder_name(raw)
68
+ if sanitized:
69
+ is_drive = sanitized in DRIVE_LETTERS
70
+ parts.append((sanitized, raw.lower(), is_drive))
71
+
72
+ if not parts:
73
+ return None
74
+
75
+ # Strategy 1: Non-generic current folder (not drive) -> use it alone
76
+ current_name, current_raw, current_is_drive = parts[-1]
77
+ if current_raw not in GENERIC_FOLDER_NAMES and not current_is_drive and len(current_name) >= 3:
78
+ return current_name[:50]
79
+
80
+ # Strategy 2: Find nearest non-generic ancestor (not drive), use path from there
81
+ start_idx = 0
82
+ for i in range(len(parts) - 2, -1, -1):
83
+ _, raw, is_drive = parts[i]
84
+ if raw not in GENERIC_FOLDER_NAMES and not is_drive:
85
+ start_idx = i
86
+ break
87
+
88
+ path_parts = [s for s, r, d in parts[start_idx:] if len(s) >= 1]
89
+ if path_parts:
90
+ path_name = '--'.join(path_parts)
91
+ if len(path_name) > 50:
92
+ path_name = path_name[:50].rsplit('--', 1)[0]
93
+ return path_name
94
+ return None
95
+
96
+ if __name__ == '__main__':
97
+ # Test cases - (path, expected_name)
98
+ test_cases = [
99
+ (r'C:\code\claude-code-task-manager', 'claude-code-task-manager'), # Non-generic folder
100
+ (r'C:\code', 'c--code'), # Generic + drive -> include drive
101
+ (r'C:\code\local', 'c--code--local'), # All generic -> include drive
102
+ (r'C:\code\my-project\local', 'my-project--local'), # Has non-generic parent
103
+ (r'C:\Users\Extreme\Documents', 'extreme--documents'), # Has non-generic parent
104
+ ('/home/dev/projects/my-app', 'my-app'), # Non-generic folder
105
+ ('/opt/STAGING/current', 'staging--current'), # Has non-generic parent
106
+ (r'Z:\code\project', 'z--code--project'), # All generic on Z drive
107
+ (r'Z:\code', 'z--code'), # Generic on Z drive
108
+ ]
109
+
110
+ print("Path -> Auto-generated Name")
111
+ print("-" * 70)
112
+ for path, expected in test_cases:
113
+ result = derive_session_name_from_cwd(path)
114
+ status = "OK" if result == expected else f"FAIL (expected: {expected})"
115
+ print(f'{path:45} -> {result:20} {status}')
File without changes
File without changes
File without changes