77import os
88import subprocess
99import sys
10+ import urllib
1011from datetime import datetime
1112
1213import shpc .defaults as defaults
@@ -236,14 +237,14 @@ def docgen(self, module_name, registry=None, out=None, branch="main"):
236237 """
237238 Render documentation for a module within a local registry.
238239 """
239- config = self ._load_container (module_name )
240+ config = self .get_module (module_name ). config
240241
241242 out = out or sys .stdout
242243 aliases = config .get_aliases ()
243244 template = self .template .load ("docs.md" )
244245 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 ( "/" )
247248 raw = (
248249 "https://gitlab.com/%s/-/raw/%s/%s/container.yaml"
249250 if "gitlab" in registry
@@ -252,24 +253,19 @@ def docgen(self, module_name, registry=None, out=None, branch="main"):
252253 raw_github_url = raw % (
253254 registry_bare ,
254255 branch ,
255- module_name ,
256+ config . name ,
256257 )
257258
258259 # Currently one doc is rendered for all containers
259260 result = template .render (
260261 parsed_name = config .name ,
262+ config = config ,
261263 settings = self .settings ,
262- description = config .description ,
263264 aliases = aliases ,
264- versions = config .tags .keys (),
265265 github_url = github_url ,
266- container_url = config .url ,
267266 config_url = raw_github_url ,
268267 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 ),
273269 )
274270 out .write (result )
275271 return out
@@ -338,50 +334,48 @@ def check(self, module_name):
338334 at updates for entire tags. If a specific folder is provided with
339335 a container, check the digest.
340336 """
341- module = self .new_module (module_name )
337+ module = self .get_module (module_name )
342338 if not os .path .exists (module .module_dir ):
343339 logger .exit (
344340 "%s does not exist. Is this a known registry entry?" % module .module_dir
345341 )
346342
347343 return module .check ()
348344
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 ):
352346 """
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.
354349 """
355350 name = self .add_namespace (name )
356351
357- # If the module has a version, overrides provided tag
358- if ":" in name :
359- name , tag = name .split (":" , 1 )
360-
361352 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 ()
367353
368354 # Pass on container and settings
369355 module .container = self .container
370356 module .settings = self .settings
371357
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+
372371 # Do we want to use a container from the local filesystem?
373372 if container_image :
374373 module .add_local_container (container_image , keep_path = keep_path )
374+
375375 return module
376376
377377 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
385379 ):
386380 """
387381 Given a unique resource identifier, install a recipe.
@@ -392,12 +386,8 @@ def install(
392386 "force" is currently not used.
393387 """
394388 # 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
401391 )
402392
403393 # We always load overrides for an install
@@ -431,16 +421,12 @@ def install(
431421 logger .info ("Module %s was created." % module .tagged_name )
432422 return module .container_path
433423
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 ):
437425 """
438426 Install a module in a view. The module must already be installed.
439427 Set "force" to True to allow overwriting existing symlinks.
440428 """
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 )
444430
445431 # A view is a symlink under views_base/$view/$module
446432 if view_name not in self .views :
0 commit comments