1111import logging
1212import os
1313import re
14+ import warnings
1415from contextlib import contextmanager
1516from shlex import quote
1617
@@ -238,6 +239,7 @@ def structure(self):
238239 "value": "yum -y update && yum clean all"}
239240 ]
240241 """
242+
241243 def _rstrip_eol (text , line_continuation_char = '\\ ' ):
242244 text = text .rstrip ()
243245 if text .endswith (line_continuation_char ):
@@ -262,8 +264,8 @@ def _clean_comment_line(line):
262264 lineno = - 1
263265 line_continuation_char = '\\ '
264266 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?
267+ contre = re .compile (r'^.*\\\s*$' ) # line continues?
268+ commentre = re .compile (r'^\s*#' ) # line is a comment?
267269 directive_possible = True
268270 # escape directive regex
269271 escape_directive_re = re .compile (r'^\s*#\s*escape\s*=\s*(\\|`)\s*$' , re .I )
@@ -354,7 +356,7 @@ def parent_images(self):
354356 top_args [key ] = value
355357 elif instr ['instruction' ] == 'FROM' :
356358 in_stage = True
357- image , _ = image_from (instr ['value' ])
359+ image , _ = image_name_from (instr ['value' ])
358360 if image is not None :
359361 image = WordSplitter (image , args = top_args ).dequote ()
360362 parents .append (image )
@@ -376,7 +378,7 @@ def parent_images(self, parents):
376378 if instr ['instruction' ] != 'FROM' :
377379 continue
378380
379- old_image , stage = image_from (instr ['value' ])
381+ old_image , stage = image_name_from (instr ['value' ])
380382 if old_image is None :
381383 continue # broken FROM, fixing would just confuse things
382384 if not parents :
@@ -393,7 +395,7 @@ def parent_images(self, parents):
393395
394396 lines = self .lines
395397 for instr in reversed (change_instrs ):
396- lines [instr ['startline' ]:instr ['endline' ]+ 1 ] = [instr ['content' ]]
398+ lines [instr ['startline' ]:instr ['endline' ] + 1 ] = [instr ['content' ]]
397399
398400 self .lines = lines
399401
@@ -416,7 +418,7 @@ def baseimage(self, new_image):
416418 images = []
417419 for instr in self .structure :
418420 if instr ['instruction' ] == 'FROM' :
419- image , _ = image_from (instr ['value' ])
421+ image , _ = image_name_from (instr ['value' ])
420422 if image is not None :
421423 images .append (image )
422424 if not images :
@@ -762,7 +764,7 @@ def add_lines(self, *lines, **kwargs):
762764 for stage in range (len (froms )- 2 , - 1 , - 1 ): # e.g. 0 for single or 2, 1, 0 for 3 stages
763765 start , finish = froms [stage ], froms [stage + 1 ]
764766 linenum = start ['endline' ] + 1 if at_start else finish ['startline' ]
765- image , _ = image_from (froms [stage ].get ('value' ) or '' )
767+ image , _ = image_name_from (froms [stage ].get ('value' ) or '' )
766768 if skip_scratch and image == 'scratch' :
767769 continue
768770 df_lines [linenum :linenum ] = lines
@@ -862,6 +864,16 @@ def context_structure(self):
862864
863865
864866def image_from (from_value ):
867+ """
868+ :param from_value: string like "image:tag" or "image:tag AS name"
869+ :return: tuple of the image and stage name, e.g. ("image:tag", None)
870+ """
871+ warnings .warn ("Use image_name_from instead." , DeprecationWarning )
872+ image , name = image_name_from (from_value )
873+ return str (image ) if image else None , name
874+
875+
876+ def image_name_from (from_value ):
865877 """
866878 :param from_value: string like "image:tag" or "image:tag AS name"
867879 :return: tuple of the image and stage name, e.g. ("image:tag", None)
0 commit comments