def test_split(self): a, b = partition(range(10)) assert list(a) == [0] assert list(b) == list(range(1, 10)) a, b = partition(range(10), lambda x: x >= 5) assert list(a) == [0, 1, 2, 3, 4] assert list(b) == [5, 6, 7, 8, 9]
def test_split(self): a, b = partition(range(10)) assert list(a) == [0] assert list(b) == list(range(1, 10)) a, b = partition(range(10), lambda x: x >= 5) assert list(a) == [0, 1, 2, 3, 4] assert list(b) == [5, 6, 7, 8, 9]
def _install_cmd(self): """Install files using `install` command. Args: iterable of (source, dest) tuples of files to install Raises: IpcCommandError on failure """ while True: files = (yield) # `install` forcibly resolves symlinks so split them out files, symlinks = partition( files, predicate=lambda x: os.path.islink(x[0])) self.install_symlinks(symlinks) # group and install sets of files by destination to decrease `install` calls files = sorted(self._prefix_targets(files), key=itemgetter(1)) for dest, files_group in itertools.groupby(files, itemgetter(1)): sources = list(path for path, _ in files_group) command = ['install'] + self.opts.insoptions + sources + [dest] ret, output = spawn.spawn_get_output(command, collect_fds=(2, )) if not ret: raise IpcCommandError('\n'.join(output), code=ret)
def schedule(self, pkg, executor, futures, results_q): http_urls, ftp_urls = partition( self._get_urls(pkg), predicate=lambda x: x.startswith('ftp://')) http_urls = tuple(http_urls) for urls, func in ((http_urls, self._http_check), (ftp_urls, self._ftp_check)): for url in urls: self._schedule_check(func, url, executor, futures, results_q, pkg=pkg) http_to_https_urls = ((url, f'https://{url[7:]}') for url in http_urls if url.startswith('http://')) for orig_url, url in http_to_https_urls: future = futures[orig_url] self._schedule_check(self._https_available_check, url, executor, futures, results_q, future=future, orig_url=orig_url, pkg=pkg)
def _install_targets(self, targets): files, dirs = partition(targets, predicate=os.path.isdir) # TODO: add peekable class for iterables to avoid list conversion dirs = list(dirs) if dirs: if self.opts.recursive: dirs = (d for d in dirs if d not in self.opts.excluded_dirs) self.install_from_dirs(dirs) else: raise IpcCommandError(f'{dirs[0]!r} is a directory, missing -r option?') self.install((f, os.path.basename(f)) for f in files if self._allowed_file(f))
def _install_targets(self, targets): files, dirs = partition(targets, predicate=os.path.isdir) # TODO: add peekable class for iterables to avoid list conversion dirs = list(dirs) if dirs: if self.opts.recursive and self.allow_recursive: self.install_from_dirs(dirs) else: missing_option = ', missing -r option?' if self.allow_recursive else '' raise IpcCommandError(f'{dirs[0]!r} is a directory{missing_option}') self.install((f, os.path.basename(f)) for f in files)
def check_args(cls, parser, namespace): if namespace.commits: if namespace.targets: targets = ' '.join(namespace.targets) s = pluralism(namespace.targets) parser.error( f'--commits is mutually exclusive with target{s}: {targets}' ) ref = namespace.commits repo = namespace.target_repo targets = list(repo.category_dirs) if os.path.isdir(pjoin(repo.location, 'eclass')): targets.append('eclass') try: p = subprocess.run( ['git', 'diff', '--cached', ref, '--name-only'] + targets, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=repo.location, encoding='utf8') except FileNotFoundError: parser.error( 'git not available to determine targets for --commits') if p.returncode != 0: error = p.stderr.splitlines()[0] parser.error(f'failed running git: {error}') elif not p.stdout: # no changes exist, exit early parser.exit() pkgs, eclasses = partition( p.stdout.splitlines(), predicate=lambda x: x.startswith('eclass/')) pkgs = sorted(cls._pkg_atoms(pkgs)) eclasses = filter(None, (eclass_regex.match(x) for x in eclasses)) eclasses = sorted(x.group('eclass') for x in eclasses) restrictions = [] if pkgs: restrict = packages.OrRestriction(*pkgs) restrictions.append((base.package_scope, restrict)) if eclasses: func = partial(cls._committed_eclass, frozenset(eclasses)) restrict = values.AnyMatch(values.FunctionRestriction(func)) restrictions.append((base.eclass_scope, restrict)) # no pkgs or eclasses to check, exit early if not restrictions: parser.exit() namespace.contexts.append(GitStash(parser, repo)) namespace.restrictions = restrictions
def _install_targets(self, targets): files, dirs = partition(targets, predicate=os.path.isdir) # TODO: add peekable class for iterables to avoid list conversion dirs = list(dirs) if dirs: if self.opts.recursive: dirs = (d for d in dirs if d not in self.opts.excluded_dirs) self.install_from_dirs(dirs) else: raise IpcCommandError(f'{dirs[0]!r} is a directory, missing -r option?') self.install((f, os.path.basename(f)) for f in files if self._allowed_file(f))
def _install_targets(self, targets): files, dirs = partition(targets, predicate=os.path.isdir) # TODO: add peekable class for iterables to avoid list conversion dirs = list(dirs) if dirs: if self.opts.recursive and self.allow_recursive: self.install_from_dirs(dirs) else: missing_option = ', missing -r option?' if self.allow_recursive else '' raise IpcCommandError(f'{dirs[0]!r} is a directory{missing_option}') self.install((f, os.path.basename(f)) for f in files)
def _install_cmd(self): """Install files using `install` command. Args: iterable of (source, dest) tuples of files to install Raises: IpcCommandError on failure """ while True: files = (yield) # `install` forcibly resolves symlinks so split them out files, symlinks = partition(files, predicate=lambda x: os.path.islink(x[0])) self.install_symlinks(symlinks) # group and install sets of files by destination to decrease `install` calls files = sorted(self._prefix_targets(files), key=itemgetter(1)) for dest, files_group in itertools.groupby(files, itemgetter(1)): sources = list(path for path, _ in files_group) command = ['install'] + self.opts.insoptions + sources + [dest] ret, output = spawn.spawn_get_output(command, collect_fds=(2,)) if not ret: raise IpcCommandError('\n'.join(output), code=ret)
def test_empty(self): a, b = partition(()) assert list(a) == [] assert list(b) == []
def _install_targets(self, targets): files, dirs = partition(targets, predicate=os.path.isdir) if self.opts.recursive: self.install_from_dirs(dirs) self.install((f, os.path.basename(f)) for f in files)
def test_empty(self): a, b = partition(()) assert list(a) == [] assert list(b) == []
def _install_targets(self, targets): files, dirs = partition(targets, predicate=os.path.isdir) if self.opts.recursive: self.install_from_dirs(dirs) self.install((f, os.path.basename(f)) for f in files)