Skip to content

Commit b8c195d

Browse files
dgarciabmwiedemann
dgarcia
authored andcommitted
Update python-itemadapter to version 0.8.0 / rev 5 via SR 1159849
https://build.opensuse.org/request/show/1159849 by user dgarcia + dimstar_suse - Add pydantic2.patch to make tests compatible with pydantic2 gh#scrapy/itemadapter#76
1 parent 3e20507 commit b8c195d

File tree

5 files changed

+168
-4
lines changed

5 files changed

+168
-4
lines changed

packages/p/python-itemadapter/.files

53 Bytes
Binary file not shown.

packages/p/python-itemadapter/.rev

+9
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,13 @@
4141
- Disable python36 build due to Scrapy</comment>
4242
<requestid>1131744</requestid>
4343
</revision>
44+
<revision rev="5" vrev="2">
45+
<srcmd5>8524f7d39675ced15d8f93eb4fba07f7</srcmd5>
46+
<version>0.8.0</version>
47+
<time>1710965920</time>
48+
<user>dimstar_suse</user>
49+
<comment>- Add pydantic2.patch to make tests compatible with pydantic2
50+
gh#scrapy/itemadapter#76</comment>
51+
<requestid>1159849</requestid>
52+
</revision>
4453
</revisionlist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
Index: itemadapter-0.8.0/README.md
2+
===================================================================
3+
--- itemadapter-0.8.0.orig/README.md
4+
+++ itemadapter-0.8.0/README.md
5+
@@ -193,7 +193,7 @@ The returned value is taken from the fol
6+
for `dataclass`-based items
7+
* [`attr.Attribute.metadata`](https://www.attrs.org/en/stable/examples.html#metadata)
8+
for `attrs`-based items
9+
- * [`pydantic.fields.FieldInfo`](https://pydantic-docs.helpmanual.io/usage/schema/#field-customisation)
10+
+ * [`pydantic.fields.FieldInfo`](https://docs.pydantic.dev/latest/api/fields/#pydantic.fields.FieldInfo)
11+
for `pydantic`-based items
12+
13+
#### class method `get_field_names_from_class(item_class: type) -> Optional[list[str]]`
14+
Index: itemadapter-0.8.0/itemadapter/adapter.py
15+
===================================================================
16+
--- itemadapter-0.8.0.orig/itemadapter/adapter.py
17+
+++ itemadapter-0.8.0/itemadapter/adapter.py
18+
@@ -179,24 +179,24 @@ class PydanticAdapter(AdapterInterface):
19+
20+
@classmethod
21+
def get_field_names_from_class(cls, item_class: type) -> Optional[List[str]]:
22+
- return list(item_class.__fields__.keys()) # type: ignore[attr-defined]
23+
+ return list(item_class.model_fields.keys()) # type: ignore[attr-defined]
24+
25+
def field_names(self) -> KeysView:
26+
- return KeysView(self.item.__fields__)
27+
+ return KeysView(self.item.model_fields)
28+
29+
def __getitem__(self, field_name: str) -> Any:
30+
- if field_name in self.item.__fields__:
31+
+ if field_name in self.item.model_fields:
32+
return getattr(self.item, field_name)
33+
raise KeyError(field_name)
34+
35+
def __setitem__(self, field_name: str, value: Any) -> None:
36+
- if field_name in self.item.__fields__:
37+
+ if field_name in self.item.model_fields:
38+
setattr(self.item, field_name, value)
39+
else:
40+
raise KeyError(f"{self.item.__class__.__name__} does not support field: {field_name}")
41+
42+
def __delitem__(self, field_name: str) -> None:
43+
- if field_name in self.item.__fields__:
44+
+ if field_name in self.item.model_fields:
45+
try:
46+
delattr(self.item, field_name)
47+
except AttributeError:
48+
@@ -205,7 +205,7 @@ class PydanticAdapter(AdapterInterface):
49+
raise KeyError(f"{self.item.__class__.__name__} does not support field: {field_name}")
50+
51+
def __iter__(self) -> Iterator:
52+
- return iter(attr for attr in self.item.__fields__ if hasattr(self.item, attr))
53+
+ return iter(attr for attr in self.item.model_fields if hasattr(self.item, attr))
54+
55+
def __len__(self) -> int:
56+
return len(list(iter(self)))
57+
Index: itemadapter-0.8.0/itemadapter/utils.py
58+
===================================================================
59+
--- itemadapter-0.8.0.orig/itemadapter/utils.py
60+
+++ itemadapter-0.8.0/itemadapter/utils.py
61+
@@ -23,30 +23,21 @@ def _is_pydantic_model(obj: Any) -> bool
62+
63+
def _get_pydantic_model_metadata(item_model: Any, field_name: str) -> MappingProxyType:
64+
metadata = {}
65+
- field = item_model.__fields__[field_name].field_info
66+
+ field = item_model.model_fields[field_name]
67+
68+
for attribute in [
69+
"alias",
70+
"title",
71+
"description",
72+
- "const",
73+
- "gt",
74+
- "ge",
75+
- "lt",
76+
- "le",
77+
- "multiple_of",
78+
- "min_items",
79+
- "max_items",
80+
- "min_length",
81+
- "max_length",
82+
- "regex",
83+
]:
84+
value = getattr(field, attribute)
85+
if value is not None:
86+
metadata[attribute] = value
87+
- if not field.allow_mutation:
88+
- metadata["allow_mutation"] = field.allow_mutation
89+
- metadata.update(field.extra)
90+
+ if field.frozen is not None:
91+
+ metadata["frozen"] = field.frozen
92+
+
93+
+ if field.json_schema_extra is not None:
94+
+ metadata.update(field.json_schema_extra)
95+
96+
return MappingProxyType(metadata)
97+
98+
Index: itemadapter-0.8.0/tests/__init__.py
99+
===================================================================
100+
--- itemadapter-0.8.0.orig/tests/__init__.py
101+
+++ itemadapter-0.8.0/tests/__init__.py
102+
@@ -102,7 +102,7 @@ else:
103+
104+
105+
try:
106+
- from pydantic import BaseModel, Field as PydanticField
107+
+ from pydantic import ConfigDict, BaseModel, Field as PydanticField
108+
except ImportError:
109+
PydanticModel = None
110+
PydanticSpecialCasesModel = None
111+
@@ -125,11 +125,9 @@ else:
112+
special_cases: Optional[int] = PydanticField(
113+
default_factory=lambda: None,
114+
alias="special_cases",
115+
- allow_mutation=False,
116+
+ frozen=False,
117+
)
118+
-
119+
- class Config:
120+
- validate_assignment = True
121+
+ model_config = ConfigDict(validate_assignment=True)
122+
123+
class PydanticModelNested(BaseModel):
124+
nested: PydanticModel
125+
@@ -139,9 +137,7 @@ else:
126+
set_: set
127+
tuple_: tuple
128+
int_: int
129+
-
130+
- class Config:
131+
- arbitrary_types_allowed = True
132+
+ model_config = ConfigDict(arbitrary_types_allowed=True)
133+
134+
class PydanticModelSubclassed(PydanticModel):
135+
subclassed: bool = PydanticField(
136+
Index: itemadapter-0.8.0/tests/test_adapter_pydantic.py
137+
===================================================================
138+
--- itemadapter-0.8.0.orig/tests/test_adapter_pydantic.py
139+
+++ itemadapter-0.8.0/tests/test_adapter_pydantic.py
140+
@@ -73,7 +73,7 @@ class DataclassTestCase(unittest.TestCas
141+
)
142+
self.assertEqual(
143+
get_field_meta_from_class(PydanticSpecialCasesModel, "special_cases"),
144+
- MappingProxyType({"alias": "special_cases", "allow_mutation": False}),
145+
+ MappingProxyType({"alias": "special_cases", "frozen": False}),
146+
)
147+
with self.assertRaises(KeyError, msg="PydanticModel does not support field: non_existent"):
148+
get_field_meta_from_class(PydanticModel, "non_existent")

packages/p/python-itemadapter/python-itemadapter.changes

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
-------------------------------------------------------------------
2+
Wed Mar 20 13:31:31 UTC 2024 - Daniel Garcia <[email protected]>
3+
4+
- Add pydantic2.patch to make tests compatible with pydantic2
5+
gh#scrapy/itemadapter#76
6+
17
-------------------------------------------------------------------
28
Thu Dec 7 22:47:54 UTC 2023 - Dirk Müller <[email protected]>
39

packages/p/python-itemadapter/python-itemadapter.spec

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
2-
# spec file
2+
# spec file for package python-itemadapter
33
#
4-
# Copyright (c) 2023 SUSE LLC
4+
# Copyright (c) 2024 SUSE LLC
55
# Copyright (c) 2016, Martin Hauke <[email protected]>
66
#
77
# All modifications and additions to the file contributed by third parties
@@ -17,7 +17,6 @@
1717
#
1818

1919

20-
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
2120
%global flavor @BUILD_FLAVOR@%{nil}
2221
%if "%{flavor}" == "test"
2322
%define psuffix -test
@@ -36,6 +35,8 @@ Summary: Wrapper for data container objects
3635
License: BSD-3-Clause
3736
URL: https://github.com/scrapy/itemadapter
3837
Source: https://github.com/scrapy/itemadapter/archive/v%{version}.tar.gz#/itemadapter-%{version}.tar.gz
38+
# PATCH-FIX-UPSTREAM pydantic2.patch gh#scrapy/itemadapter#76
39+
Patch0: pydantic2.patch
3940
BuildRequires: %{python_module setuptools >= 40.5.0}
4041
BuildRequires: fdupes
4142
BuildRequires: python-rpm-macros
@@ -53,7 +54,7 @@ a common interface to handle objects of different types in an uniform
5354
manner, regardless of their underlying implementation.
5455

5556
%prep
56-
%setup -q -n itemadapter-%{version}
57+
%autosetup -p1 -n itemadapter-%{version}
5758

5859
%build
5960
%python_build

0 commit comments

Comments
 (0)