5
5
# You should still set up your module_base before doing this (as we need
6
6
# to write module files.
7
7
8
+ # This script also requires pipelib
9
+ # pip install pipelib
10
+
8
11
# **ALWAYS** dry run first!
9
12
# python biocontainer-match.py --dry-run
10
13
# At the root of your depot do:
22
25
import re
23
26
import sys
24
27
28
+ import pipelib .pipeline as pipeline
29
+ import pipelib .pipelines as pipelines
30
+ import pipelib .steps as step
31
+
25
32
from shpc .logger import logger
26
33
from shpc .main import get_client
27
34
from shpc .main .container import ContainerConfig
28
35
36
+ # A pipeline to process docker tags
37
+ steps = (
38
+ # Filter out those that look like commits
39
+ pipelines .git .RemoveCommits ,
40
+ # Scrub commits from version string
41
+ step .filters .CleanCommit (),
42
+ # Parse versions, return sorted ascending, and taking version major.minor.patch into account
43
+ step .container .ContainerTagSort (),
44
+ )
45
+
46
+ p = pipeline .Pipeline (steps )
47
+
29
48
30
49
def get_parser ():
31
50
parser = argparse .ArgumentParser (
@@ -51,7 +70,6 @@ def get_parser():
51
70
52
71
53
72
def main ():
54
-
55
73
parser = get_parser ()
56
74
57
75
# If an error occurs while parsing the arguments, the interpreter will exit with value 2
@@ -65,22 +83,34 @@ def main():
65
83
depot = os .path .abspath (args .containers )
66
84
cli = get_client ()
67
85
68
- # Keep a record of repos we've seen and don't repeat
69
- seen = set ()
70
-
71
86
# Ensure we start with the populated modules
72
87
cli .registry .iter_modules ()
73
88
89
+ # Organize paths based on container uri
90
+ paths = {}
91
+
74
92
# Find all paths that match the pattern of a name:tag
93
+ # Organize by tag so we can later find the newest
75
94
for path in os .listdir (depot ):
76
95
if not re .search ("^(.*):(.*)$" , path ) or os .path .isdir (path ):
77
96
continue
78
97
repo , tag = path .split (":" , 1 )
98
+ if repo not in paths :
99
+ paths [repo ] = set ()
100
+ paths [repo ].add (tag )
79
101
80
- # Don't need to parse twice
81
- if repo in seen :
102
+ # Find all paths that match the pattern of a name:tag
103
+ for repo , tags in paths .items ():
104
+ # The updated and transformed items
105
+ sorted_tags = p .run (tags , unwrap = False )
106
+ if not sorted_tags :
82
107
continue
83
108
109
+ latest = sorted_tags [0 ]
110
+ tag = latest ._original
111
+ path = f"{ repo } :{ tag } "
112
+ print (f"⭐️ Found { len (tags )} for { repo } , latest is { tag } " )
113
+
84
114
container = f"{ args .namespace } /{ repo } "
85
115
tagged = f"{ container } :{ tag } "
86
116
@@ -96,7 +126,6 @@ def main():
96
126
97
127
if args .dry_run :
98
128
print (f"Would be installing { path } to { tagged } " )
99
- seen .add (repo )
100
129
continue
101
130
102
131
# Note we need to install the correct version but using aliases
@@ -121,7 +150,6 @@ def main():
121
150
container_image = path ,
122
151
keep_path = True ,
123
152
)
124
- seen .add (repo )
125
153
126
154
127
155
if __name__ == "__main__" :
0 commit comments