def add_dependencies(
        self,
        requirements: Iterable[str | Requirement],
        to_group: str = "default",
        dev: bool = False,
        show_message: bool = True,
        write: bool = True,
    ) -> list[Requirement]:
        """Add requirements to the given group, and return the requirements of that group."""
        if isinstance(requirements, Mapping):  # pragma: no cover
            deprecation_warning(
                "Passing a requirements map to add_dependencies is deprecated, please pass an iterable", stacklevel=2
            )
            requirements = requirements.values()
        deps, setter = self.use_pyproject_dependencies(to_group, dev)
        updated_indices: set[int] = set()

        with cd(self.root):
            parsed_deps = [(parse_line(dep) if isinstance(dep, str) else None) for dep in deps]

            for req in requirements:
                if isinstance(req, str):
                    req = parse_line(req)
                matched_index = next(
                    (
                        i
                        for i, r in enumerate(deps)
                        if isinstance(r, str) and req.matches(r) and i not in updated_indices
                    ),
                    None,
                )
                dep = req.as_line()
                if matched_index is None:
                    updated_indices.add(len(deps))
                    deps.append(dep)
                    parsed_deps.append(req)
                else:
                    deps[matched_index] = dep
                    parsed_deps[matched_index] = req
                    updated_indices.add(matched_index)
        setter(deps)
        if write:
            self.pyproject.write(show_message)
        for r in parsed_deps:
            if r is not None:
                r.groups = [to_group]
        return [r for r in parsed_deps if r is not None]
Add requirements to the given group, and return the requirements of that group.
src/pdm/project/core.py