    ((string-match "\\(/test_[^/]+\\|_test\\)\\.py$" (buffer-file-name)) "pytest")
    ((string-match "\\.py$" (buffer-file-name)) "module")
    (t nil)))
+
+(defun b-python-maybe-pykern-fmt-run ()
+  (when (string-match
+         (concat "^" (expand-file-name "src/radiasoft" "~") ".*")
+         (buffer-file-name))
+    (add-hook 'after-save-hook #'b-python-pykern-fmt-run
+              nil t)))
 
 (defun b-python-sirepo-service-restart (service)
   "Start sirepo service in project root"

    (b-python-template-module t)))

(add-hook 'python-mode-hook
	  '(lambda ()
	     (set (make-local-variable 'compile-command)
		  (b-python-compile-command))
             (abbrev-mode)))

(progn
  (define-key python-mode-map "\C-c\C-m" 'compile)

	(b-python-project-root
	 (directory-file-name (file-name-directory pwd)))))))

(defun b-python-pykern-fmt-run ()
  (shell-command (concat "pykern fmt run "
                         (buffer-file-name)))
  (minibuffer-message "Running pykern fmt")
  (revert-buffer :ignore-auto :noconfirm))

(defun b-python-template nil
  "inserts template according to file name"
  (interactive)
