1- import sys
2- from modules .item_manager import read_item_data , write_item_data , get_item_path
1+ """
2+ Chronos `copy` command.
3+
4+ Important compatibility note:
5+ - This file is named `copy.py` because it powers the `copy` CLI command.
6+ - In some Chronos startup paths, the `commands/` directory can end up on
7+ `sys.path`, which means imports like `from copy import deepcopy` may
8+ accidentally resolve to this file instead of Python's standard-library
9+ `copy` module.
10+
11+ To avoid breaking those imports, this command file proxies the standard-library
12+ `copy` API (`copy`, `deepcopy`, and related error symbols) before defining the
13+ Chronos command entrypoints.
14+ """
15+
16+ import importlib .util
317import os
18+ import sysconfig
19+
20+
21+ def _load_stdlib_copy_module ():
22+ """Load the real Python standard-library `copy` module by filesystem path."""
23+ stdlib_dir = sysconfig .get_path ("stdlib" )
24+ if not stdlib_dir :
25+ raise ImportError ("Could not locate Python stdlib path for copy module." )
26+
27+ copy_path = os .path .join (stdlib_dir , "copy.py" )
28+ spec = importlib .util .spec_from_file_location ("_chronos_stdlib_copy" , copy_path )
29+ if spec is None or spec .loader is None :
30+ raise ImportError (f"Could not load stdlib copy module from: { copy_path } " )
31+
32+ module = importlib .util .module_from_spec (spec )
33+ spec .loader .exec_module (module )
34+ return module
35+
36+
37+ _STDLIB_COPY = _load_stdlib_copy_module ()
38+
39+ # Re-export the stdlib API so `from copy import deepcopy` still works even if
40+ # this file is resolved as module `copy`.
41+ copy = _STDLIB_COPY .copy
42+ deepcopy = _STDLIB_COPY .deepcopy
43+ Error = getattr (_STDLIB_COPY , "Error" , Exception )
44+ error = getattr (_STDLIB_COPY , "error" , Error )
45+
46+ __all__ = ["copy" , "deepcopy" , "Error" , "error" , "run" , "get_help_message" ]
447
548# --- Command Definition ---
649def run (args , properties ):
750 """
851 Handles the 'copy' command, creating a duplicate of an existing item.
952 """
53+ from modules .item_manager import read_item_data , write_item_data , get_item_path
54+
1055 # Validate command arguments
1156 if len (args ) < 2 :
1257 print (get_help_message ())
@@ -66,4 +111,4 @@ def get_help_message():
66111Description: Creates a duplicate of an existing item, optionally with a new name and modified properties.
67112Example: copy note MyMeetingNotes MyMeetingNotes_Copy
68113Example: copy task "Old Task" "New Task" status:pending priority:high
69- """
114+ """
0 commit comments