Skip to content

Commit f97d8b9

Browse files
committed
resolve issue #285
simply moved the check in init for requirements.txt ahead of searching for packages. Closes #285. Passes tox (3.7, 3.8, 3.9, pypy3, flake8)
1 parent 80bfad8 commit f97d8b9

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

pipreqs/pipreqs.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,16 @@ def init(args):
412412
if extra_ignore_dirs:
413413
extra_ignore_dirs = extra_ignore_dirs.split(',')
414414

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+
415425
candidates = get_all_imports(input_path,
416426
encoding=encoding,
417427
extra_ignore_dirs=extra_ignore_dirs,
@@ -442,9 +452,6 @@ def init(args):
442452
# sort imports based on lowercase name of package, similar to `pip freeze`.
443453
imports = sorted(imports, key=lambda x: x['name'].lower())
444454

445-
path = (args["--savepath"] if args["--savepath"] else
446-
os.path.join(input_path, "requirements.txt"))
447-
448455
if args["--diff"]:
449456
diff(args["--diff"], imports)
450457
return
@@ -453,14 +460,6 @@ def init(args):
453460
clean(args["--clean"], imports)
454461
return
455462

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-
464463
if args["--mode"]:
465464
scheme = args.get("--mode")
466465
if scheme in ["compat", "gt", "no-pin"]:

0 commit comments

Comments
 (0)