shoestring-assembler 0.0.3__tar.gz → 0.0.4__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.
Files changed (37) hide show
  1. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/PKG-INFO +4 -2
  2. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/pyproject.toml +2 -1
  3. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/src/shoestring_assembler/__init__.py +1 -1
  4. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/src/shoestring_assembler/assembler.py +170 -7
  5. shoestring_assembler-0.0.4/src/shoestring_assembler/cli.py +315 -0
  6. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/src/shoestring_assembler/display.py +12 -0
  7. shoestring_assembler-0.0.4/src/shoestring_assembler/solution_picker.py +80 -0
  8. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/src/shoestring_assembler.egg-info/PKG-INFO +4 -2
  9. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/src/shoestring_assembler.egg-info/SOURCES.txt +1 -0
  10. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/src/shoestring_assembler.egg-info/requires.txt +1 -0
  11. shoestring_assembler-0.0.3/src/shoestring_assembler/cli.py +0 -123
  12. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/AUTHORS.rst +0 -0
  13. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/CONTRIBUTING.rst +0 -0
  14. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/HISTORY.rst +0 -0
  15. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/LICENSE +0 -0
  16. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/MANIFEST.in +0 -0
  17. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/README.rst +0 -0
  18. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/docs/Makefile +0 -0
  19. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/docs/authors.rst +0 -0
  20. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/docs/conf.py +0 -0
  21. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/docs/contributing.rst +0 -0
  22. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/docs/history.rst +0 -0
  23. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/docs/index.rst +0 -0
  24. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/docs/installation.rst +0 -0
  25. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/docs/make.bat +0 -0
  26. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/docs/readme.rst +0 -0
  27. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/docs/usage.rst +0 -0
  28. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/setup.cfg +0 -0
  29. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/src/shoestring_assembler/minimal_mustache.py +0 -0
  30. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/src/shoestring_assembler/schemas/meta.schema.json +0 -0
  31. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/src/shoestring_assembler/schemas/recipe.schema.json +0 -0
  32. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/src/shoestring_assembler.egg-info/dependency_links.txt +0 -0
  33. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/src/shoestring_assembler.egg-info/entry_points.txt +0 -0
  34. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/src/shoestring_assembler.egg-info/top_level.txt +0 -0
  35. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/tests/__init__.py +0 -0
  36. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/tests/console.log +0 -0
  37. {shoestring_assembler-0.0.3 → shoestring_assembler-0.0.4}/tests/test_shoestring_assembler.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: shoestring_assembler
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: Assembles Shoestring Solutions from a solution recipe
5
5
  Author-email: Greg Hawkridge <gth24@cam.ac.uk>
6
6
  Maintainer-email: Greg Hawkridge <gth24@cam.ac.uk>
@@ -23,11 +23,13 @@ Requires-Dist: typer==0.15.2
23
23
  Requires-Dist: tomli==2.2.1; python_version < "3.11"
24
24
  Requires-Dist: jsonschema[format-nongpl]==4.21.1
25
25
  Requires-Dist: pyyaml==6.0.2
26
+ Requires-Dist: textual==2.1.2
26
27
  Provides-Extra: dev
27
28
  Requires-Dist: coverage; extra == "dev"
28
29
  Requires-Dist: mypy; extra == "dev"
29
30
  Requires-Dist: pytest; extra == "dev"
30
31
  Requires-Dist: ruff; extra == "dev"
32
+ Dynamic: license-file
31
33
 
32
34
  ====================
33
35
  Shoestring Assembler
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "shoestring_assembler"
9
- version = "0.0.3"
9
+ version = "0.0.4"
10
10
  description = "Assembles Shoestring Solutions from a solution recipe"
11
11
  readme = "README.rst"
12
12
  authors = [
@@ -33,6 +33,7 @@ dependencies = [
33
33
  "tomli==2.2.1;python_version<'3.11'",
34
34
  "jsonschema[format-nongpl]==4.21.1",
35
35
  "pyyaml==6.0.2",
36
+ "textual==2.1.2"
36
37
  ]
37
38
 
38
39
  [project.optional-dependencies]
@@ -2,4 +2,4 @@
2
2
 
3
3
  __author__ = """Greg Hawkridge"""
4
4
  __email__ = 'gth24@cam.ac.uk'
5
- __version__ = '0.0.1'
5
+ __version__ = '0.0.4'
@@ -149,7 +149,9 @@ class Assembler:
149
149
  all_ok = check_dir(SOLUTION_FILES_DIR) and all_ok
150
150
  all_ok = check_dir(SOLUTION_CONFIG_DIR) and all_ok
151
151
  for source_name in source_list:
152
- all_ok = check_dir(f"{SOLUTION_CONFIG_DIR}/{source_name}") and all_ok
152
+ all_ok = (
153
+ check_or_create_dir(f"{SOLUTION_CONFIG_DIR}/{source_name}") and all_ok
154
+ )
153
155
 
154
156
  all_ok = check_or_create_dir(BASE_MODULE_FILES_DIR) and all_ok
155
157
  if check_sources:
@@ -561,14 +563,14 @@ def check_or_create_dir(rel_path):
561
563
 
562
564
  if sys.version_info[0] == 3 and sys.version_info[1] < 14:
563
565
 
564
- def do_copy(src_path, dest_path,create_dirs = False):
566
+ def do_copy(src_path, dest_path, create_dirs=False):
565
567
  import shutil
566
568
 
567
569
  shutil.copytree(src_path, dest_path, dirs_exist_ok=create_dirs)
568
570
 
569
571
  else:
570
572
 
571
- def do_copy(src_path, dest_path,create_dirs = False):
573
+ def do_copy(src_path, dest_path, create_dirs=False):
572
574
  src_path.copy_into(dest_path)
573
575
 
574
576
 
@@ -668,7 +670,7 @@ def get_version_from_file(file):
668
670
  def transfer_user_config_from_template(template_dir_path, dest_dir_path):
669
671
  template_dir = Path.resolve(Path.cwd()) / Path(template_dir_path)
670
672
  dest_dir = Path.resolve(Path.cwd()) / Path(dest_dir_path)
671
- do_copy(template_dir,dest_dir, True)
673
+ do_copy(template_dir, dest_dir, True)
672
674
  display.print_log(f"Copied user config to {dest_dir_path} from template")
673
675
 
674
676
 
@@ -783,6 +785,12 @@ def handle_git_source(name, details, console, progress: rich.progress.Progress):
783
785
  command, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, env=env
784
786
  ) # git outputs updates over stderr
785
787
 
788
+ git_clone_progress_bars(process, progress, console)
789
+
790
+ return process.returncode == 0
791
+
792
+
793
+ def git_clone_progress_bars(process, progress: rich.progress.Progress, console):
786
794
  # likely overkill but would be good to be able to relay updates
787
795
  buffer = bytearray()
788
796
  active_progress_tracker = None
@@ -812,10 +820,11 @@ def handle_git_source(name, details, console, progress: rich.progress.Progress):
812
820
  if line:
813
821
  if active_progress_tracker or line_update: # progress update line
814
822
  m = regex.match(line)
815
- if active_progress_tracker:
823
+ if active_progress_tracker is not None:
816
824
  if line_update: # update
817
825
  progress.update(
818
826
  active_progress_tracker,
827
+ description=m.group("label"),
819
828
  completed=int(m.group("progress")),
820
829
  )
821
830
  else: # end
@@ -844,16 +853,166 @@ def handle_git_source(name, details, console, progress: rich.progress.Progress):
844
853
 
845
854
  process.poll()
846
855
 
856
+
857
+
858
+ def git_fetch_current():
859
+ env = os.environ.copy()
860
+ env["GIT_TERMINAL_PROMPT"] = (
861
+ "0" # prevents hanging on username input if url invalid
862
+ )
863
+
864
+ # fetch updates
865
+ command = [
866
+ "git",
867
+ "fetch",
868
+ "--progress",
869
+ "--all",
870
+ ]
871
+ display.print_log("Fetching list of available versions...")
872
+ result = subprocess.run(command, capture_output=True, env=env)
873
+ display.print_debug(
874
+ f"git fetch return code: {result.returncode}\nstdout:\n{result.stdout.decode()}\nstderr:\n{result.stderr.decode()}"
875
+ )
876
+
877
+ if result.returncode != 0:
878
+ display.print_warning("Unable to fetch the latest list of available versions")
879
+
880
+
881
+ head_search_regex = re.compile("(?P<has_head>HEAD)")
882
+ tag_search_regex = re.compile("(?:tag:\s?(?P<tag>[\w\d\.-]*))")
883
+ strict_tag_regex = re.compile("^v\d*\.\d*\.\d*$")
884
+
885
+
886
+ def git_check_update(strict_tags_only=True, full_list=True):
887
+ env = os.environ.copy()
888
+ env["GIT_TERMINAL_PROMPT"] = (
889
+ "0" # prevents hanging on username input if url invalid
890
+ )
891
+
892
+ # check tags
893
+ command = [
894
+ "git",
895
+ "log",
896
+ "--all", # include all commits
897
+ '--format="%D"', # print list of commit refs (includes HEAD, tags and branches)
898
+ "--simplify-by-decoration", # filter out commits that have empty ref entries
899
+ ]
900
+ result = subprocess.run(command, capture_output=True, env=env)
901
+ readout = result.stdout.decode()
902
+
903
+ tag_entries = []
904
+ for line in readout.split("\n"):
905
+ has_head = head_search_regex.search(line)
906
+ tags = tag_search_regex.findall(line)
907
+
908
+ if strict_tags_only:
909
+ tags = [tag for tag in tags if strict_tag_regex.match(tag)]
910
+
911
+ if tags:
912
+ tag_entries.extend(
913
+ [
914
+ {
915
+ "has_head": has_head is not None,
916
+ "tag": tag,
917
+ }
918
+ for tag in tags
919
+ ]
920
+ )
921
+ elif has_head:
922
+ tag_entries.append(
923
+ {
924
+ "has_head": has_head is not None,
925
+ "tag": None,
926
+ }
927
+ )
928
+
929
+ display.print_debug(f"raw:\n{readout}\nextracted:\n{tag_entries}")
930
+
931
+ display.print_header("Available versions:")
932
+ first_current = None
933
+ for index, entry in enumerate(tag_entries):
934
+ is_current = entry["has_head"]
935
+ if is_current:
936
+ first_current = index
937
+ else:
938
+ if not full_list and first_current is not None:
939
+ # only show one entry prior to (current) entry
940
+ display.print_log("...")
941
+ break
942
+
943
+ tag_display = (
944
+ f'[purple]{entry["tag"]} [/purple]'
945
+ if entry["tag"]
946
+ else f"[white]none[/white]"
947
+ )
948
+
949
+ display.print_log(f'{tag_display} [green]{"(current)"if is_current else " "}')
950
+
951
+ if tag_entries[0]["has_head"]:
952
+ return False, []
953
+ else:
954
+ return True, [entry["tag"] for entry in tag_entries[0:first_current]]
955
+
956
+
957
+ def git_update(tag_or_branch):
958
+
959
+ display.print_header(f"Updating to {tag_or_branch}")
960
+
961
+ env = os.environ.copy()
962
+ env["GIT_TERMINAL_PROMPT"] = (
963
+ "0" # prevents hanging on username input if url invalid
964
+ )
965
+
966
+ command = ["git", "checkout", tag_or_branch]
967
+
968
+ display.print_debug(f"command: {command}")
969
+
970
+ process = subprocess.Popen(
971
+ command, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, env=env
972
+ ) # git outputs updates over stderr
973
+
974
+ # likely overkill but would be good to be able to relay updates
975
+ buffer = bytearray()
976
+ while process.returncode == None:
977
+ while True:
978
+ line = None
979
+
980
+ read_list, _wlist, _xlist = select.select([process.stderr], [], [], 1)
981
+ # display.print_log(read_list,console=console)
982
+ if process.stderr in read_list:
983
+ char = process.stderr.read(1)
984
+ if char == b"\n":
985
+ line = buffer.decode()
986
+ buffer.clear()
987
+ elif char:
988
+ # display.print_log(f"char: {char}", console=console)
989
+ buffer += char
990
+ else:
991
+ break # end of file
992
+ else:
993
+ break # timeout - break to check if process terminated
994
+
995
+ if line:
996
+ display.print_log(f"[white]{line}")
997
+ else:
998
+ pass
999
+
1000
+ process.poll()
1001
+
1002
+ if process.returncode == 0:
1003
+ display.print_complete("Update Complete.")
1004
+ else:
1005
+ display.print_error("Update failed.")
1006
+
847
1007
  return process.returncode == 0
848
1008
 
849
1009
 
850
1010
  """
851
1011
  TO DO List:
852
1012
  * work out what clean means
853
- * user_config templates
854
- * solution config templates & bootstrapping
855
1013
 
856
1014
  Longer term
1015
+ * solution config templates & bootstrapping
857
1016
  * host side volume specification
858
1017
  * named volumes - when only has container entry?
859
1018
  * would need warning if repeated
@@ -861,3 +1020,7 @@ Longer term
861
1020
  * coveying port and alias mappings to services
862
1021
  * external resources
863
1022
  """
1023
+
1024
+
1025
+ def fetch_solution():
1026
+ pass
@@ -0,0 +1,315 @@
1
+ """Console script for shoestring_assembler."""
2
+
3
+ import shoestring_assembler as shoestring_assembler_top
4
+ from shoestring_assembler import assembler, display
5
+
6
+ import typer
7
+ from typing_extensions import Annotated
8
+ import os
9
+ import sys
10
+
11
+ from rich.prompt import Prompt, Confirm
12
+
13
+ typer_app = typer.Typer(name="Shoestring Assembler", no_args_is_help=True)
14
+
15
+
16
+ CANCEL_PHRASE = "cancel"
17
+
18
+
19
+ @typer_app.command()
20
+ def update(
21
+ version: Annotated[
22
+ str, typer.Argument(help="Update to this version. (optional)")
23
+ ] = "",
24
+ verbose: Annotated[
25
+ bool, typer.Option("--verbose", help="Show extra logs.")
26
+ ] = False,
27
+ yes: Annotated[
28
+ bool,
29
+ typer.Option(
30
+ "--yes", "-y", help="Automatically download and assemble the latest version"
31
+ ),
32
+ ] = False,
33
+ recipe: Annotated[
34
+ str, typer.Argument(help="Path to recipe file")
35
+ ] = "./recipe.toml",
36
+ ):
37
+ """
38
+ Updates the solution to the specified version. If a version is not specified - it lists the available versions that you can choose from.
39
+ """
40
+ if verbose:
41
+ display.debug = True
42
+
43
+ display.print_top_header("Updating Solution")
44
+
45
+ assembler.git_fetch_current()
46
+
47
+ if not version:
48
+ has_update, available_versions = assembler.git_check_update()
49
+ if not has_update:
50
+ display.print_notification("Latest version installed.")
51
+ return
52
+ else:
53
+ display.print_notification("A new version is available.")
54
+ if yes:
55
+ version = available_versions[0]
56
+ elif Confirm.ask("? Do you want to update now?", default=True):
57
+ selected_version = Prompt.ask(
58
+ "? Select a version?",
59
+ choices=available_versions
60
+ + [
61
+ CANCEL_PHRASE,
62
+ ],
63
+ default=available_versions[0],
64
+ )
65
+ if selected_version != CANCEL_PHRASE:
66
+ version = selected_version
67
+
68
+ if version:
69
+ updated = assembler.git_update(version)
70
+ if updated:
71
+ if yes or Confirm.ask(
72
+ "? Do you want to assemble the solution now?", default=True
73
+ ):
74
+ try:
75
+ assemble(recipe)
76
+ return
77
+ except SystemExit:
78
+ display.print_error(
79
+ "Solution assembly failed. If you want to run it again use: [green]shoestring assemble[/green]"
80
+ )
81
+ raise
82
+ else:
83
+ display.print_log(
84
+ "If you want to update later - run: [green]shoestring update <version>[/green]"
85
+ )
86
+
87
+ display.print_top_header("Finished")
88
+
89
+
90
+ @typer_app.command()
91
+ def check_recipe(
92
+ recipe: Annotated[
93
+ str, typer.Argument(help="Path to recipe file")
94
+ ] = "./recipe.toml",
95
+ ):
96
+ display.print_top_header("Checking Recipe")
97
+ assembler_inst = assembler.Assembler(recipe)
98
+ assembler_inst.load_recipe()
99
+ display.print_top_header("Finished")
100
+
101
+
102
+ @typer_app.command()
103
+ def bootstrap(
104
+ recipe: Annotated[
105
+ str, typer.Argument(help="Path to recipe file")
106
+ ] = "./recipe.toml",
107
+ verbose: Annotated[
108
+ bool, typer.Option("--verbose", help="Show extra logs.")
109
+ ] = False,
110
+ ):
111
+ """
112
+ Uses templates to bootstrap the solution config for the specified sources
113
+ """
114
+ pass
115
+
116
+
117
+ @typer_app.command()
118
+ def assemble(
119
+ recipe: Annotated[
120
+ str, typer.Argument(help="Path to recipe file")
121
+ ] = "./recipe.toml",
122
+ download: bool = True,
123
+ verbose: Annotated[
124
+ bool, typer.Option("--verbose", help="Show extra logs.")
125
+ ] = False,
126
+ ):
127
+ """
128
+ Assembles the solution using the provided recipe
129
+ """
130
+ if verbose:
131
+ display.debug = True
132
+ display.root_console.record = True
133
+ try:
134
+ display.print_top_header("Assembling Solution")
135
+ assembler_inst = assembler.Assembler(recipe)
136
+ assembler_inst.load_recipe()
137
+ assembler_inst.clean(clean_sources=download)
138
+ assembler_inst.verify_filestructure(check_sources=not download)
139
+ assembler_inst.gather_base_service_modules(do_gather=download)
140
+ assembler_inst.check_user_config()
141
+ assembler_inst.generate_compose_file()
142
+ display.print_top_header("Finished")
143
+ display.print_next_steps("* Configure the service modules according to your needs (refer to the guide for details) \n\n* Once the solution is ready - run [white]shoestring build[/white] to build the solution")
144
+ finally:
145
+ display.root_console.save_html("./console.log")
146
+
147
+
148
+ import urllib
149
+ import yaml
150
+ from rich.prompt import Prompt
151
+ import rich.progress
152
+ import subprocess
153
+ from .solution_picker import SolutionPickerApp
154
+
155
+
156
+ # Temporary implementation - refactor once proof-of-concept complete
157
+ @typer_app.command()
158
+ def get(
159
+ verbose: Annotated[
160
+ bool, typer.Option("--verbose", help="Show extra logs.")
161
+ ] = False,
162
+ ):
163
+ """
164
+ Downloads the specified solution
165
+ """
166
+ if verbose:
167
+ display.debug = True
168
+
169
+ display.print_top_header("Get Solution")
170
+
171
+ display.print_header(f"Selecting Solution")
172
+ # fetch solution list
173
+ list_branch = os.getenv("SHOESTRING_LIST_BRANCH","main")
174
+ with urllib.request.urlopen(
175
+ f"https://github.com/DigitalShoestringSolutions/solution_list/raw/refs/heads/{list_branch}/list.yaml"
176
+ ) as web_in:
177
+ content = web_in.read()
178
+ provider_list = yaml.safe_load(content)
179
+
180
+ selected = SolutionPickerApp(provider_list).run()
181
+
182
+ if selected == None:
183
+ display.print_log("Solution selection cancelled")
184
+ else:
185
+ display.print_log(f"Selected [green]{selected['name']}[/green]")
186
+
187
+ display.print_header(f"Downloading {selected['name']}")
188
+ tag_or_branch = selected["tag"] if "tag" in selected else selected["branch"]
189
+
190
+ env = os.environ.copy()
191
+ env["GIT_TERMINAL_PROMPT"] = (
192
+ "0" # prevents hanging on username input if url invalid
193
+ )
194
+
195
+ command = [
196
+ "git",
197
+ "clone",
198
+ "--progress", # force inclusion of progress updates
199
+ "--branch",
200
+ tag_or_branch,
201
+ selected["url"],
202
+ ]
203
+
204
+ display.print_debug(f"command: {command}")
205
+
206
+ process = subprocess.Popen(
207
+ command, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, env=env
208
+ ) # git outputs updates over stderr
209
+
210
+ with rich.progress.Progress(transient=True) as progress:
211
+ assembler.git_clone_progress_bars(process, progress, progress.console)
212
+
213
+ if process.returncode == 0:
214
+ display.print_complete("Done")
215
+ else:
216
+ display.print_error("Unable to download solution")
217
+ display.print_top_header("Finished")
218
+
219
+ import select
220
+
221
+ @typer_app.command()
222
+ def build():
223
+ display.print_top_header("Starting solution")
224
+ command = ["docker", "compose", "build"]
225
+ process = subprocess.Popen(
226
+ command, stdout=None, stderr=None
227
+ )
228
+ process.wait()
229
+ if process.returncode ==0:
230
+ display.print_complete("Solution Built")
231
+ display.print_next_steps("To run the solution use [white]shoestring start[/white]")
232
+ else:
233
+ display.print_error("Solution Building Failed")
234
+ display.print_top_header("Finished")
235
+ # buffer = bytearray()
236
+ # while process.returncode == None:
237
+ # while True:
238
+ # out_line = None
239
+ # err_line = None
240
+
241
+ # read_list, _wlist, _xlist = select.select([process.stderr,process.stdout], [], [], 1)
242
+ # # display.print_log(read_list,console=console)
243
+ # if process.stderr in read_list:
244
+ # char = process.stderr.read(1)
245
+ # if char == b"\n":
246
+ # err_line = buffer.decode()
247
+ # buffer.clear()
248
+ # elif char:
249
+ # # display.print_log(f"char: {char}", console=console)
250
+ # buffer += char
251
+ # else:
252
+ # break # end of file
253
+ # if process.stdout in read_list:
254
+ # char = process.stdout.read(1)
255
+ # if char == b"\n":
256
+ # out_line = buffer.decode()
257
+ # buffer.clear()
258
+ # elif char:
259
+ # # display.print_log(f"char: {char}", console=console)
260
+ # buffer += char
261
+ # else:
262
+ # break # end of file
263
+ # else:
264
+ # break # timeout - break to check if process terminated
265
+
266
+ # if out_line:
267
+ # display.print_log(f"[white]{out_line}")
268
+ # if err_line:
269
+ # display.print_error(f"{err_line}")
270
+
271
+ # process.poll()
272
+
273
+ @typer_app.command()
274
+ def start():
275
+ display.print_top_header("Starting solution")
276
+ command = ["docker", "compose", "up", "-d", "--remove-orphans"]
277
+ process = subprocess.Popen(command, stdout=None, stderr=None)
278
+ process.wait()
279
+
280
+ if process.returncode ==0:
281
+ display.print_complete("Solution is now running in the background")
282
+ display.print_top_header("Finished")
283
+
284
+
285
+ @typer_app.callback(invoke_without_command=True)
286
+ def main(
287
+ version: Annotated[
288
+ bool, typer.Option("--version", "-v", help="Assembler version")
289
+ ] = False,
290
+ ):
291
+ if version:
292
+ display.print_log(
293
+ f"Shoestring Assembler version {shoestring_assembler_top.__version__}"
294
+ )
295
+ else:
296
+ pass
297
+
298
+
299
+ def app():
300
+ if os.geteuid() == 0:
301
+ display.print_error(
302
+ "To try prevent you from accidentally breaking things, this program won't run with sudo or as root! \nRun it again without sudo or change to a non-root user."
303
+ )
304
+ sys.exit(255)
305
+ typer_app()
306
+
307
+
308
+ if __name__ == "__main__":
309
+ app()
310
+
311
+
312
+ """
313
+ * shoestring
314
+ * bootstrap (maybe for a separate developer focussed tool?)
315
+ """
@@ -1,5 +1,6 @@
1
1
  from rich.console import Console
2
2
  from rich.panel import Panel
3
+
3
4
  import rich.progress
4
5
 
5
6
  root_console = Console()
@@ -45,6 +46,17 @@ def print_notification(text,console=None):
45
46
  style="bright_cyan",
46
47
  )
47
48
  )
49
+
50
+ def print_next_steps(text,console=None):
51
+ console = _get_console(console)
52
+ console.print(
53
+ Panel(
54
+ f"[bold bright_cyan]{text}[/bold bright_cyan]",
55
+ title="[bold bright_cyan]:footprints: Next Steps",
56
+ title_align="left",
57
+ style="bright_cyan",
58
+ )
59
+ )
48
60
 
49
61
  def print_warning(text, console=None):
50
62
  console = _get_console(console)
@@ -0,0 +1,80 @@
1
+ from textual.app import App, ComposeResult
2
+ from textual.widgets import Footer, Header, OptionList, Label, Markdown
3
+ from textual.widgets.option_list import Option
4
+ from textual import on
5
+
6
+ import urllib.request
7
+ import yaml
8
+
9
+ INSTRUCTIONS_MULTI_PROVIDER = """
10
+ ### Select which solution you want to download.
11
+ Use the `up` and `down` arrows to move up and down each provider's list.
12
+
13
+ Use `tab` and `shift + tab` to move between providers.
14
+
15
+ Use `Enter` to select the solution you want.
16
+
17
+ Press `q` to exit.
18
+ """
19
+
20
+ INSTRUCTIONS_SINGLE_PROVIDER = """
21
+ ### Select which solution you want to download.
22
+ Use the `up` and `down` arrows to move up and down the list.
23
+
24
+ Use `Enter` to select the solution you want.
25
+
26
+ Press `q` to exit.
27
+ """
28
+
29
+
30
+ class SolutionList(OptionList):
31
+ def __init__(self, *content, provider=None, solution_list={}, **kwargs):
32
+ super().__init__(*content, **kwargs)
33
+ self.solution_list = solution_list
34
+ self.provider = provider
35
+
36
+ def on_mount(self):
37
+ for index, solution in enumerate(self.solution_list):
38
+ self.add_option(Option(solution["name"], id=f"{self.provider}@{index}"))
39
+ return super().on_mount()
40
+
41
+
42
+ class SolutionPickerApp(App):
43
+
44
+ def __init__(self, provider_list, **kwargs):
45
+ super().__init__(**kwargs)
46
+ self.provider_list = provider_list
47
+
48
+ BINDINGS = [("q", "exit", "Exit")]
49
+
50
+ def compose(self) -> ComposeResult:
51
+ """Create child widgets for the app."""
52
+ yield Header()
53
+ yield Markdown(INSTRUCTIONS_MULTI_PROVIDER if len(self.provider_list["providers"]) > 1 else INSTRUCTIONS_SINGLE_PROVIDER)
54
+ for tag, values in self.provider_list["providers"].items():
55
+ yield Label(values["name"])
56
+ yield SolutionList(provider=tag, solution_list=values["solutions"])
57
+
58
+ def on_mount(self):
59
+ self.title = "Select a Shoestring Solution"
60
+
61
+ def action_exit(self) -> None:
62
+ self.exit()
63
+
64
+ @on(OptionList.OptionSelected)
65
+ def handle_selected(self, event):
66
+ id = event.option.id
67
+ provider, index = id.split("@")
68
+ result = self.provider_list["providers"][provider]["solutions"][int(index)]
69
+ self.exit(result)
70
+
71
+
72
+ if __name__ == "__main__":
73
+ # fetch solution list
74
+ with urllib.request.urlopen(
75
+ "https://github.com/DigitalShoestringSolutions/solution_list/raw/refs/heads/main/list.yaml"
76
+ ) as web_in:
77
+ content = web_in.read()
78
+ provider_list = yaml.safe_load(content)
79
+ result = SolutionPickerApp(provider_list).run()
80
+ print(result)
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: shoestring_assembler
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: Assembles Shoestring Solutions from a solution recipe
5
5
  Author-email: Greg Hawkridge <gth24@cam.ac.uk>
6
6
  Maintainer-email: Greg Hawkridge <gth24@cam.ac.uk>
@@ -23,11 +23,13 @@ Requires-Dist: typer==0.15.2
23
23
  Requires-Dist: tomli==2.2.1; python_version < "3.11"
24
24
  Requires-Dist: jsonschema[format-nongpl]==4.21.1
25
25
  Requires-Dist: pyyaml==6.0.2
26
+ Requires-Dist: textual==2.1.2
26
27
  Provides-Extra: dev
27
28
  Requires-Dist: coverage; extra == "dev"
28
29
  Requires-Dist: mypy; extra == "dev"
29
30
  Requires-Dist: pytest; extra == "dev"
30
31
  Requires-Dist: ruff; extra == "dev"
32
+ Dynamic: license-file
31
33
 
32
34
  ====================
33
35
  Shoestring Assembler
@@ -20,6 +20,7 @@ src/shoestring_assembler/assembler.py
20
20
  src/shoestring_assembler/cli.py
21
21
  src/shoestring_assembler/display.py
22
22
  src/shoestring_assembler/minimal_mustache.py
23
+ src/shoestring_assembler/solution_picker.py
23
24
  src/shoestring_assembler.egg-info/PKG-INFO
24
25
  src/shoestring_assembler.egg-info/SOURCES.txt
25
26
  src/shoestring_assembler.egg-info/dependency_links.txt
@@ -1,6 +1,7 @@
1
1
  typer==0.15.2
2
2
  jsonschema[format-nongpl]==4.21.1
3
3
  pyyaml==6.0.2
4
+ textual==2.1.2
4
5
 
5
6
  [:python_version < "3.11"]
6
7
  tomli==2.2.1
@@ -1,123 +0,0 @@
1
- """Console script for shoestring_assembler."""
2
-
3
- from shoestring_assembler import assembler, display
4
-
5
- import typer
6
- from typing_extensions import Annotated
7
- import time
8
- import os
9
- import sys
10
-
11
- from rich.live import Live
12
- from rich.table import Table
13
-
14
- __version__ = "0.0.3"
15
-
16
- typer_app = typer.Typer(name="Shoestring Assembler", no_args_is_help=True)
17
-
18
-
19
- cwd = os.getcwd()
20
-
21
-
22
- @typer_app.command()
23
- def update(recipe: str = "./recipe.toml"):
24
- display.print_log(
25
- "For help - go to [link=https://community.digitalshoestring.net]the Shoestring Community[/link]!"
26
- )
27
-
28
-
29
- @typer_app.command(help="Fetch all base service modules")
30
- def pull(recipe: str = "./recipe.toml"):
31
- with Live(console=display.root_console, transient=True) as live:
32
- live.console.print("[bold blue]Starting work!")
33
- time.sleep(1)
34
- live.console.print("1")
35
- time.sleep(1)
36
- live.console.print("2")
37
- time.sleep(1)
38
- live.console.print("3")
39
-
40
-
41
- @typer_app.command()
42
- def check_recipe(
43
- recipe: str = "./recipe.toml",
44
- ):
45
- display.print_top_header("Checking Recipe")
46
- assembler_inst = assembler.Assembler(recipe)
47
- assembler_inst.load_recipe()
48
- display.print_top_header("Finished")
49
-
50
-
51
- @typer_app.command()
52
- def bootstrap(
53
- recipe: str = "./recipe.toml",
54
- verbose: Annotated[
55
- bool, typer.Option("--verbose", help="enable verbose output")
56
- ] = False,
57
- ):
58
- """
59
- Uses templates to bootstrap the solution config for the specified sources
60
- """
61
- pass
62
-
63
-
64
- @typer_app.command()
65
- def assemble(
66
- recipe: str = "./recipe.toml",
67
- download: bool = True,
68
- verbose: Annotated[
69
- bool, typer.Option("--verbose", help="enable verbose output")
70
- ] = False,
71
- ):
72
- """
73
- Assembles the solution using the provided recipe
74
- """
75
- if verbose:
76
- display.debug = True
77
- display.root_console.record = True
78
- try:
79
- display.print_top_header("Assembling Solution")
80
- assembler_inst = assembler.Assembler(recipe)
81
- assembler_inst.load_recipe()
82
- assembler_inst.clean(clean_sources=download)
83
- assembler_inst.verify_filestructure(check_sources=not download)
84
- assembler_inst.gather_base_service_modules(do_gather=download)
85
- assembler_inst.check_user_config()
86
- assembler_inst.generate_compose_file()
87
- display.print_top_header("Finished")
88
- finally:
89
- display.root_console.save_html("./console.log")
90
-
91
-
92
- @typer_app.callback(invoke_without_command=True)
93
- def main(
94
- version: Annotated[
95
- bool, typer.Option("--version", "-v", help="Assembler version")
96
- ] = False,
97
- ):
98
- if version:
99
- display.print_log(f"Shoestring Assembler version {__version__}")
100
- else:
101
- pass
102
-
103
-
104
- def app():
105
- if os.geteuid() == 0:
106
- display.print_error(
107
- "To try prevent you from breaking things, this program won't run with sudo or as root! \nRun it again without sudo or change to a non-root user."
108
- )
109
- sys.exit(255)
110
- typer_app()
111
-
112
-
113
- if __name__ == "__main__":
114
- app()
115
-
116
-
117
- """
118
- * shoestring
119
- * assemble
120
- * check-recipe
121
- * install_docker
122
- * check_docker
123
- """