1010#
1111
1212import json
13- import sys
1413from typing import List
1514
1615import click
3433
3534
3635@click .command ()
36+ @click .pass_context
3737@click .option (
3838 "-r" ,
3939 "--requirement" ,
133133 "--index-url are ignored when this option is active." ,
134134)
135135@click .option (
136- "--debug " ,
136+ "--verbose " ,
137137 is_flag = True ,
138138 hidden = True ,
139139 help = "Enable debug output." ,
140140)
141141@click .help_option ("-h" , "--help" )
142142def resolve_dependencies (
143+ ctx ,
143144 requirement_files ,
144145 netrc_file ,
145146 specifiers ,
@@ -151,7 +152,7 @@ def resolve_dependencies(
151152 max_rounds ,
152153 use_cached_index = False ,
153154 use_pypi_json_api = False ,
154- debug = TRACE ,
155+ verbose = TRACE ,
155156):
156157 """
157158 Resolve the dependencies of the packages listed in REQUIREMENT-FILE(s) file
@@ -172,11 +173,14 @@ def resolve_dependencies(
172173 dad --spec "flask==2.1.2" --json -
173174 """
174175 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 )
178178
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 :
180184 click .secho (f"Resolving dependencies..." )
181185
182186 netrc = None
@@ -199,11 +203,10 @@ def resolve_dependencies(
199203 direct_dependencies .append (dep )
200204
201205 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 )
205208
206- if debug :
209+ if verbose :
207210 click .secho ("direct_dependencies:" )
208211 for dep in direct_dependencies :
209212 click .secho (f" { dep } " )
@@ -213,7 +216,7 @@ def resolve_dependencies(
213216 python_version = python_version , operating_system = operating_system
214217 )
215218
216- if debug :
219+ if verbose :
217220 click .secho (f"environment: { environment } " )
218221
219222 repos = []
@@ -239,7 +242,7 @@ def resolve_dependencies(
239242 )
240243 repos .append (repo )
241244
242- if debug :
245+ if verbose :
243246 click .secho ("repos:" )
244247 for repo in repos :
245248 click .secho (f" { repo } " )
@@ -251,7 +254,7 @@ def resolve_dependencies(
251254 repos = repos ,
252255 as_tree = False ,
253256 max_rounds = max_rounds ,
254- debug = debug ,
257+ verbose = verbose ,
255258 pdt_output = pdt_output ,
256259 )
257260
@@ -286,7 +289,7 @@ def resolve_dependencies(
286289 json_output = json_output ,
287290 )
288291
289- if pdt_output :
292+ else :
290293 write_output (
291294 headers = headers ,
292295 requirements = requirements ,
@@ -295,7 +298,7 @@ def resolve_dependencies(
295298 pdt_output = True ,
296299 )
297300
298- if debug :
301+ if verbose :
299302 click .secho ("done!" )
300303
301304
@@ -305,7 +308,7 @@ def resolve(
305308 repos = tuple (),
306309 as_tree = False ,
307310 max_rounds = 200000 ,
308- debug = False ,
311+ verbose = False ,
309312 pdt_output = False ,
310313):
311314 """
@@ -324,11 +327,10 @@ def resolve(
324327 repos = repos ,
325328 as_tree = as_tree ,
326329 max_rounds = max_rounds ,
327- debug = debug ,
330+ verbose = verbose ,
328331 pdt_output = pdt_output ,
329332 )
330333
331-
332334 initial_requirements = [d .to_dict () for d in direct_dependencies ]
333335
334336 return initial_requirements , resolved_dependencies
0 commit comments