Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: if 'max_conversions' limit is reached but there are unconverted dependencies left, prompt user to continue conversion #11

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/py2spack/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,8 @@ def convert_package( # noqa: PLR0913 [too many arguments in function defintion]
or bool(spackpkg.dependency_conflict_errors)
or bool(spackpkg.cmake_dependency_names)
)

print(f"> Converted package {name}")
converted.append((name, spackpkg.num_converted_versions, dep_requires_fix))

for dep in spackpkg.original_dependencies:
Expand All @@ -1087,9 +1089,27 @@ def convert_package( # noqa: PLR0913 [too many arguments in function defintion]
if not spack_utils.package_exists_in_spack(dep) and dep not in ignore_list:
missing_non_python_deps.add(dep)

if len(converted) == max_conversions and queue:
print("\nUnconverted dependency packages:")
for p in queue:
print(f" - {p}")
user_input = ""
while (
user_input := input(
f"\n'max_conversions' limit reached but {len(queue)} unconverted dependencies remaining. Do you want to:\n 'n' - stop conversion\n 'y' - convert the {len(queue)} remaining dependencies\n 'all' - continue conversion of all dependencies without 'max_conversions' limit (you can cancel at any time using Ctrl+C)\n>> "
)
) not in ["y", "n", "all"]:
continue

if user_input == "y":
max_conversions += len(queue)
elif user_input == "all":
max_conversions = -1

except KeyboardInterrupt:
# display the current package in summary
queue.insert(0, name)
if name not in converted and name not in conversion_failures:
queue.insert(0, name)

_print_summary(converted, queue, conversion_failures, missing_non_python_deps)

Expand Down
7 changes: 6 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,12 @@ def test_convert_package_writes_file(package: str) -> None:
repo = cwd / "tests" / "sample_data" / "sample_repo"

core.convert_package(
package, max_conversions=1, versions_per_package=5, repo=str(repo), allow_duplicate=True
package,
max_conversions=1,
versions_per_package=5,
repo=str(repo),
allow_duplicate=True,
ignore=["slack-sdk"],
)

pkg_dir = repo / "packages" / f"py-{package}"
Expand Down
Loading