<commit_before>;;; lang/python/autoload/python.el -*- lexical-binding: t; -*-

(defvar +python-version-cache (make-hash-table :test 'equal)
  "TODO")

;;;###autoload
(defun +python/repl ()
  "Open the Python REPL."
  (interactive)
  (unless python-shell-interpreter
    (user-error "`python-shell-interpreter' isn't set"))
  (pop-to-buffer
   (process-buffer
    (if-let* ((pipenv (executable-find "pipenv"))
              (pipenv-project (pipenv-project-p)))
        (let ((default-directory pipenv-project)
              (python-shell-interpreter-args
               (format "run %s %s"
                       python-shell-interpreter
                       python-shell-interpreter-args))
              (python-shell-interpreter pipenv))
          (run-python nil t t))
      (run-python nil t t)))))

;;;###autoload
(defun +python/open-ipython-repl ()
  "Open an IPython REPL."
  (interactive)
  (let ((python-shell-interpreter "ipython")
        (python-shell-interpreter-args  "-i --pylab --simple-prompt --no-color-info"))
    (+python/repl)))

;;;###autoload
(defun +python/open-jupyter-repl ()
  "Open a Jupyter console."
  (interactive)
  (add-to-list 'python-shell-completion-native-disabled-interpreters "jupyter")
  (let ((python-shell-interpreter "jupyter")
        (python-shell-interpreter-args  "console --simple-prompt"))
    (+python/repl)))

(defun +python--extract-version (prefix str)
  (when str
    (format "%s%s" prefix (cadr (split-string str " ")))))

;;;###autoload
(defun +python-version ()
  "Return the currently installed version of python on your system or active in
the current pipenv.

This is not necessarily aware of env management tools like virtualenv, pyenv or
pipenv, unless those tools have modified the PATH that Emacs picked up when you
started it."
  (condition-case _
      (if-let* ((proot (and (fboundp 'pipenv-project-p)
                            (pipenv-project-p))))
          (let* ((default-directory proot)
                 (v (car (process-lines "pipenv" "run" "python" "--version"))))
            (puthash proot
                     (+python--extract-version "Pipenv " v)
                     +python-version-cache))
        (puthash (or (doom-project-root) default-directory)
                 (+python--extract-version
                  "Python "
                  (car (process-lines python-shell-intepreter "--version")))
                 +python-version-cache))
    (error "Python")))
<commit_msg>lang/python: fix typo in +python-version<commit_after>;;; lang/python/autoload/python.el -*- lexical-binding: t; -*-

(defvar +python-version-cache (make-hash-table :test 'equal)
  "TODO")

;;;###autoload
(defun +python/repl ()
  "Open the Python REPL."
  (interactive)
  (unless python-shell-interpreter
    (user-error "`python-shell-interpreter' isn't set"))
  (pop-to-buffer
   (process-buffer
    (if-let* ((pipenv (executable-find "pipenv"))
              (pipenv-project (pipenv-project-p)))
        (let ((default-directory pipenv-project)
              (python-shell-interpreter-args
               (format "run %s %s"
                       python-shell-interpreter
                       python-shell-interpreter-args))
              (python-shell-interpreter pipenv))
          (run-python nil t t))
      (run-python nil t t)))))

;;;###autoload
(defun +python/open-ipython-repl ()
  "Open an IPython REPL."
  (interactive)
  (let ((python-shell-interpreter "ipython")
        (python-shell-interpreter-args  "-i --pylab --simple-prompt --no-color-info"))
    (+python/repl)))

;;;###autoload
(defun +python/open-jupyter-repl ()
  "Open a Jupyter console."
  (interactive)
  (add-to-list 'python-shell-completion-native-disabled-interpreters "jupyter")
  (let ((python-shell-interpreter "jupyter")
        (python-shell-interpreter-args  "console --simple-prompt"))
    (+python/repl)))

(defun +python--extract-version (prefix str)
  (when str
    (format "%s%s" prefix (cadr (split-string str " ")))))

;;;###autoload
(defun +python-version ()
  "Return the currently installed version of python on your system or active in
the current pipenv.

This is not necessarily aware of env management tools like virtualenv, pyenv or
pipenv, unless those tools have modified the PATH that Emacs picked up when you
started it."
  (condition-case _
      (if-let* ((proot (and (fboundp 'pipenv-project-p)
                            (pipenv-project-p))))
          (let* ((default-directory proot)
                 (v (car (process-lines "pipenv" "run" "python" "--version"))))
            (puthash proot
                     (+python--extract-version "Pipenv " v)
                     +python-version-cache))
        (puthash (or (doom-project-root) default-directory)
                 (+python--extract-version
                  "Python "
                  (car (process-lines python-shell-interpreter "--version")))
                 +python-version-cache))
    (error "Python")))

{'fraction_non_alphanumeric': 0.14840274969672462, 'fraction_numerical': 0.0, 'mean_word_length': 2.452198185624564, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7043906', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1553, 'n_words': 370}