@@ -238,6 +238,7 @@ def structure(self):
238238 "value": "yum -y update && yum clean all"}
239239 ]
240240 """
241+
241242 def _rstrip_eol (text , line_continuation_char = '\\ ' ):
242243 text = text .rstrip ()
243244 if text .endswith (line_continuation_char ):
@@ -262,8 +263,8 @@ def _clean_comment_line(line):
262263 lineno = - 1
263264 line_continuation_char = '\\ '
264265 insnre = re .compile (r'^\s*(\S+)\s+(.*)$' ) # matched group is insn
265- contre = re .compile (r'^.*\\\s*$' ) # line continues?
266- commentre = re .compile (r'^\s*#' ) # line is a comment?
266+ contre = re .compile (r'^.*\\\s*$' ) # line continues?
267+ commentre = re .compile (r'^\s*#' ) # line is a comment?
267268 directive_possible = True
268269 # escape directive regex
269270 escape_directive_re = re .compile (r'^\s*#\s*escape\s*=\s*(\\|`)\s*$' , re .I )
@@ -354,7 +355,7 @@ def parent_images(self):
354355 top_args [key ] = value
355356 elif instr ['instruction' ] == 'FROM' :
356357 in_stage = True
357- image , _ = image_from (instr ['value' ])
358+ image , _ = image_name_from (instr ['value' ])
358359 if image is not None :
359360 image = WordSplitter (image , args = top_args ).dequote ()
360361 parents .append (image )
@@ -376,7 +377,7 @@ def parent_images(self, parents):
376377 if instr ['instruction' ] != 'FROM' :
377378 continue
378379
379- old_image , stage = image_from (instr ['value' ])
380+ old_image , stage = image_name_from (instr ['value' ])
380381 if old_image is None :
381382 continue # broken FROM, fixing would just confuse things
382383 if not parents :
@@ -393,7 +394,7 @@ def parent_images(self, parents):
393394
394395 lines = self .lines
395396 for instr in reversed (change_instrs ):
396- lines [instr ['startline' ]:instr ['endline' ]+ 1 ] = [instr ['content' ]]
397+ lines [instr ['startline' ]:instr ['endline' ] + 1 ] = [instr ['content' ]]
397398
398399 self .lines = lines
399400
@@ -416,7 +417,7 @@ def baseimage(self, new_image):
416417 images = []
417418 for instr in self .structure :
418419 if instr ['instruction' ] == 'FROM' :
419- image , _ = image_from (instr ['value' ])
420+ image , _ = image_name_from (instr ['value' ])
420421 if image is not None :
421422 images .append (image )
422423 if not images :
@@ -762,7 +763,7 @@ def add_lines(self, *lines, **kwargs):
762763 for stage in range (len (froms )- 2 , - 1 , - 1 ): # e.g. 0 for single or 2, 1, 0 for 3 stages
763764 start , finish = froms [stage ], froms [stage + 1 ]
764765 linenum = start ['endline' ] + 1 if at_start else finish ['startline' ]
765- image , _ = image_from (froms [stage ].get ('value' ) or '' )
766+ image , _ = image_name_from (froms [stage ].get ('value' ) or '' )
766767 if skip_scratch and image == 'scratch' :
767768 continue
768769 df_lines [linenum :linenum ] = lines
@@ -862,6 +863,16 @@ def context_structure(self):
862863
863864
864865def image_from (from_value ):
866+ """
867+ :param from_value: string like "image:tag" or "image:tag AS name"
868+ :return: tuple of the image and stage name, e.g. ("image:tag", None)
869+ """
870+ DeprecationWarning ("Use image_name_from instead." )
871+ image , name = image_name_from (from_value )
872+ return str (image ) if image else None , name
873+
874+
875+ def image_name_from (from_value ):
865876 """
866877 :param from_value: string like "image:tag" or "image:tag AS name"
867878 :return: tuple of the image and stage name, e.g. ("image:tag", None)
0 commit comments