elpy
elpy copied to clipboard
Elpy 1.28 (elpy-django-runserver ARG) returns elpy-django-runserver: Wrong type argument: stringp, nil
Summary
The sequence key binded to the command elpy-django-runserver
returns error when called in Elpy 1.28.
I've tested C-c C-x c
and works. I'm using that for time being but would like to know what may be wrong with the runserver command.
Steps to reproduce
- activate virtual environment with django
M-: (pyvenv-activate "venv")
-
C-c C-x r
Error: elpy-django-runserver: Wrong type argument: stringp, nil
My configuration
OS
Emacs 26.3 Ubuntu 18
pip freeze > requirements.txt
Django==2.2.5
pytz==2019.2
sqlparse==0.3.0
Result of (elpy-config)
Elpy Configuration
Virtualenv........: (/home/jon/Desktop/mysite/venv/)
RPC Python........: 3.7.2 (/home/jon/Desktop/mysite/venv/bin/python)
Interactive Python: python3 (/home/jon/Desktop/mysite/venv/bin/python3)
Emacs.............: 26.3
Elpy..............: 1.28.0
Jedi..............: Not found (0.15.1 available)
Rope..............: Not found (0.14.0 available)
Autopep8..........: Not found (1.4.4 available)
Yapf..............: Not found (0.28.0 available)
Black.............: Not found (19.3b0 available)
Syntax checker....: Not found (flake8)
Elpy configuration in my init.el
(setq python-shell-interpreter "python3"
python-indent-offset 4)
(elpy-enable)
(defun pyvenv-venv-dwim ()
"Ask to activate a virtual environment or deactivate one if active."
(interactive)
(if pyvenv-virtual-env
(pyvenv-deactivate)
(call-interactively 'pyvenv-activate)))
(add-hook 'elpy-mode-hook (lambda () (define-key elpy-mode-map (kbd "C-c v") 'pyvenv-venv-dwim)))
I wasn't able to reproduce this.
Could you use (toggle-debug-on-error)
and post the backtrace ?
@galaunay
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
directory-file-name(nil)
elpy-django-runserver(nil)
funcall-interactively(elpy-django-runserver nil)
call-interactively(elpy-django-runserver nil nil)
command-execute(elpy-django-runserver)
called when visiting manage.py
. If I attempt the same but using C-c C-x c runserver RET
the dev server launches.
Apparently Elpy is failing to detect the root of your project.
The problem is that Elpy is using the presence of some files (.git
, .svn
, .projectile
, setup.py
, ...) to infer what is the project root.
Because it is not checking for manage.py
or django-admin.py
files at the moment, it may fail to get the project root in some situations.
I made a PR (#1668) to fix this.
In the meantime, you can add a .projectile
file at the root of your project (alongside manage.py
?) and it should fix the problem.
@galaunay yes, I was about to comment back. I realized this right now while trying the command on a project with a git repo.