Recently while debugging the behavior of an external package in an emacs -Q session, I came up with the below.
(defmacro emacs-pkg-debug-setup (pkg-alist &rest body)
"Install packages in PKG-ALIST and evaluate BODY.
Each element of PKG-ALIST has the form (((ID . LOCATION) . (PKG1 PKG2 ..)) ..).
The ID and LOCATION are the same as the ones in `package-archives'.
PKG1, PKG2, .. are package names from the ID archive.
1. Launch 'emacs -Q'.
2. Copy this macro definition to its scratch buffer and evaluate it.
3. Evaluate a minimum working example using this macro as below:
(declare (indent 1) (debug t))
(setq user-emacs-directory (concat temporary-file-directory
(getenv "USER") "/" ".emacs.d-debug/"))
(setq package-user-dir (concat user-emacs-directory "elpa/"))
(let ((pkgs ()))
(dolist (archive-alist ,pkg-alist)
(add-to-list 'package-archives (car archive-alist) :append)
(setq pkgs (append pkgs (cdr archive-alist))))
(dolist (pkg pkgs)
Then anyone can safe evaluate just that little form in a fresh emacs -Q session, and let the emacs-pkg-debug-setup macro handle the package-archives updating and package installation. The packages get installed to "/tmp/$USER/.emacs.d-debug/elpa/" by default.