10
10
#
11
11
12
12
import json
13
- import sys
14
13
from typing import List
15
14
16
15
import click
34
33
35
34
36
35
@click .command ()
36
+ @click .pass_context
37
37
@click .option (
38
38
"-r" ,
39
39
"--requirement" ,
133
133
"--index-url are ignored when this option is active." ,
134
134
)
135
135
@click .option (
136
- "--debug " ,
136
+ "--verbose " ,
137
137
is_flag = True ,
138
138
hidden = True ,
139
139
help = "Enable debug output." ,
140
140
)
141
141
@click .help_option ("-h" , "--help" )
142
142
def resolve_dependencies (
143
+ ctx ,
143
144
requirement_files ,
144
145
netrc_file ,
145
146
specifiers ,
@@ -151,7 +152,7 @@ def resolve_dependencies(
151
152
max_rounds ,
152
153
use_cached_index = False ,
153
154
use_pypi_json_api = False ,
154
- debug = TRACE ,
155
+ verbose = TRACE ,
155
156
):
156
157
"""
157
158
Resolve the dependencies of the packages listed in REQUIREMENT-FILE(s) file
@@ -172,11 +173,14 @@ def resolve_dependencies(
172
173
dad --spec "flask==2.1.2" --json -
173
174
"""
174
175
if not (json_output or pdt_output ):
175
- if debug :
176
- click .secho ("No output file specified. Use --json or --json-pdt." , err = True )
177
- return
176
+ click .secho ("No output file specified. Use --json or --json-pdt." , err = True )
177
+ ctx .exit (1 )
178
178
179
- if debug :
179
+ if json_output and pdt_output :
180
+ click .secho ("Only one of --json or --json-pdt can be used." , err = True )
181
+ ctx .exit (1 )
182
+
183
+ if verbose :
180
184
click .secho (f"Resolving dependencies..." )
181
185
182
186
netrc = None
@@ -199,11 +203,10 @@ def resolve_dependencies(
199
203
direct_dependencies .append (dep )
200
204
201
205
if not direct_dependencies :
202
- if debug :
203
- click .secho ("Error: no requirements requested." )
204
- sys .exit (1 )
206
+ click .secho ("Error: no requirements requested." )
207
+ ctx .exit (1 )
205
208
206
- if debug :
209
+ if verbose :
207
210
click .secho ("direct_dependencies:" )
208
211
for dep in direct_dependencies :
209
212
click .secho (f" { dep } " )
@@ -213,7 +216,7 @@ def resolve_dependencies(
213
216
python_version = python_version , operating_system = operating_system
214
217
)
215
218
216
- if debug :
219
+ if verbose :
217
220
click .secho (f"environment: { environment } " )
218
221
219
222
repos = []
@@ -239,7 +242,7 @@ def resolve_dependencies(
239
242
)
240
243
repos .append (repo )
241
244
242
- if debug :
245
+ if verbose :
243
246
click .secho ("repos:" )
244
247
for repo in repos :
245
248
click .secho (f" { repo } " )
@@ -251,7 +254,7 @@ def resolve_dependencies(
251
254
repos = repos ,
252
255
as_tree = False ,
253
256
max_rounds = max_rounds ,
254
- debug = debug ,
257
+ verbose = verbose ,
255
258
pdt_output = pdt_output ,
256
259
)
257
260
@@ -286,7 +289,7 @@ def resolve_dependencies(
286
289
json_output = json_output ,
287
290
)
288
291
289
- if pdt_output :
292
+ else :
290
293
write_output (
291
294
headers = headers ,
292
295
requirements = requirements ,
@@ -295,7 +298,7 @@ def resolve_dependencies(
295
298
pdt_output = True ,
296
299
)
297
300
298
- if debug :
301
+ if verbose :
299
302
click .secho ("done!" )
300
303
301
304
@@ -305,7 +308,7 @@ def resolve(
305
308
repos = tuple (),
306
309
as_tree = False ,
307
310
max_rounds = 200000 ,
308
- debug = False ,
311
+ verbose = False ,
309
312
pdt_output = False ,
310
313
):
311
314
"""
@@ -324,11 +327,10 @@ def resolve(
324
327
repos = repos ,
325
328
as_tree = as_tree ,
326
329
max_rounds = max_rounds ,
327
- debug = debug ,
330
+ verbose = verbose ,
328
331
pdt_output = pdt_output ,
329
332
)
330
333
331
-
332
334
initial_requirements = [d .to_dict () for d in direct_dependencies ]
333
335
334
336
return initial_requirements , resolved_dependencies
0 commit comments