def _get_class_module()

in labgraph/runners/parallel_runner.py [0:0]


    def _get_class_module(self, cls: type) -> str:
        python_module = cls.__module__
        if python_module != "__main__":
            return python_module

        # Getting the real module name for __main__ can be annoyingly complicated...
        try:
            entry_point: Optional[str] = None

            # Try to get the module name from the file path
            cls_file = inspect.getfile(cls)
            cls_path = Path(cls_file)
            path_components = cls_path.with_name(cls_path.stem).parts

            if all(not component.endswith(".pex") for component in path_components):
                while len(path_components) > 0:
                    try:
                        entry_point = ".".join(path_components)
                        importlib.import_module(entry_point)
                        break
                    except (ImportError, TypeError):
                        entry_point = None
                    finally:
                        path_components = path_components[1:]

            # Try to get the module name from the PEX
            if entry_point is None:

                if not sys.argv[0].endswith(".pex"):
                    raise RuntimeError()
                from _pex.pex_info import PexInfo  # type: ignore

                pex_info = PexInfo.from_pex(sys.argv[0])
                entry_point = pex_info.entry_point

            # Fail if all methods failed to find an entry point
            if entry_point is None:
                raise RuntimeError()

            assert isinstance(entry_point, str)
            entry_module = importlib.import_module(entry_point)
            if hasattr(entry_module, cls.__name__):
                return entry_point
            else:
                raise RuntimeError()
        except (ImportError, RuntimeError):
            raise RuntimeError(
                f"Putting {cls.__name__} in the main scope is preventing its use with "
                f"lg.{self.__class__.__name__}. Please consider either a) creating "
                "another module to use as the main module or b) using __main__.py "
                "instead.\nhttps://docs.python.org/3.6/library/__main__.html"
            )