robotframework-libtoc 1.6.0__tar.gz → 1.7.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: robotframework-libtoc
3
- Version: 1.6.0
3
+ Version: 1.7.0
4
4
  Summary: Docs and TOC generator for Robot Framework resources and libs
5
5
  Home-page: https://github.com/amochin/robotframework-libtoc
6
6
  License: Apache-2.0
@@ -40,7 +40,7 @@ in the intranet or uploaded as CI artifact - so everybody can easily access the
40
40
  - It looks for the **config files** named `.libtoc` which contain items you would like to create docs for:
41
41
  1. Paths to resource/lib files in [glob format](https://en.wikipedia.org/wiki/Glob_(programming))
42
42
  2. RF libraries, installed or available in PYTHONPATH using the provided fully qualified name
43
- > Librariy import params (if necessary) like described in [libdoc user guide](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#general-usage)
43
+ > Library import params (if necessary) like described in [libdoc user guide](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#general-usage)
44
44
  > Other libdoc CLI options (e.g. version or name of the output file) are not supported
45
45
  3. Paths to resource/lib files in [glob format](https://en.wikipedia.org/wiki/Glob_(programming)) inside Python packages, loaded from the PYTHONPATH
46
46
  > See more about bundling RF resources in Python packages in [RF User Guide](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#taking-resource-files-into-use)
@@ -90,6 +90,7 @@ pip install robotframework-libtoc
90
90
  - `--toc_template`
91
91
  - `--homepage_template`
92
92
  - `--no_timestamp`
93
+ - `--tree-label`
93
94
 
94
95
  Examples:
95
96
  ```shell
@@ -98,6 +99,7 @@ pip install robotframework-libtoc
98
99
  libtoc --output_dir docs example_resources
99
100
  libtoc --output_dir docs --toc_file MY_SPECIAL_NAME_FOR_DOCS.html example_resources
100
101
  libtoc --toc_template MY_CUSTOM_TOC.html --homepage_template MY_CUSTOM_HOMEPAGE.html example_resources
102
+ libtoc --tree-label "my_folder=My Display Name" --tree-label "my_lib=My Lib Label" example_resources
101
103
  ```
102
104
 
103
105
  - Open the created file, e.g. `docs/keyword_docs.html`
@@ -112,3 +114,14 @@ There are two ways to extend the list of paths where the libraries are searched
112
114
  2. Set the **PYTHONPATH** environment variable
113
115
 
114
116
  See more in [Robot Framework User Guide](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pythonpath).
117
+
118
+ ## How to customize TOC tree item labels
119
+ By default the TOC navigation tree uses the original folder, file and library names.
120
+ Use `--tree-label KEY=VALUE` to replace any folder, library or file name (without extension) with a custom display label — without affecting the actual file paths.
121
+
122
+ The option can be repeated any number of times:
123
+ ```shell
124
+ libtoc --tree-label "sut_x=SUT X (Production)" --tree-label "common=Common Keywords" example_resources
125
+ ```
126
+ > - Only the visible label in the tree is changed. Folder structure and file paths remain untouched.
127
+ > - If the item name is found multiple times in the TOC, all occurrences would be replaced.
@@ -20,7 +20,7 @@ in the intranet or uploaded as CI artifact - so everybody can easily access the
20
20
  - It looks for the **config files** named `.libtoc` which contain items you would like to create docs for:
21
21
  1. Paths to resource/lib files in [glob format](https://en.wikipedia.org/wiki/Glob_(programming))
22
22
  2. RF libraries, installed or available in PYTHONPATH using the provided fully qualified name
23
- > Librariy import params (if necessary) like described in [libdoc user guide](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#general-usage)
23
+ > Library import params (if necessary) like described in [libdoc user guide](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#general-usage)
24
24
  > Other libdoc CLI options (e.g. version or name of the output file) are not supported
25
25
  3. Paths to resource/lib files in [glob format](https://en.wikipedia.org/wiki/Glob_(programming)) inside Python packages, loaded from the PYTHONPATH
26
26
  > See more about bundling RF resources in Python packages in [RF User Guide](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#taking-resource-files-into-use)
@@ -70,6 +70,7 @@ pip install robotframework-libtoc
70
70
  - `--toc_template`
71
71
  - `--homepage_template`
72
72
  - `--no_timestamp`
73
+ - `--tree-label`
73
74
 
74
75
  Examples:
75
76
  ```shell
@@ -78,6 +79,7 @@ pip install robotframework-libtoc
78
79
  libtoc --output_dir docs example_resources
79
80
  libtoc --output_dir docs --toc_file MY_SPECIAL_NAME_FOR_DOCS.html example_resources
80
81
  libtoc --toc_template MY_CUSTOM_TOC.html --homepage_template MY_CUSTOM_HOMEPAGE.html example_resources
82
+ libtoc --tree-label "my_folder=My Display Name" --tree-label "my_lib=My Lib Label" example_resources
81
83
  ```
82
84
 
83
85
  - Open the created file, e.g. `docs/keyword_docs.html`
@@ -91,4 +93,15 @@ There are two ways to extend the list of paths where the libraries are searched
91
93
  1. Using the `--pythonpath` option
92
94
  2. Set the **PYTHONPATH** environment variable
93
95
 
94
- See more in [Robot Framework User Guide](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pythonpath).
96
+ See more in [Robot Framework User Guide](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pythonpath).
97
+
98
+ ## How to customize TOC tree item labels
99
+ By default the TOC navigation tree uses the original folder, file and library names.
100
+ Use `--tree-label KEY=VALUE` to replace any folder, library or file name (without extension) with a custom display label — without affecting the actual file paths.
101
+
102
+ The option can be repeated any number of times:
103
+ ```shell
104
+ libtoc --tree-label "sut_x=SUT X (Production)" --tree-label "common=Common Keywords" example_resources
105
+ ```
106
+ > - Only the visible label in the tree is changed. Folder structure and file paths remain untouched.
107
+ > - If the item name is found multiple times in the TOC, all occurrences would be replaced.
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "robotframework-libtoc"
3
- version = "1.6.0"
3
+ version = "1.7.0"
4
4
  description = "Docs and TOC generator for Robot Framework resources and libs"
5
5
  authors = ["Andre Mochinin"]
6
6
  license = "Apache-2.0"
@@ -238,18 +238,30 @@ def inject_libtoc_script(src_dir, homepage_file):
238
238
  f.write(content)
239
239
 
240
240
 
241
- def add_files_from_folder(folder, base_dir_path, root=True):
241
+ def add_files_from_folder(folder, base_dir_path, root=True, folder_and_file_labels=None):
242
242
  """
243
243
  Creates a HTML source code with links to all HTML files in the `folder` and all it's subfolders.
244
244
  The links contain file paths relative to the `base_dir_path`.
245
245
 
246
246
  The `root` parameter is needed for internal usage only - it's set to False during deeper recursive calls.
247
247
  """
248
+
249
+ def get_label_for_file_or_folder(item_name, labels):
250
+ if item_name in labels:
251
+ item_display_name = labels[item_name]
252
+ print(f">> Modified label of tree item: '{item_name}' -> '{item_display_name}'")
253
+ else:
254
+ item_display_name = item_name
255
+ return item_display_name
256
+
257
+ if folder_and_file_labels is None:
258
+ folder_and_file_labels = {}
248
259
  result_str = ""
249
260
  if not root: # means we're in the root - no collapsible need in this case
261
+ folder_display_name = get_label_for_file_or_folder(os.path.basename(folder), folder_and_file_labels)
250
262
  result_str += """<button class="collapsible">{}</button>
251
263
  """.format(
252
- os.path.basename(folder)
264
+ folder_display_name
253
265
  )
254
266
 
255
267
  result_str += """<div class="collapsible_content">
@@ -259,14 +271,15 @@ def add_files_from_folder(folder, base_dir_path, root=True):
259
271
  item_path = os.path.abspath(os.path.join(folder, item))
260
272
  if item.endswith(".html"):
261
273
  name_without_ext = os.path.splitext(item)[0]
274
+ display_name = get_label_for_file_or_folder(name_without_ext, folder_and_file_labels)
262
275
  result_str += """<a class="link_not_selected" href="{}" target="targetFrame">{}</a>
263
276
  """.format(
264
- os.path.relpath(item_path, base_dir_path), name_without_ext
277
+ os.path.relpath(item_path, base_dir_path), display_name
265
278
  )
266
279
  else:
267
280
  if os.path.isdir(item_path):
268
281
  result_str += add_files_from_folder(
269
- item_path, base_dir_path, root=False
282
+ item_path, base_dir_path, root=False, folder_and_file_labels=folder_and_file_labels
270
283
  )
271
284
 
272
285
  if not root:
@@ -379,6 +392,7 @@ def create_toc(
379
392
  toc_template="",
380
393
  homepage_template="",
381
394
  no_timestamp=False,
395
+ folder_labels=None,
382
396
  ):
383
397
  """
384
398
  Generates a `toc_file` (Table of Contents) HTML page with links to all HTML files inside the `html_docs_dir` and all it's subfolders.
@@ -403,7 +417,7 @@ def create_toc(
403
417
  # create homepage in "src"
404
418
  homepage_path = os.path.join(src_subdir, homepage_file)
405
419
  current_date_time = "" if no_timestamp else datetime.now().strftime("%d.%m.%Y %H:%M:%S")
406
- doc_files_links = add_files_from_folder(src_subdir, os.path.abspath(html_docs_dir))
420
+ doc_files_links = add_files_from_folder(src_subdir, os.path.abspath(html_docs_dir), folder_and_file_labels=folder_labels)
407
421
  with open(homepage_path, "w", encoding="utf8") as f:
408
422
  f.write(homepage(homepage_template))
409
423
 
@@ -472,12 +486,26 @@ def main():
472
486
  default="",
473
487
  help="Additional locations where to search for libraries and resources similarly as when running tests",
474
488
  )
489
+ parser.add_argument(
490
+ "--tree-label",
491
+ dest="folder_labels",
492
+ action="append",
493
+ metavar="KEY=VALUE",
494
+ default=[],
495
+ help="Replace folder, file or lib name KEY with VALUE in the TOC tree. Can be specified multiple times, e.g. --tree-label 'SUT X=My Project'",
496
+ )
475
497
 
476
498
  args = parser.parse_args()
477
499
 
478
500
  if args.pythonpath:
479
501
  sys.path.insert(0, args.pythonpath)
480
502
 
503
+ folder_labels = {}
504
+ for kv in args.folder_labels:
505
+ if "=" in kv:
506
+ key, _, value = kv.partition("=")
507
+ folder_labels[key] = value
508
+
481
509
  if os.path.isdir(args.output_dir):
482
510
  print(f"Output dir already exists, deleting it: {args.output_dir}")
483
511
  shutil.rmtree(args.output_dir)
@@ -550,6 +578,7 @@ def main():
550
578
  toc_template=args.toc_template,
551
579
  homepage_template=args.homepage_template,
552
580
  no_timestamp=args.no_timestamp,
581
+ folder_labels=folder_labels,
553
582
  )
554
583
  else:
555
584
  print("No docs were created!")