@@ -65,6 +65,7 @@ def handle(self) -> int:
65
65
project_content = content .get ("project" , {})
66
66
groups_content = content .get ("dependency-groups" , {})
67
67
poetry_content = content .get ("tool" , {}).get ("poetry" , {})
68
+ poetry_groups_content = poetry_content .get ("group" , {})
68
69
69
70
if group is None :
70
71
# remove from all groups
@@ -75,42 +76,39 @@ def handle(self) -> int:
75
76
76
77
if project_dependencies or poetry_dependencies :
77
78
group_sections .append (
78
- (MAIN_GROUP , project_dependencies , poetry_dependencies , [] )
79
+ (MAIN_GROUP , project_dependencies , poetry_dependencies )
79
80
)
80
81
group_sections .extend (
81
- (group_name , [], {}, dependencies )
82
+ (
83
+ group_name ,
84
+ dependencies ,
85
+ poetry_groups_content .get (group_name , {}).get ("dependencies" , {}),
86
+ )
82
87
for group_name , dependencies in groups_content .items ()
83
88
)
84
89
group_sections .extend (
85
- (group_name , [], group_section .get ("dependencies" , {}), [])
86
- for group_name , group_section in poetry_content .get ("group" , {}).items ()
90
+ (group_name , [], group_section .get ("dependencies" , {}))
91
+ for group_name , group_section in poetry_groups_content .items ()
92
+ if group_name not in groups_content and group_name != MAIN_GROUP
87
93
)
88
94
89
- for (
90
- group_name ,
91
- project_section ,
92
- poetry_section ,
93
- group_dep_section ,
94
- ) in group_sections :
95
+ for group_name , standard_section , poetry_section in group_sections :
95
96
removed |= self ._remove_packages (
96
97
packages = packages ,
97
- project_section = project_section ,
98
+ standard_section = standard_section ,
98
99
poetry_section = poetry_section ,
99
- group_section = group_dep_section ,
100
100
group_name = group_name ,
101
101
)
102
102
if group_name != MAIN_GROUP :
103
- if not poetry_section and group_name in poetry_content .get (
104
- "group" , {}
105
- ):
103
+ if not poetry_section and group_name in poetry_groups_content :
106
104
del poetry_content ["group" ][group_name ]
107
- if not group_dep_section and group_name in groups_content :
105
+ if not standard_section and group_name in groups_content :
108
106
del groups_content [group_name ]
109
107
110
108
elif group == "dev" and "dev-dependencies" in poetry_content :
111
109
# We need to account for the old `dev-dependencies` section
112
110
removed = self ._remove_packages (
113
- packages , [], poetry_content ["dev-dependencies" ], [], "dev"
111
+ packages , [], poetry_content ["dev-dependencies" ], "dev"
114
112
)
115
113
116
114
if not poetry_content ["dev-dependencies" ]:
@@ -122,11 +120,10 @@ def handle(self) -> int:
122
120
removed .update (
123
121
self ._remove_packages (
124
122
packages = packages ,
125
- project_section = [],
123
+ standard_section = [],
126
124
poetry_section = poetry_content ["group" ][group ].get (
127
125
"dependencies" , {}
128
126
),
129
- group_section = [],
130
127
group_name = group ,
131
128
)
132
129
)
@@ -137,9 +134,8 @@ def handle(self) -> int:
137
134
removed .update (
138
135
self ._remove_packages (
139
136
packages = packages ,
140
- project_section = [ ],
137
+ standard_section = groups_content [ group ],
141
138
poetry_section = {},
142
- group_section = groups_content [group ],
143
139
group_name = group ,
144
140
)
145
141
)
@@ -178,28 +174,23 @@ def handle(self) -> int:
178
174
def _remove_packages (
179
175
self ,
180
176
packages : list [str ],
181
- project_section : list [str ],
177
+ standard_section : list [str ],
182
178
poetry_section : dict [str , Any ],
183
- group_section : list [str ],
184
179
group_name : str ,
185
180
) -> set [str ]:
186
181
removed = set ()
187
182
group = self .poetry .package .dependency_group (group_name )
188
183
189
184
for package in packages :
190
185
normalized_name = canonicalize_name (package )
191
- for requirement in project_section .copy ():
186
+ for requirement in standard_section .copy ():
192
187
if Dependency .create_from_pep_508 (requirement ).name == normalized_name :
193
- project_section .remove (requirement )
188
+ standard_section .remove (requirement )
194
189
removed .add (package )
195
190
for existing_package in list (poetry_section ):
196
191
if canonicalize_name (existing_package ) == normalized_name :
197
192
del poetry_section [existing_package ]
198
193
removed .add (package )
199
- for requirement in group_section .copy ():
200
- if Dependency .create_from_pep_508 (requirement ).name == normalized_name :
201
- group_section .remove (requirement )
202
- removed .add (package )
203
194
204
195
for package in removed :
205
196
group .remove_dependency (package )
0 commit comments