diff options
| author | Pavel Egorov <[email protected]> | 2026-03-17 19:08:57 +0300 |
|---|---|---|
| committer | Pavel Egorov <[email protected]> | 2026-03-17 19:08:57 +0300 |
| commit | 85bc9012a01f910a8c431d5aa698847a180e208c (patch) | |
| tree | fae54fd7b8bf88b0aeac4c6f44a91f7ef86d2f34 /.config | |
| parent | b63f9dc3b0358a367c8aa0ee08e825bf661b4fc1 (diff) | |
| download | dotfiles-85bc9012a01f910a8c431d5aa698847a180e208c.tar.gz dotfiles-85bc9012a01f910a8c431d5aa698847a180e208c.zip | |
[python] add pythonrc
Diffstat (limited to '.config')
| -rw-r--r-- | .config/fish/conf.d/python.fish | 4 | ||||
| -rw-r--r-- | .config/pythonrc.py | 40 |
2 files changed, 43 insertions, 1 deletions
diff --git a/.config/fish/conf.d/python.fish b/.config/fish/conf.d/python.fish index b3b5eec..9ea8f6e 100644 --- a/.config/fish/conf.d/python.fish +++ b/.config/fish/conf.d/python.fish | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | if type -q pyenv | 1 | if type -q pyenv && status is-interactive |
| 2 | pyenv init - | source | 2 | pyenv init - | source |
| 3 | end | 3 | end |
| 4 | |||
| 5 | set -x PYTHONSTARTUP "$XDG_CONFIG_HOME/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 @@ | |||
| 1 | _auto_imports = [ | ||
| 2 | {"name": "sys", "module": "sys"}, | ||
| 3 | {"name": "os", "module": "os"}, | ||
| 4 | {"name": "Path", "module": "pathlib", "object": "Path"}, | ||
| 5 | {"name": "dt", "module": "datetime"}, | ||
| 6 | {"name": "collections", "module": "collections"}, | ||
| 7 | {"name": "pprint", "module": "pprint", "object": "pprint"}, | ||
| 8 | {"name": "it", "module": "itertools"}, | ||
| 9 | {"name": "tempfile", "module": "tempfile"}, | ||
| 10 | {"name": "subprocess", "module": "subprocess"}, | ||
| 11 | {"name": "json", "module": "json"}, | ||
| 12 | ] | ||
| 13 | |||
| 14 | def _autoimport(): | ||
| 15 | import importlib | ||
| 16 | |||
| 17 | print('Auto importing libs:') | ||
| 18 | |||
| 19 | for target in sorted(_auto_imports, key=lambda x: x["name"].lower()): | ||
| 20 | try: | ||
| 21 | module = importlib.import_module(target["module"]) | ||
| 22 | except Exception: | ||
| 23 | continue | ||
| 24 | |||
| 25 | obj = getattr(module, target["object"]) if target.get("object") else module | ||
| 26 | globals()[target["name"]] = obj | ||
| 27 | |||
| 28 | if target.get("object"): | ||
| 29 | what = f'{target["object"]} from {target["module"]}' | ||
| 30 | else: | ||
| 31 | what = f'{target["module"]}' | ||
| 32 | |||
| 33 | if target["module"] == target["name"]: | ||
| 34 | named = '' | ||
| 35 | else: | ||
| 36 | named = f' as {target["name"]}' | ||
| 37 | |||
| 38 | print(f'\t{what}{named}') | ||
| 39 | |||
| 40 | _autoimport() | ||
