                (make-local-variable flycheck-executable-variable)
                (setf (symbol-value flycheck-executable-variable)
                      (with-temp-buffer
-                       (if (zerop
-                            (condition-case err
-                                (call-process "poetry" nil t nil "run" "which" executable-name)
-                              (error (message "%s" (error-message-string err)) nil)))
-                           (string-trim (buffer-string))
-                         nil))))
+                       (when (condition-case err
+                                 (zerop (call-process "poetry" nil t nil "run" "which" executable-name))
+                               (error (message "%s" (error-message-string err)) nil))
+                         (string-trim (buffer-string))))))
               ((executable-find executable-name)
                (make-local-variable flycheck-executable-variable)
                (setf (symbol-value flycheck-executable-variable) executable-name)))))

       (or (executable-find "pre-commit")
           (member "pre-commit" requirements))))

(defun python-project-requirements-from-file (&optional file-path)
  (let* ((requirements-dir (locate-dominating-file default-directory "requirements.txt"))
         (requirements-file
          (or (and file-path
                   (file-exists-p file-path)
                   file-path)
              (and requirements-dir
                   (concat requirements-dir "requirements.txt")))))
    (when requirements-file
      (with-temp-buffer
        (insert-file-contents requirements-file)
        (goto-char (point-min))
        (string-lines (string-trim (buffer-string)))))))

;; https://pip.pypa.io/en/stable/cli/pip_install/#requirements-file-format
(defun python-parse-requirement-spec (req)
  (save-match-data
    (cond ((not (null (or (string-match "\\(-r\\|--requirement\\) +\\(.+\\)$" req)
                          (string-match "\\(-c\\|--constraint\\) +\\(.+\\)$" req))))
           (mapcar 'python-parse-requirement-spec
                   (python-project-requirements-from-file
                    (match-string-no-properties 1 req))))
          ;; TODO: fetch the package and read the setup.cfg or setup.py files to
          ;; extract dependencies
          ((not (null (string-match "\\(-e\\|--editable\\) +\\(.+\\)$" req)))
           nil)
          ;; Options
          ((not (null (string-match "--[a-zA-Z0-9-_]+" req)))
           nil)
          ;; Requirement specifiers
          (t (let* ((requirement-spec (split-string req ";\\|@\\|--"))

(require 'cl-lib)
(require 'subr-x)
(require 'let-alist)
(require 'rx)

(set-locale-environment "UTF-8")
(custom-autoload 'package-selected-packages "package")
