7
7
import os
8
8
import subprocess
9
9
import sys
10
+ import urllib
10
11
from datetime import datetime
11
12
12
13
import shpc .defaults as defaults
@@ -236,14 +237,14 @@ def docgen(self, module_name, registry=None, out=None, branch="main"):
236
237
"""
237
238
Render documentation for a module within a local registry.
238
239
"""
239
- config = self ._load_container (module_name )
240
+ config = self .get_module (module_name ). config
240
241
241
242
out = out or sys .stdout
242
243
aliases = config .get_aliases ()
243
244
template = self .template .load ("docs.md" )
244
245
registry = registry or defaults .github_url
245
- github_url = "%s/blob/%s/%s/container.yaml" % (registry , branch , module_name )
246
- registry_bare = registry . split ( ".com" )[ - 1 ]
246
+ github_url = "%s/blob/%s/%s/container.yaml" % (registry , branch , config . name )
247
+ registry_bare = urllib . parse . urlparse ( registry ). path . lstrip ( "/" )
247
248
raw = (
248
249
"https://gitlab.com/%s/-/raw/%s/%s/container.yaml"
249
250
if "gitlab" in registry
@@ -252,24 +253,19 @@ def docgen(self, module_name, registry=None, out=None, branch="main"):
252
253
raw_github_url = raw % (
253
254
registry_bare ,
254
255
branch ,
255
- module_name ,
256
+ config . name ,
256
257
)
257
258
258
259
# Currently one doc is rendered for all containers
259
260
result = template .render (
260
261
parsed_name = config .name ,
262
+ config = config ,
261
263
settings = self .settings ,
262
- description = config .description ,
263
264
aliases = aliases ,
264
- versions = config .tags .keys (),
265
265
github_url = github_url ,
266
- container_url = config .url ,
267
266
config_url = raw_github_url ,
268
267
creation_date = datetime .now (),
269
- name = module_name ,
270
- latest = config .latest .name ,
271
- flatname = module_name .replace (os .sep , "-" ),
272
- config = json .dumps (config .entry ._config ),
268
+ config_json = json .dumps (config .entry ._config ),
273
269
)
274
270
out .write (result )
275
271
return out
@@ -338,50 +334,48 @@ def check(self, module_name):
338
334
at updates for entire tags. If a specific folder is provided with
339
335
a container, check the digest.
340
336
"""
341
- module = self .new_module (module_name )
337
+ module = self .get_module (module_name )
342
338
if not os .path .exists (module .module_dir ):
343
339
logger .exit (
344
340
"%s does not exist. Is this a known registry entry?" % module .module_dir
345
341
)
346
342
347
343
return module .check ()
348
344
349
- def new_module (
350
- self , name , tag = None , tag_exists = True , container_image = None , keep_path = False
351
- ):
345
+ def new_module (self , name ):
352
346
"""
353
- Create a new module
347
+ Create a new Module just from a name, which doesn't have to exist in the registry.
348
+ The name may have a tag appended with a colon.
354
349
"""
355
350
name = self .add_namespace (name )
356
351
357
- # If the module has a version, overrides provided tag
358
- if ":" in name :
359
- name , tag = name .split (":" , 1 )
360
-
361
352
module = Module (name )
362
- module .config = self ._load_container (module .name , tag )
363
-
364
- # Ensure the tag exists, if required, uses config.tag
365
- if tag_exists :
366
- module .validate_tag_exists ()
367
353
368
354
# Pass on container and settings
369
355
module .container = self .container
370
356
module .settings = self .settings
371
357
358
+ return module
359
+
360
+ def get_module (self , name , container_image = None , keep_path = False ):
361
+ """
362
+ Create a new Module from an existing registry entry, given its name.
363
+ The name may have a tag appended with a colon.
364
+ """
365
+ module = self .new_module (name )
366
+
367
+ config = self ._load_container (module .name )
368
+ # Ensure the tag exists, if required, uses config.tag
369
+ module .load_config (config , module .name )
370
+
372
371
# Do we want to use a container from the local filesystem?
373
372
if container_image :
374
373
module .add_local_container (container_image , keep_path = keep_path )
374
+
375
375
return module
376
376
377
377
def install (
378
- self ,
379
- name ,
380
- tag = None ,
381
- force = False ,
382
- container_image = None ,
383
- keep_path = False ,
384
- ** kwargs
378
+ self , name , force = False , container_image = None , keep_path = False , ** kwargs
385
379
):
386
380
"""
387
381
Given a unique resource identifier, install a recipe.
@@ -392,12 +386,8 @@ def install(
392
386
"force" is currently not used.
393
387
"""
394
388
# Create a new module
395
- module = self .new_module (
396
- name ,
397
- tag = tag ,
398
- tag_exists = True ,
399
- container_image = container_image ,
400
- keep_path = keep_path ,
389
+ module = self .get_module (
390
+ name , container_image = container_image , keep_path = keep_path
401
391
)
402
392
403
393
# We always load overrides for an install
@@ -431,16 +421,12 @@ def install(
431
421
logger .info ("Module %s was created." % module .tagged_name )
432
422
return module .container_path
433
423
434
- def view_install (
435
- self , view_name , name , tag = None , force = False , container_image = None
436
- ):
424
+ def view_install (self , view_name , name , force = False , container_image = None ):
437
425
"""
438
426
Install a module in a view. The module must already be installed.
439
427
Set "force" to True to allow overwriting existing symlinks.
440
428
"""
441
- module = self .new_module (
442
- name , tag = tag , tag_exists = True , container_image = container_image
443
- )
429
+ module = self .get_module (name , container_image = container_image )
444
430
445
431
# A view is a symlink under views_base/$view/$module
446
432
if view_name not in self .views :
0 commit comments