diff --git a/ci/util.py b/ci/util.py index 22331dfdd..fc3a5e671 100644 --- a/ci/util.py +++ b/ci/util.py @@ -10,7 +10,6 @@ import logging import os import pathlib -import shutil import string import sys import typing @@ -166,10 +165,6 @@ def _quiet(): return ctx().args and ctx().args.quiet -def _verbose(): - return ctx().args and ctx().args.verbose - - def _print(msg, colour, outfh=sys.stdout): if not msg: return @@ -212,14 +207,6 @@ def warning(msg:str): _print('WARNING: ' + str(msg), colour='yellow', outfh=sys.stderr) -@deprecated.deprecated -def verbose(msg:str): - if not _verbose(): - return - if msg: - _print('VERBOSE: ' + msg, colour=None, outfh=sys.stdout) - - @deprecated.deprecated def success(msg:str): if msg: @@ -427,21 +414,6 @@ def urlparse(url: str) -> urllib.parse.ParseResult: return urllib.parse.urlparse(url) -def file_extension_join(path: str, extension: str) -> str: - return '.'.join((path, extension)) - - -def which(cmd_name: str) -> str: - ''' - wrapper around shutil.which that calls ci.util.fail if the requested executable is not - found in the PATH. - ''' - cmd_path = shutil.which(cmd_name) - if not cmd_path: - fail("{cmd} not found in PATH".format(cmd=cmd_name)) - return cmd_path - - def merge_dicts(base: dict, *other: dict, list_semantics='merge'): ''' merges copies of the given dict instances and returns the merge result. @@ -484,47 +456,6 @@ def merge_dicts(base: dict, *other: dict, list_semantics='merge'): ) -class FluentIterable: - ''' a fluent object stream processing chain builder inspired by guava's FluentIterable - - Example: - result = FluentIterable(items=(1,2,3)) - .filter(lambda e: e < 2) - .map(lambda e: e * 2) - .as_generator() - - ''' - - def __init__(self, items): - def starter(): - yield from items - self.ops = [starter] - - def filter(self, filter_func): - last_op = self.ops[-1] - - def f(): - yield from filter(filter_func, last_op()) - - self.ops.append(f) - return self - - def map(self, map_func): - last_op = self.ops[-1] - - def m(): - yield from map(map_func, last_op()) - - self.ops.append(m) - return self - - def as_generator(self): - return self.ops[-1]() - - def as_list(self): - return list(self.as_generator()) - - def dict_factory_enum_serialisiation(data): def convert_value(obj): @@ -549,16 +480,3 @@ def convert_value(obj): return obj return dict((k, convert_value(v)) for k, v in data) - - -class MultilineYamlDumper(yaml.SafeDumper): - def represent_data(self, data): - # by default, the SafeDumper includes an extra empty line for each line in the data for - # string-blocks. As all provided ways to configure the dumper differently affect all - # rendered types we create our own Dumper. - if isinstance(data, str) and '\n' in data: - return self.represent_scalar(u'tag:yaml.org,2002:str', data, style='|') - # Also, don't include keys with None/null values. - if data is None: - return self.represent_scalar('tag:yaml.org,2002:null', '') - return super().represent_data(data) diff --git a/concourse/steps/update_component_deps.mako b/concourse/steps/update_component_deps.mako index 5430492db..388fe6fa2 100644 --- a/concourse/steps/update_component_deps.mako +++ b/concourse/steps/update_component_deps.mako @@ -106,8 +106,10 @@ git_helper.rebase( commit_ish=REPO_BRANCH, ) -upgrade_pull_requests = pull_request_util.enumerate_upgrade_pull_requests( - state='all', +upgrade_pull_requests = tuple( + pull_request_util.enumerate_upgrade_pull_requests( + state='all', + ), ) own_component = current_component() diff --git a/github/util.py b/github/util.py index 87e05dba5..eaf4c64d4 100644 --- a/github/util.py +++ b/github/util.py @@ -7,6 +7,7 @@ import datetime import enum import io +import logging import re import typing @@ -26,6 +27,8 @@ import ci.util import version +logger = logging.getLogger(__name__) + class RepoPermission(enum.Enum): PULL = "pull" @@ -310,37 +313,25 @@ def enumerate_upgrade_pull_requests( self, state: str='all', pattern: re.Pattern=None, - ): - '''returns a sequence of `UpgradePullRequest` for all found pull-requests - ''' + ) -> typing.Generator[UpgradePullRequest, None, None]: def has_upgrade_pr_title(pull_request): return bool(pattern.fullmatch(pull_request.title)) - def pr_to_upgrade_pr(pull_request): - return self._pr_to_upgrade_pull_request( - pull_request=pull_request, - pattern=pattern, - ) - - def strip_title(pull_request): - pull_request.title = pull_request.title.strip() - return pull_request - if not pattern: pattern = self._pr_title_pattern - parsed_prs = ci.util.FluentIterable( - self.repository.pull_requests( - state=state, - number=128, # avoid issueing more than one github-api-request + for pull_request in self.repository.pull_requests( + state=state, + number=128, # avoid issueing more than one github-api-request + ): + pull_request.title = pull_request.title.strip() + if not has_upgrade_pr_title(pull_request): + continue + + yield self._pr_to_upgrade_pull_request( + pull_request=pull_request, + pattern=pattern, ) - ) \ - .map(strip_title) \ - .filter(has_upgrade_pr_title) \ - .map(pr_to_upgrade_pr) \ - .filter(lambda e: e) \ - .as_list() - return parsed_prs def retrieve_pr_template_text(self): '''Return the content for the PR template file looking in predefined directories. @@ -380,7 +371,7 @@ def create_or_update_file( decoded_contents = contents.decoded.decode('utf-8') if decoded_contents == file_contents: # Nothing to do - return ci.util.info( + return logger.info( 'Repository file contents are identical to passed file contents.' ) else: diff --git a/test/ci/util_test.py b/test/ci/util_test.py index 573867483..da280e8fd 100644 --- a/test/ci/util_test.py +++ b/test/ci/util_test.py @@ -47,14 +47,6 @@ def test_fail(): assert len(stdout.getvalue()) == 0 -def test_success(): - with capture_out() as (stdout, stderr): - examinee.success('xxx') - - assert 'SUCCESS: xxx' == stdout.getvalue().strip() - assert len(stderr.getvalue()) == 0 - - class UtilTest(unittest.TestCase): def test_not_empty(self): result = examinee.not_empty('foo') diff --git a/version.py b/version.py index 7bdd5e168..d4b5c96be 100644 --- a/version.py +++ b/version.py @@ -545,7 +545,7 @@ def is_semver_parseable(version_string: str): try: parse_to_semver(version_string) except ValueError: - ci.util.verbose(f"Could not parse '{version_string}' as semver version") + logger.debug(f"Could not parse '{version_string}' as semver version") return False return True