Skip to content

Commit 1b5361f

Browse files
authored
Improve template library navigation (#145)
* Fix random order of template libraries * Fix graceful exit on user Ctrl+C * Update CHANGELOG
1 parent 53a0099 commit 1b5361f

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning][].
1515
- Exit gracefully when aborting template selections ([#134](https://github.com/Boehringer-Ingelheim/dso/pull/134)).
1616
- Make sure watermarking doesn't modify external images inplace ([#140](https://github.com/Boehringer-Ingelheim/dso/pull/140)).
1717
- Do not exclude `meta.yaml` from templates. We leave it up to the templates to .gitignore them ([#142](https://github.com/Boehringer-Ingelheim/dso/pull/142)).
18+
- Fix that template libraries appeared in random order in `dso create` ([#145](https://github.com/Boehringer-Ingelheim/dso/pull/145)).
1819

1920
### Additions
2021

src/dso/_templates.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def _get_template_libraries() -> dict[str, dict]:
2525
Paths to template libraries are obtained from `DSO_TEMPLATE_LIBRARIES` env variable.
2626
The paths can either be a python module, or a path to directory in the file system.
2727
"""
28-
lib_paths = set(os.environ.get("DSO_TEMPLATE_LIBRARIES", "dso.templates").split(":"))
28+
# as opposed to set(), this keep the order of libraries as specified in DSO_TEMPLATE_LIBRARIES
29+
lib_paths = list(dict.fromkeys(os.environ.get("DSO_TEMPLATE_LIBRARIES", "dso.templates").split(":")))
2930

3031
libraries = {}
3132
for lib_path in lib_paths:
@@ -110,7 +111,7 @@ def prompt_for_template_params(
110111
if len(libraries) == 1:
111112
library_id = next(iter(libraries))
112113
else:
113-
library_id = str(questionary.select("Choose a template library:", choices=list(libraries)).ask())
114+
library_id = questionary.select("Choose a template library:", choices=list(libraries)).ask()
114115
if library_id is None:
115116
sys.exit(1) # user aborted prompt
116117

@@ -131,10 +132,8 @@ def prompt_for_template_params(
131132
show_description=True,
132133
).ask()
133134

134-
if template_id is None:
135-
sys.exit(1)
136-
else:
137-
template_id = str(template_id)
135+
if template_id is None:
136+
sys.exit(1) # user aborted prompt
138137

139138
template = templates[template_id]
140139

@@ -143,7 +142,7 @@ def prompt_for_template_params(
143142
if name not in kwargs:
144143
res = questionary.text(p["description"]).ask()
145144
if res is None:
146-
sys.exit(1)
145+
sys.exit(1) # user aborted prompt
147146
kwargs[name] = res
148147

149148
return template, kwargs

0 commit comments

Comments
 (0)