From 6f4351ec88cc4e3af2b548e9c05cdf295dd578a7 Mon Sep 17 00:00:00 2001 From: Benjamin Schubert Date: Fri, 9 Nov 2018 16:11:23 +0000 Subject: source.py: don't let StopIteration propagate to silence() contextmanager As per PEP 0479 (https://www.python.org/dev/peps/pep-0479/), StopIteration thrown in context managers are not valid starting from Python 3.7. --- buildstream/source.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/buildstream/source.py b/buildstream/source.py index af0ba0d96..f346fdf83 100644 --- a/buildstream/source.py +++ b/buildstream/source.py @@ -973,32 +973,34 @@ class Source(Plugin): # the items of source_fetchers, if it happens to be a generator. # source_fetchers = iter(source_fetchers) - try: - while True: + while True: - with context.silence(): + with context.silence(): + try: fetcher = next(source_fetchers) - - alias = fetcher._get_alias() - for uri in project.get_alias_uris(alias, first_pass=self.__first_pass): - try: - fetcher.fetch(uri) - # FIXME: Need to consider temporary vs. permanent failures, - # and how this works with retries. - except BstError as e: - last_error = e - continue - - # No error, we're done with this fetcher + except StopIteration: + # as per PEP479, we are not allowed to let StopIteration + # thrown from a context manager. + # Catching it here and breaking instead. break - else: - # No break occurred, raise the last detected error - raise last_error + alias = fetcher._get_alias() + for uri in project.get_alias_uris(alias, first_pass=self.__first_pass): + try: + fetcher.fetch(uri) + # FIXME: Need to consider temporary vs. permanent failures, + # and how this works with retries. + except BstError as e: + last_error = e + continue - except StopIteration: - pass + # No error, we're done with this fetcher + break + + else: + # No break occurred, raise the last detected error + raise last_error # Default codepath is to reinstantiate the Source # -- cgit v1.2.1