From 85bc9012a01f910a8c431d5aa698847a180e208c Mon Sep 17 00:00:00 2001 From: Pavel Egorov Date: Tue, 17 Mar 2026 19:08:57 +0300 Subject: [python] add pythonrc --- .config/pythonrc.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .config/pythonrc.py (limited to '.config/pythonrc.py') diff --git a/.config/pythonrc.py b/.config/pythonrc.py new file mode 100644 index 0000000..febde4e --- /dev/null +++ b/.config/pythonrc.py @@ -0,0 +1,40 @@ +_auto_imports = [ + {"name": "sys", "module": "sys"}, + {"name": "os", "module": "os"}, + {"name": "Path", "module": "pathlib", "object": "Path"}, + {"name": "dt", "module": "datetime"}, + {"name": "collections", "module": "collections"}, + {"name": "pprint", "module": "pprint", "object": "pprint"}, + {"name": "it", "module": "itertools"}, + {"name": "tempfile", "module": "tempfile"}, + {"name": "subprocess", "module": "subprocess"}, + {"name": "json", "module": "json"}, +] + +def _autoimport(): + import importlib + + print('Auto importing libs:') + + for target in sorted(_auto_imports, key=lambda x: x["name"].lower()): + try: + module = importlib.import_module(target["module"]) + except Exception: + continue + + obj = getattr(module, target["object"]) if target.get("object") else module + globals()[target["name"]] = obj + + if target.get("object"): + what = f'{target["object"]} from {target["module"]}' + else: + what = f'{target["module"]}' + + if target["module"] == target["name"]: + named = '' + else: + named = f' as {target["name"]}' + + print(f'\t{what}{named}') + +_autoimport() -- cgit v1.3