Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Deduplicate lists when running pdm import #1627

Merged
merged 3 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/pdm/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import json
import os
import sys
from argparse import Action, _ArgumentGroup
from collections import ChainMap, OrderedDict
from concurrent.futures import ThreadPoolExecutor
from json import dumps
Expand All @@ -26,19 +25,16 @@
from rich.tree import Tree

from pdm import termui
from pdm.compat import importlib_metadata as im
from pdm.exceptions import PdmArgumentError, PdmUsageError, ProjectError
from pdm.formats import FORMATS
from pdm.formats.base import make_array, make_inline_table
from pdm.models.repositories import BaseRepository
from pdm.models.requirements import (
Requirement,
filter_requirements_with_extras,
parse_requirement,
strip_extras,
)
from pdm.models.specifiers import get_specifier
from pdm.project import Project
from pdm.utils import (
comparable_version,
is_path_relative_to,
Expand All @@ -47,11 +43,16 @@
)

if TYPE_CHECKING:
from argparse import Action, _ArgumentGroup

from packaging.version import Version
from resolvelib.resolvers import RequirementInformation, ResolutionImpossible

from pdm.compat import Distribution
from pdm.compat import importlib_metadata as im
from pdm.models.candidates import Candidate
from pdm.models.repositories import BaseRepository
from pdm.project import Project


class ErrorArgumentParser(argparse.ArgumentParser):
Expand Down Expand Up @@ -677,14 +678,15 @@ def merge_dictionary(
) -> None:
"""Merge the input dict with the target while preserving the existing values
properly. This will update the target dictionary in place.
List values will be extended, but only if the value is not already in the list.
"""
for key, value in input.items():
if key not in target:
target[key] = value
elif isinstance(value, dict):
target[key].update(value)
elif isinstance(value, list):
target[key].extend(value)
target[key].extend([x for x in value if x not in target[key]])
else:
target[key] = value

Expand Down
4 changes: 2 additions & 2 deletions src/pdm/formats/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import operator
import os
import re
from argparse import Namespace
from pathlib import Path
from typing import TYPE_CHECKING, Any, Iterable, Mapping, cast

from pdm._types import RequirementDict, Source
from pdm.compat import tomllib
from pdm.formats.base import (
MetaConverter,
Expand All @@ -24,6 +22,8 @@

if TYPE_CHECKING:
from pdm.project.core import Project
from argparse import Namespace
from pdm._types import RequirementDict, Source

from pdm.utils import cd

Expand Down