Issue with slpkg Attempting to Remove Non-Existent List Item
Dear Dimitris Zlatanidis:
I am experiencing an issue with slpkg where it attempts to remove an item from a list that doesn't exist, resulting in a ValueError. Below are the details:
Environment:
Slackware Version: Slackware64 live lean current SSD install w/persistence
sudo /usr/local/sbin/iso2usb.sh -F btrfs -P -c 50% -f -i slackware64-live-lean-current.iso -o /dev/sdb/
https://download.liveslak.org/latest/
slpkg Version: 5.2.1
Python Version: 3.12.8
Installation Log:
Collecting slpkg Downloading slpkg-5.2.1-py3-none-any.whl.metadata (3.5 kB) Collecting pythondialog>=3.5.3 (from slpkg) Downloading pythondialog-3.5.3-py3-none-any.whl.metadata (12 kB) Collecting tomlkit>=0.13.2 (from slpkg) Downloading tomlkit-0.13.2-py3-none-any.whl.metadata (2.7 kB) Downloading slpkg-5.2.1-py3-none-any.whl (87 kB) Downloading pythondialog-3.5.3-py3-none-any.whl (54 kB) Downloading tomlkit-0.13.2-py3-none-any.whl (37 kB) Installing collected packages: tomlkit, pythondialog, slpkg Successfully installed pythondialog-3.5.3 slpkg-5.2.1 tomlkit-0.13.2
Problem Description:
After PIP3 installation, when attempting to use slpkg, the following error occurs:
Traceback (most recent call last): File "/usr/bin/slpkg", line 33, in sys.exit(load_entry_point('slpkg==5.2.1', 'console_scripts', 'slpkg')()) File "/usr/lib/python3.12/site-packages/slpkg/main.py", line 9, in main cli() File "/usr/lib/python3.12/site-packages/click/core.py", line 829, in call return self.main(*args, **kwargs) File "/usr/lib/python3.12/site-packages/click/core.py", line 782, in main rv = self.invoke(ctx) File "/usr/lib/python3.12/site-packages/click/core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/usr/lib/python3.12/site-packages/click/core.py", line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File "/usr/lib/python3.12/site-packages/click/core.py", line 610, in invoke return callback(*args, **kwargs) File "/usr/lib/python3.12/site-packages/slpkg/main.py", line 54, in cli update() File "/usr/lib/python3.12/site-packages/slpkg/main.py", line 85, in update remove_package(pkg) File "/usr/lib/python3.12/site-packages/slpkg/main.py", line 113, in remove_package installed_packages.remove(pkg) ValueError: list.remove(x): x not in list
Expected Behavior:
slpkg should manage packages without errors, including correctly handling the removal of packages from the list of installed packages.
Actual Behavior:
Attempting to remove a package results in a ValueError because the package is not found in the list.
Additional Information:
This issue may be related to the way slpkg handles the removal of items from lists. In Python, attempting to remove an item that doesn't exist in a list raises a ValueError. To prevent this, it's advisable to check if the item exists in the list before attempting to remove it.
stackoverflow.com I have found discussions where similar issues are addressed, suggesting that verifying the item's presence before removal can prevent such errors. softwareengineering.stackexchange.com
Steps to Reproduce:
Install slpkg version 5.2.1 using pip3.
Attempt to remove a package using slpkg.
Observe the ValueError traceback.
Proposed Solution:
Modify the remove_package function in slpkg to check if the package exists in the installed_packages list before attempting to remove it. This can be achieved by adding a conditional check:
if pkg in installed_packages: installed_packages.remove(pkg) else: # Handle the case where the package is not found
Implementing this change should prevent the ValueError and allow slpkg to function as intended.
Thank you for your attention to this matter.
Best regards, SLPKG USER