@@ -412,6 +412,16 @@ def init(args):
412
412
if extra_ignore_dirs :
413
413
extra_ignore_dirs = extra_ignore_dirs .split (',' )
414
414
415
+ path = (args ["--savepath" ] if args ["--savepath" ] else
416
+ os .path .join (input_path , "requirements.txt" ))
417
+ if (not args ["--print" ]
418
+ and not args ["--savepath" ]
419
+ and not args ["--force" ]
420
+ and os .path .exists (path )):
421
+ logging .warning ("requirements.txt already exists, "
422
+ "use --force to overwrite it" )
423
+ return
424
+
415
425
candidates = get_all_imports (input_path ,
416
426
encoding = encoding ,
417
427
extra_ignore_dirs = extra_ignore_dirs ,
@@ -442,9 +452,6 @@ def init(args):
442
452
# sort imports based on lowercase name of package, similar to `pip freeze`.
443
453
imports = sorted (imports , key = lambda x : x ['name' ].lower ())
444
454
445
- path = (args ["--savepath" ] if args ["--savepath" ] else
446
- os .path .join (input_path , "requirements.txt" ))
447
-
448
455
if args ["--diff" ]:
449
456
diff (args ["--diff" ], imports )
450
457
return
@@ -453,14 +460,6 @@ def init(args):
453
460
clean (args ["--clean" ], imports )
454
461
return
455
462
456
- if (not args ["--print" ]
457
- and not args ["--savepath" ]
458
- and not args ["--force" ]
459
- and os .path .exists (path )):
460
- logging .warning ("requirements.txt already exists, "
461
- "use --force to overwrite it" )
462
- return
463
-
464
463
if args ["--mode" ]:
465
464
scheme = args .get ("--mode" )
466
465
if scheme in ["compat" , "gt" , "no-pin" ]:
0 commit comments