Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
ulauncher / usr / lib / python3 / dist-packages / ulauncher / api / server / ProcessErrorExtractor.py
Size: Mime:
import re

from ulauncher.api.shared.errors import UlauncherAPIError


class ProcessErrorExtractor:
    def __init__(self, error: str):
        """
        expecting an error like this:
            ModuleNotFoundError: No module named 'mymodule'
        """
        self.error = error

    def is_import_error(self) -> bool:
        return 'ModuleNotFoundError' in self.error

    def get_missing_package_name(self) -> str:
        """
        Returns a name of a module that extension failed to import
        """
        match = re.match(r"^.*'(\w+)'$", self.error)
        if not match:
            raise UlauncherAPIError('Could not extract errored module name from process output')

        return match.group(1)