nebius/SWE-bench-extra huggingface dataset:
Repository: gahjelle/pyplugs

Issue:
`.exists()` crashes for non-existing packages
When using `pyplugs.exists()` with a package that doesn't exist, `pyplugs` crashes instead of returning `False`

Comments:

Patch:
diff --git a/pyplugs/_plugins.py b/pyplugs/_plugins.py
index ca0d4d1..38f4434 100644
--- a/pyplugs/_plugins.py
+++ b/pyplugs/_plugins.py
@@ -141,7 +141,7 @@ def exists(package: str, plugin: str) -> bool:
 
     try:
         _import(package, plugin)
-    except _exceptions.UnknownPluginError:
+    except (_exceptions.UnknownPluginError, _exceptions.UnknownPackageError):
         return False
     else:
         return package in _PLUGINS and plugin in _PLUGINS[package]
@@ -175,6 +175,10 @@ def _import(package: str, plugin: str) -> None:
             raise _exceptions.UnknownPluginError(
                 f"Plugin {plugin!r} not found in {package!r}"
             ) from None
+        elif repr(package) in err.msg:  # type: ignore
+            raise _exceptions.UnknownPackageError(
+                f"Package {package!r} does not exist"
+            ) from None
         raise
 
 


Test patch:
diff --git a/tests/test_plugins.py b/tests/test_plugins.py
index 35e6f7d..82aea8b 100644
--- a/tests/test_plugins.py
+++ b/tests/test_plugins.py
@@ -81,6 +81,12 @@ def test_exists(plugin_package):
     assert pyplugs.exists(plugin_package, "non_existent") is False
 
 
+def test_exists_on_non_existing_package():
+    """Test that exists() correctly returns False for non-existing packages"""
+    assert pyplugs.exists("non_existent_package", "plugin_parts") is False
+    assert pyplugs.exists("non_existent_package", "non_existent") is False
+
+
 def test_call_existing_plugin(plugin_package):
     """Test that calling a test-plugin works, and returns a string"""
     plugin_name = pyplugs.names(plugin_package)[0]