prthm11 commited on
Commit
85c13c2
·
verified ·
1 Parent(s): 7028127

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -19
app.py CHANGED
@@ -1827,36 +1827,33 @@ def similarity_matching(sprites_data: dict, project_folder: str, top_k: int = 1,
1827
 
1828
  # Flatten unique matched indices to process copying once per folder
1829
  matched_indices = sorted({idx for lst in per_sprite_matched_indices for idx in lst})
1830
- print("matched_indices=========================>",matched_indices)
 
1831
  for matched_idx in matched_indices:
1832
  matched_image_path = paths_list[matched_idx]
 
 
 
 
1833
  matched_folder = os.path.dirname(matched_image_path)
1834
  matched_filename = os.path.basename(matched_image_path)
1835
  # --- Minimal diagnostics (drop these in prod) ---
1836
  try:
1837
  # Normalize many forms so we can compare apples-to-apples
1838
- mf_abs = os.path.normpath(os.path.abspath(matched_folder))
 
1839
  mf_repr = repr(matched_folder)
1840
  mf_abspath_repr = repr(mf_abs)
1841
-
1842
  # backdrop / sprite base (may be pathlib.Path in prod)
1843
  bb = os.path.normpath(os.path.abspath(str(backdrop_base_path)))
1844
  sb = os.path.normpath(os.path.abspath(str(sprite_base_path)))
1845
-
1846
  # quick membership tests
1847
- starts_with_backdrop = matched_folder.startswith(backdrop_base_path) or mf_abs.startswith(bb)
1848
- starts_with_sprite = matched_folder.startswith(sprite_base_path) or mf_abs.startswith(sb)
1849
-
1850
- # cross-platform commonpath test
1851
- try:
1852
- common_with_backdrop = (os.path.commonpath([mf_abs, bb]) == bb)
1853
- except Exception:
1854
- common_with_backdrop = False
1855
- try:
1856
- common_with_sprite = (os.path.commonpath([mf_abs, sb]) == sb)
1857
- except Exception:
1858
- common_with_sprite = False
1859
-
1860
  print("DEBUG matched_idx:", matched_idx)
1861
  print("DEBUG matched_image_path:", matched_image_path)
1862
  print("DEBUG matched_folder (raw):", mf_repr)
@@ -1865,13 +1862,12 @@ def similarity_matching(sprites_data: dict, project_folder: str, top_k: int = 1,
1865
  print("DEBUG backdrop_base_path (abs):", repr(bb))
1866
  print("DEBUG sprite_base_path (raw):", repr(sprite_base_path))
1867
  print("DEBUG sprite_base_path (abs):", repr(sb))
1868
- print("DEBUG startswith_backdrop:", starts_with_backdrop, " startswith_sprite:", starts_with_sprite)
1869
  print("DEBUG common_with_backdrop:", common_with_backdrop, " common_with_sprite:", common_with_sprite)
1870
  # Show a short sample of the reference path for matched index
1871
  print("DEBUG sample paths_list entry:", repr(paths_list[matched_idx])[:400])
1872
  except Exception as _e:
1873
  print("DEBUG diagnostics failed:", _e)
1874
- # --- end diagnostics ---
1875
  # If it's a sprite (under SPRITE_DIR) -> copy sprite assets and read sprite.json
1876
  # if matched_folder.startswith(sprite_base_path) and matched_folder not in copied_sprite_folders:
1877
  if is_subpath(matched_folder, sprite_base_path) and matched_folder not in copied_sprite_folders:
 
1827
 
1828
  # Flatten unique matched indices to process copying once per folder
1829
  matched_indices = sorted({idx for lst in per_sprite_matched_indices for idx in lst})
1830
+ print("matched_indices------------------>",matched_indices)
1831
+
1832
  for matched_idx in matched_indices:
1833
  matched_image_path = paths_list[matched_idx]
1834
+
1835
+ # --- Change 1: Convert path to absolute path for reliable comparison
1836
+ matched_image_path = os.path.abspath(matched_image_path)
1837
+
1838
  matched_folder = os.path.dirname(matched_image_path)
1839
  matched_filename = os.path.basename(matched_image_path)
1840
  # --- Minimal diagnostics (drop these in prod) ---
1841
  try:
1842
  # Normalize many forms so we can compare apples-to-apples
1843
+ # --- Change 2: Use the already normalized matched_image_path for consistency
1844
+ mf_abs = os.path.normpath(matched_folder)
1845
  mf_repr = repr(matched_folder)
1846
  mf_abspath_repr = repr(mf_abs)
1847
+
1848
  # backdrop / sprite base (may be pathlib.Path in prod)
1849
  bb = os.path.normpath(os.path.abspath(str(backdrop_base_path)))
1850
  sb = os.path.normpath(os.path.abspath(str(sprite_base_path)))
1851
+
1852
  # quick membership tests
1853
+ # --- Change 3: Use os.path.commonpath for reliable cross-platform checks
1854
+ starts_with_backdrop = (os.path.commonpath([mf_abs, bb]) == bb)
1855
+ starts_with_sprite = (os.path.commonpath([mf_abs, sb]) == sb)
1856
+
 
 
 
 
 
 
 
 
 
1857
  print("DEBUG matched_idx:", matched_idx)
1858
  print("DEBUG matched_image_path:", matched_image_path)
1859
  print("DEBUG matched_folder (raw):", mf_repr)
 
1862
  print("DEBUG backdrop_base_path (abs):", repr(bb))
1863
  print("DEBUG sprite_base_path (raw):", repr(sprite_base_path))
1864
  print("DEBUG sprite_base_path (abs):", repr(sb))
1865
+ print("DEBUG starts_with_backdrop:", starts_with_backdrop, " starts_with_sprite:", starts_with_sprite)
1866
  print("DEBUG common_with_backdrop:", common_with_backdrop, " common_with_sprite:", common_with_sprite)
1867
  # Show a short sample of the reference path for matched index
1868
  print("DEBUG sample paths_list entry:", repr(paths_list[matched_idx])[:400])
1869
  except Exception as _e:
1870
  print("DEBUG diagnostics failed:", _e)
 
1871
  # If it's a sprite (under SPRITE_DIR) -> copy sprite assets and read sprite.json
1872
  # if matched_folder.startswith(sprite_base_path) and matched_folder not in copied_sprite_folders:
1873
  if is_subpath(matched_folder, sprite_base_path) and matched_folder not in copied_sprite_folders: