]> git.immae.eu Git - perso/Immae/Config/dotdrop.git/commitdiff
Add python script
authorIsmaël Bouya <ismael.bouya@fretlink.com>
Sun, 28 Oct 2018 10:42:18 +0000 (11:42 +0100)
committerIsmaël Bouya <ismael.bouya@fretlink.com>
Sun, 28 Oct 2018 10:42:18 +0000 (11:42 +0100)
config.yaml
dotfiles/pam_environment
dotfiles/programming/python/startup_script.py [new file with mode: 0644]

index f33b6ebcce30206b6bff5c27bb6d23fb4e0cf925..9d544f446a37b3c563b634f57f56dc1d10868526 100644 (file)
@@ -118,6 +118,9 @@ dotfiles:
   prog_nodejs_npm:
     dst: ~/.config/npm/npmrc
     src: programming/nodejs/npmrc
+  prog_python_startup:
+    dst: ~/.config/python/startup_script.py
+    src: programming/python/startup_script.py
   remind_0_service:
     actions:
     - systemd_daemon_reload
@@ -171,6 +174,7 @@ profiles:
     include:
     - _prog_haskell
     - _prog_nodejs
+    - _prog_python
   _git:
     dotfiles:
     - git_config_files
@@ -198,6 +202,9 @@ profiles:
   _prog_nodejs:
     dotfiles:
     - prog_nodejs_npm
+  _prog_python:
+    dotfiles:
+    - prog_python_startup
   _shell_bash:
     dotfiles:
     - shell_bash_profile
index 09172e1db41390b1156edcb56ee4e2b7048ac68e..02741badfb305a686c61e1078a6e538c11a5f058 100644 (file)
@@ -16,6 +16,11 @@ VISUAL                               DEFAULT="vim"
 PAGER                          DEFAULT="less"
 BROWSER                                DEFAULT="firefox"
 
+# Python
+IPYTHONDIR                     DEFAULT="${XDG_CONFIG_HOME}/ipython"
+JUPYTER_CONFIG_DIR             DEFAULT="${XDG_CONFIG_HOME}/jupyter"
+PYTHONSTARTUP                  DEFAULT="${XDG_CONFIG_HOME}/python/startup_script.py"
+
 # VIM
 VIMINIT                                DEFAULT=":source ${XDG_CONFIG_HOME}/vim/vimrc"
 
diff --git a/dotfiles/programming/python/startup_script.py b/dotfiles/programming/python/startup_script.py
new file mode 100644 (file)
index 0000000..403afe5
--- /dev/null
@@ -0,0 +1,52 @@
+import sys as sys_
+
+# Adapted from /usr/lib/python3.7/site.py # enablerlcompleter
+def register_readline():
+    import os
+    import atexit
+    try:
+        import readline
+        import rlcompleter
+    except ImportError:
+        return
+
+    # Reading the initialization (config) file may not be enough to set a
+    # completion key, so we set one first and then read the file.
+    readline_doc = getattr(readline, '__doc__', '')
+    if readline_doc is not None and 'libedit' in readline_doc:
+        readline.parse_and_bind('bind ^I rl_complete')
+    else:
+        readline.parse_and_bind('tab: complete')
+
+    try:
+        readline.read_init_file()
+    except OSError:
+        # An OSError here could have many causes, but the most likely one
+        # is that there's no .inputrc file (or .editrc file in the case of
+        # Mac OS X + libedit) in the expected location.  In that case, we
+        # want to ignore the exception.
+        pass
+
+    if readline.get_current_history_length() == 0:
+        # If no history was loaded, default to .python_history.
+        # The guard is necessary to avoid doubling history size at
+        # each interpreter exit when readline was already configured
+        # through a PYTHONSTARTUP hook, see:
+        # http://bugs.python.org/issue5845#msg198636
+        environ = os.environ.get("XDG_STATE_HOME") or os.environ.get("XDG_DATA_HOME")
+        if environ is not None:
+            if not os.path.exists(os.path.join(environ, "python")):
+                os.mkdir(os.path.join(environ, "python"))
+            history = os.path.join(environ, "python", "history")
+        else:
+            history = os.path.join(os.path.expanduser('~'),
+                                   '.python_history')
+        try:
+            readline.read_history_file(history)
+        except OSError:
+            pass
+        atexit.register(readline.write_history_file, history)
+
+sys_.__interactivehook__ = register_readline
+
+del sys_