From 93a127beed093821697aa340400f95b5e2e33582 Mon Sep 17 00:00:00 2001 From: GodSaveTheDoge <51802433+GodSaveTheDoge@users.noreply.github.com> Date: Wed, 9 Feb 2022 22:50:18 +0100 Subject: [PATCH] Made the world slightly worse --- README.md | 3 ++- star/__init__.py | 28 ++++++++++++++++++++++++++++ star/__main__.py | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 star/__init__.py create mode 100644 star/__main__.py diff --git a/README.md b/README.md index 1cb708c..8363447 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # Phpython - +Are you tired of writing so many import statements? +Fear not, with Phpython you can just `from star import *` diff --git a/star/__init__.py b/star/__init__.py new file mode 100644 index 0000000..be287f0 --- /dev/null +++ b/star/__init__.py @@ -0,0 +1,28 @@ +# How this works: +# +# - Make a list of everyhing importable and expose it with __all__ +# - Python fetches __all__ and tries to import everything +# - Via __getattr__ when the stuff starts getting imported by python, import +# the required module and return it +# - Profit ??? +import sys +import os + +mods = [ + [ + f.split(".", 1)[0] + for f in os.listdir(spath) + if f.endswith(".py") + or ( + os.path.isdir(f) + and os.path.exists(os.path.join(f, "__init__.p__init__.py")) + ) + ] + for spath in sys.path + if os.path.exists(spath) +] +__all__ = [f for m in mods for f in m] +__path__ = [] + +def __getattr__(name): + return __import__(name) diff --git a/star/__main__.py b/star/__main__.py new file mode 100644 index 0000000..58aa189 --- /dev/null +++ b/star/__main__.py @@ -0,0 +1 @@ +breakpoint()