Skip to content

Commit

Permalink
resolve issue #285
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
clvnkhr committed Jan 5, 2023
1 parent 80bfad8 commit f97d8b9
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions pipreqs/pipreqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ def init(args):
if extra_ignore_dirs:
extra_ignore_dirs = extra_ignore_dirs.split(',')

path = (args["--savepath"] if args["--savepath"] else
os.path.join(input_path, "requirements.txt"))
if (not args["--print"]
and not args["--savepath"]
and not args["--force"]
and os.path.exists(path)):
logging.warning("requirements.txt already exists, "
"use --force to overwrite it")
return

candidates = get_all_imports(input_path,
encoding=encoding,
extra_ignore_dirs=extra_ignore_dirs,
Expand Down Expand Up @@ -442,9 +452,6 @@ def init(args):
# sort imports based on lowercase name of package, similar to `pip freeze`.
imports = sorted(imports, key=lambda x: x['name'].lower())

path = (args["--savepath"] if args["--savepath"] else
os.path.join(input_path, "requirements.txt"))

if args["--diff"]:
diff(args["--diff"], imports)
return
Expand All @@ -453,14 +460,6 @@ def init(args):
clean(args["--clean"], imports)
return

if (not args["--print"]
and not args["--savepath"]
and not args["--force"]
and os.path.exists(path)):
logging.warning("requirements.txt already exists, "
"use --force to overwrite it")
return

if args["--mode"]:
scheme = args.get("--mode")
if scheme in ["compat", "gt", "no-pin"]:
Expand Down

0 comments on commit f97d8b9

Please sign in to comment.