diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2018-11-09 16:11:23 +0000 |
---|---|---|
committer | Benjamin Schubert <ben.c.schubert@gmail.com> | 2018-11-09 16:53:42 +0000 |
commit | 6f4351ec88cc4e3af2b548e9c05cdf295dd578a7 (patch) | |
tree | e5858529ebc3d05144d104a95516596128140f22 /buildstream | |
parent | 7ce6581bef58637c28d72c95adfca8feb1271d67 (diff) | |
download | buildstream-6f4351ec88cc4e3af2b548e9c05cdf295dd578a7.tar.gz |
source.py: don't let StopIteration propagate to silence() contextmanagerbschubert/fix-silence-stopiteration-pep-0479
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.
Diffstat (limited to 'buildstream')
-rw-r--r-- | buildstream/source.py | 42 |
1 files 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 # |