Use importlib.resources to enumerate kitten names

This commit is contained in:
Kovid Goyal
2021-02-16 13:48:02 +05:30
parent d2a16bc8e8
commit 55e7f69768

View File

@@ -123,14 +123,12 @@ def run_kitten(kitten: str, run_name: str = '__main__') -> None:
@run_once @run_once
def all_kitten_names() -> FrozenSet[str]: def all_kitten_names() -> FrozenSet[str]:
n = [] from importlib.resources import contents
import glob ans = []
base = os.path.dirname(os.path.abspath(__file__)) for name in contents('kittens'):
for x in glob.glob(os.path.join(base, '*', '__init__.py')): if '__' not in name and name != 'tui':
q = os.path.basename(os.path.dirname(x)) ans.append(name)
if q != 'tui': return frozenset(ans)
n.append(q)
return frozenset(n)
def list_kittens() -> None: def list_kittens() -> None: