harnice 0.3.1__py3-none-any.whl → 0.3.2__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.
harnice/fileio.py CHANGED
@@ -41,13 +41,15 @@ def path(target_value, structure_dict=None, base_directory=None):
41
41
 
42
42
  # returns the filepath/filename of a filekey.
43
43
  """
44
- Recursively searches for a value in a nested JSON structure and returns the path to the element containing that value.
44
+ Recursively searches for a value in a nested JSON structure and returns the path to the element containing that value.
45
45
 
46
- Args:
47
- target_value (str): The value to search for.
46
+ It's complicated ... check out https://harnice.io/commands/fileio/ for more information.
47
+
48
+ Args:
49
+ target_value (str): The value to search for.
48
50
 
49
- Returns:
50
- list: A list of container names leading to the element containing the target value, or None if not found.
51
+ Returns:
52
+ list: A list of container names leading to the element containing the target value, or None if not found.
51
53
  """
52
54
 
53
55
  # FILES NOT DEPENDENT ON PRODUCT TYPE
@@ -65,7 +67,20 @@ def path(target_value, structure_dict=None, base_directory=None):
65
67
  harnice_root = os.path.dirname(
66
68
  os.path.dirname(os.path.dirname(harnice.__file__))
67
69
  )
68
- return os.path.join(harnice_root, "library_locations.csv")
70
+
71
+ library_locations_path = os.path.join(harnice_root, "library_locations.csv")
72
+
73
+ if not os.path.exists(library_locations_path):
74
+ from harnice import cli
75
+ answer = cli.prompt(f"Library locations file not found at {library_locations_path}. Create it?", default="y")
76
+ if answer.lower() not in ("y", "yes", ""):
77
+ exit()
78
+
79
+ with open(library_locations_path, "w") as f:
80
+ f.write("repo_url,local_path\n")
81
+ f.write(f"https://github.com/harnice/harnice,{os.path.join(harnice_root, 'library_public')}\n")
82
+
83
+ return library_locations_path
69
84
 
70
85
  if target_value == "project locations":
71
86
  import harnice
@@ -73,6 +88,17 @@ def path(target_value, structure_dict=None, base_directory=None):
73
88
  harnice_root = os.path.dirname(
74
89
  os.path.dirname(os.path.dirname(harnice.__file__))
75
90
  )
91
+ project_locations_path = os.path.join(harnice_root, "project_locations.csv")
92
+ if not os.path.exists(project_locations_path):
93
+ from harnice import cli
94
+ answer = cli.prompt(f"Project locations file not found at {project_locations_path}. Create it?", default="y")
95
+ if answer.lower() not in ("y", "yes", ""):
96
+ exit()
97
+
98
+ with open(project_locations_path, "w") as f:
99
+ f.write("traceable_key,local_path\n")
100
+ f.write("your project part number,local path to your project\n")
101
+
76
102
  return os.path.join(harnice_root, "project_locations.csv")
77
103
 
78
104
  if target_value == "drawnby":
@@ -81,7 +107,24 @@ def path(target_value, structure_dict=None, base_directory=None):
81
107
  harnice_root = os.path.dirname(
82
108
  os.path.dirname(os.path.dirname(harnice.__file__))
83
109
  )
84
- return os.path.join(harnice_root, "drawnby.json")
110
+
111
+ drawnby_path = os.path.join(harnice_root, "drawnby.json")
112
+ if not os.path.exists(drawnby_path):
113
+ from harnice import cli
114
+ answer = cli.prompt(f"Drawnby file not found at {drawnby_path}. Create it?", default="y")
115
+ if answer.lower() not in ("y", "yes", ""):
116
+ exit()
117
+
118
+ name = cli.prompt("Enter your name: (recommended: first inital, last name, all caps: K SHUTT)")
119
+
120
+ while not name:
121
+ print("Name cannot be empty. Please try again.")
122
+ name = cli.prompt("Enter your name")
123
+
124
+ with open(drawnby_path, "w") as f:
125
+ f.write(f"{name}\n")
126
+
127
+ return drawnby_path
85
128
 
86
129
  # FILES INSIDE OF A STRUCURE DEFINED BY FILEIO
87
130
  # look up from default structure state if not provided
@@ -32,32 +32,32 @@ Overwrite a revision history entry.
32
32
 
33
33
  **Arguments:**
34
34
 
35
- - `content_dict` (dict): The content to overwrite the revision history entry with.
36
- - This should be a dictionary with the keys and values to overwrite.
37
- - The keys should be the column names, and the values should be the new values.
38
- - Some keys are protected and cannot be overwritten:
39
- - `"product"`
40
- - `"mfg"`
41
- - `"pn"`
42
- - `"rev"`
43
- - `"releaseticket"`
44
- - `"library_repo"`
45
- - `"library_subpath"`
46
- - `"datestarted"`
35
+ - `content_dict` (dict): The content to overwrite the revision history entry with.
36
+ - This should be a dictionary with the keys and values to overwrite.
37
+ - The keys should be the column names, and the values should be the new values.
38
+ - Some keys are protected and cannot be overwritten:
39
+ - `"product"`
40
+ - `"mfg"`
41
+ - `"pn"`
42
+ - `"rev"`
43
+ - `"releaseticket"`
44
+ - `"library_repo"`
45
+ - `"library_subpath"`
46
+ - `"datestarted"`
47
47
 
48
48
  The function will update the revision history file as referenced by the current product file structure.
49
49
 
50
50
  **Returns:**
51
51
 
52
- - `None`
52
+ - `None`
53
53
 
54
54
  **Raises:**
55
55
 
56
- - `KeyError`: If a key is provided that is not in the COLUMNS list.
57
- - `KeyError`: If a protected key is provided.
58
- - `ValueError`: If the revision history file is not found.
59
- - `ValueError`: If the revision is not found in the revision history file.
60
- - `RuntimeError`: If `state.rev` is not set.
56
+ - `KeyError`: If a key is provided that is not in the COLUMNS list.
57
+ - `KeyError`: If a protected key is provided.
58
+ - `ValueError`: If the revision history file is not found.
59
+ - `ValueError`: If the revision is not found in the revision history file.
60
+ - `RuntimeError`: If `state.rev` is not set.
61
61
  """
62
62
  PROTECTED_KEYS = [
63
63
  "product",
@@ -417,17 +417,24 @@ def append(next_rev=None):
417
417
  # add lib_repo if filepath is found in library locations
418
418
  library_repo = ""
419
419
  library_subpath = ""
420
- cwd = str(os.getcwd()).lower().strip("~")
420
+ # Normalize path separators for comparison (handle both forward and backslashes)
421
+ cwd = str(os.getcwd()).lower().replace("\\", "/").strip("~")
421
422
 
422
423
  for row in fileio.read_tsv("library locations", delimiter=","):
423
- lib_local_path = str(row.get("local_path", "")).lower().strip("~")
424
+ # Normalize path separators and expand user home directory if needed
425
+ lib_local_path_raw = str(row.get("local_path", "")).strip()
426
+ lib_local_path = (
427
+ os.path.expanduser(lib_local_path_raw).lower().replace("\\", "/").strip("~")
428
+ )
424
429
  if lib_local_path in cwd:
425
430
  library_repo = row.get("repo_url")
426
431
 
427
432
  # keep only the portion AFTER local_path
428
433
  idx = cwd.find(lib_local_path)
429
- remainder = cwd[idx + len(lib_local_path) :].lstrip("/")
430
- parts = remainder.split("/")
434
+ remainder = cwd[idx + len(lib_local_path) :]
435
+ # Normalize path separators - handle both forward and backslashes
436
+ remainder = remainder.replace("\\", "/").lstrip("/")
437
+ parts = remainder.split("/") if remainder else []
431
438
 
432
439
  # find the part number in the path
433
440
  pn = str(state.partnumber("pn")).lower()
@@ -438,6 +445,7 @@ def append(next_rev=None):
438
445
  core_parts = parts
439
446
 
440
447
  # build library_subpath and product
448
+ # Use forward slashes for cross-platform compatibility (works in URLs and most contexts)
441
449
  if core_parts:
442
450
  library_subpath = (
443
451
  "/".join(core_parts[1:]) + "/" if len(core_parts) > 1 else ""
@@ -510,8 +518,6 @@ def part_family_append(content_dict, rev_history_path):
510
518
  fileio.get_git_hash_of_harnice_src()
511
519
  )
512
520
 
513
- rev = content_dict.get("rev")
514
-
515
521
  if os.path.exists(rev_history_path):
516
522
  rows = fileio.read_tsv(rev_history_path)
517
523
  else:
@@ -303,7 +303,9 @@ def get_local_path(lib_repo):
303
303
  os.makedirs(os.path.dirname(csv_path), exist_ok=True)
304
304
 
305
305
  with open(csv_path, "w", encoding="utf-8") as f:
306
- f.write(f"https://github.com/harnice/harnice,{default_local_path}\n")
306
+ # Normalize the default path to ensure correct separators
307
+ normalized_path = os.path.normpath(default_local_path)
308
+ f.write(f"https://github.com/harnice/harnice,{normalized_path}\n")
307
309
 
308
310
  print(f"[harnice] Created '{csv_path}'")
309
311
  print(f"[harnice] Default library-public location: {default_local_path}")
@@ -328,6 +330,10 @@ def get_local_path(lib_repo):
328
330
  if url.lower() == lib_repo.lower().strip():
329
331
  if not local:
330
332
  raise ValueError(f"No local path found for '{lib_repo}'")
331
- return os.path.expanduser(local)
333
+ # Expand user directory (~) and normalize path separators for current platform
334
+ expanded_path = os.path.expanduser(local)
335
+ # Normalize separators - os.path.normpath() converts forward slashes to
336
+ # backslashes on Windows, ensuring proper path format
337
+ return os.path.normpath(expanded_path)
332
338
 
333
339
  raise ValueError(f"'{lib_repo}' not found in library locations")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: harnice
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Electrical System CAD
5
5
  Author-email: Kenyon Shutt <harnice.io@gmail.com>
6
6
  Project-URL: Documentation, https://harnice.io/
@@ -1,7 +1,7 @@
1
1
  harnice/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  harnice/__main__.py,sha256=6Ni-cHmuKYqm9WKNd5bgzHyMkpyJ80IzoUmBqldUanw,68
3
3
  harnice/cli.py,sha256=npYeqdywC8C4dStWzGnwy25hTapUEkCTFeNwo9aDmi8,6571
4
- harnice/fileio.py,sha256=MiBPo5Z6DfEDkuFs9purekJHxNW3w1spjs_AZONAzCc,9511
4
+ harnice/fileio.py,sha256=DT0eqw5ATLwtIQ5KA825CvBY-kxN11KneImJH2TvSS8,11360
5
5
  harnice/state.py,sha256=V-HK1Jgh5sfEt9m3keYFdZGtvW2cA88gM8b_4Tx05-k,1248
6
6
  harnice/gui/launcher.py,sha256=R0T48RJkgFOJqFhgO7CvZa05zzHOu_q5tgV9U1iwreY,12993
7
7
  harnice/lists/channel_map.py,sha256=Q3cuBcYTQg7H25SFx8wb2Q0o4zNNCCS8WRBMPrwyGxg,6112
@@ -12,7 +12,7 @@ harnice/lists/instances_list.py,sha256=g28vHzarDpsRu3aPEPaX-gsRZ_knJW9fgWAn174qr
12
12
  harnice/lists/library_history.py,sha256=DhuRJWs1ziyfnhzEsmn3kVD5iaRELQ8OQ9UmDvmFjPU,1576
13
13
  harnice/lists/manifest.py,sha256=nCwibNehQ1VYDN9_Q7vqM8DfssQXO4IQ1n39AW9Bp8Y,3039
14
14
  harnice/lists/post_harness_instances_list.py,sha256=dxTwCLSRHX0J4YdEUx8GNMy9-UL8DK__4llGKTRrWSY,2490
15
- harnice/lists/rev_history.py,sha256=efIK8V3gAqk8gK3f2MnH1zI744JiNPub6-1E0PUM2to,18058
15
+ harnice/lists/rev_history.py,sha256=GyxirEfFwmjSLXguo4g9yzK_atnBK7L4nwH5dyygklk,18525
16
16
  harnice/lists/signals_list.py,sha256=qqRAtxYsJeSVL0XDESFbBDrdcxhWKAq6oZAqPVVrSOE,6972
17
17
  harnice/products/__init__.py,sha256=LlsPf7uk1kyBdmaBuLhlGwcQau3uzEUdCW_eqtTs7TQ,29
18
18
  harnice/products/cable.py,sha256=I05__-WxJUR-teV-oYB1Qzi5ufWbbYCOfM8oqCSXWPs,5107
@@ -29,13 +29,13 @@ harnice/utils/appearance.py,sha256=ps_tMLdbURL-FCIv0Z3X19bTRFVRIuP0J5N9zvugUbs,1
29
29
  harnice/utils/circuit_utils.py,sha256=k5CfwYaL2flvilE5r_pZPy_puY9nyC093DO-H3s0VYU,13085
30
30
  harnice/utils/feature_tree_utils.py,sha256=dLcEUdvrA9p_EGWIqqBfRb5ZuxuXNp9OZcLh2W4N300,6973
31
31
  harnice/utils/formboard_utils.py,sha256=f7SXn8uFMysv5_Gq-84G-jOauSrbMeL8PBPquzkq8Sw,36861
32
- harnice/utils/library_utils.py,sha256=KgBHisCuB3IOuhCSwXUoLNalI8Mz_8vFS_jI4j-1d0M,12564
32
+ harnice/utils/library_utils.py,sha256=Qp6UEtmcgQvK8Jxxt88GngQX_OBvhxumV_hCqcfwpFQ,13015
33
33
  harnice/utils/note_utils.py,sha256=flcWmaRNz03t-Xo6bbp8erF9FuuUuAG5hcW7ephx02M,15676
34
34
  harnice/utils/svg_utils.py,sha256=HZrEdTS1dHyrHxaYM35Va644bdrkwao5OkJPG_RPX2Y,33490
35
35
  harnice/utils/system_utils.py,sha256=nFIEaf_5rt0kVETvB7DX-RVCNLH7Q9ZAhPBtFpio__Q,25651
36
- harnice-0.3.1.dist-info/licenses/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
37
- harnice-0.3.1.dist-info/METADATA,sha256=lNIUXpgv-pLrrzm-bVi78XusXrYAzDsl5_ptKbZUej8,1072
38
- harnice-0.3.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
39
- harnice-0.3.1.dist-info/entry_points.txt,sha256=AsINav6n93Jl0X-cF2nEQT2Mqj0FI-BJu2ieyUqddnE,85
40
- harnice-0.3.1.dist-info/top_level.txt,sha256=HF3Q2YiwIW9HIDhXjucyrtGy7dubDEcJUMpb5Ajb5pM,8
41
- harnice-0.3.1.dist-info/RECORD,,
36
+ harnice-0.3.2.dist-info/licenses/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
37
+ harnice-0.3.2.dist-info/METADATA,sha256=s32OUCTTvnt-fwrwMaIy07SRgUiv6i6FxFzYD6ji8EE,1072
38
+ harnice-0.3.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
39
+ harnice-0.3.2.dist-info/entry_points.txt,sha256=AsINav6n93Jl0X-cF2nEQT2Mqj0FI-BJu2ieyUqddnE,85
40
+ harnice-0.3.2.dist-info/top_level.txt,sha256=HF3Q2YiwIW9HIDhXjucyrtGy7dubDEcJUMpb5Ajb5pM,8
41
+ harnice-0.3.2.dist-info/RECORD,,