Get the entry point for the main object.
()
| 73 | |
| 74 | |
| 75 | def get_entry_point() -> importlib.metadata.EntryPoint: |
| 76 | """Get the entry point for the main object.""" |
| 77 | sel = importlib.metadata.entry_points( |
| 78 | group=ENTRY_POINT_GROUP, |
| 79 | name=ENTRY_POINT_NAME, |
| 80 | ) |
| 81 | if ep := next(iter(sel), None): |
| 82 | return ep |
| 83 | |
| 84 | import_pkg = IMPORT_PKG |
| 85 | |
| 86 | # Fallback for modules that still use the "main" package name. |
| 87 | if not importlib.util.find_spec(import_pkg): |
| 88 | import_pkg = "main" |
| 89 | |
| 90 | if not importlib.util.find_spec(import_pkg): |
| 91 | msg = ( |
| 92 | "Main object not found. You can configure it explicitly by adding " |
| 93 | "an entry point to your pyproject.toml file. For example:\n" |
| 94 | "\n" |
| 95 | f'[project.entry-points."{ENTRY_POINT_GROUP}"]\n' |
| 96 | f"{ENTRY_POINT_NAME} = '{IMPORT_PKG}:{MAIN_OBJECT}'\n" |
| 97 | ) |
| 98 | raise ModuleLoadError(msg) |
| 99 | |
| 100 | return importlib.metadata.EntryPoint( |
| 101 | group=ENTRY_POINT_GROUP, |
| 102 | name=ENTRY_POINT_NAME, |
| 103 | value=f"{import_pkg}:{MAIN_OBJECT}", |
| 104 | ) |
no test coverage detected