Skip to content

Commit 903919f

Browse files
ivanbarsukovbbhtt
authored andcommitted
pip: Improve output filename handling
1 parent ea9bfa2 commit 903919f

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

pip/flatpak-pip-generator.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -291,23 +291,30 @@ def fprint(string: str) -> None:
291291
flatpak_cmd = [pip_executable]
292292

293293
output_path = ""
294+
output_package = ""
294295

295296
if opts.output:
296-
output_path = os.path.dirname(opts.output)
297-
output_package = os.path.basename(opts.output)
298-
elif opts.requirements_file:
299-
output_package = "python{}-{}".format(
300-
python_version,
301-
os.path.basename(opts.requirements_file).replace(".txt", ""),
302-
)
303-
elif len(packages) == 1:
304-
output_package = f"python{python_version}-{packages[0].name}"
305-
else:
306-
output_package = f"python{python_version}-modules"
307-
if opts.yaml:
308-
output_filename = os.path.join(output_path, output_package) + ".yaml"
309-
else:
310-
output_filename = os.path.join(output_path, output_package) + ".json"
297+
if os.path.isdir(opts.output):
298+
output_path = opts.output
299+
else:
300+
output_path = os.path.dirname(opts.output)
301+
output_package = os.path.basename(opts.output)
302+
303+
if not output_package:
304+
if opts.requirements_file:
305+
output_package = "python{}-{}".format(
306+
python_version,
307+
os.path.basename(opts.requirements_file).replace(".txt", ""),
308+
)
309+
elif len(packages) == 1:
310+
output_package = f"python{python_version}-{packages[0].name}"
311+
else:
312+
output_package = f"python{python_version}-modules"
313+
314+
output_filename = os.path.join(output_path, output_package)
315+
suffix = ".yaml" if opts.yaml else ".json"
316+
if not output_filename.endswith(suffix):
317+
output_filename += suffix
311318

312319
modules: list[dict[str, str | list[str] | list[dict[str, Any]]]] = []
313320
vcs_modules: list[dict[str, str | list[str] | list[dict[str, Any]]]] = []

0 commit comments

Comments
 (0)