elpy icon indicating copy to clipboard operation
elpy copied to clipboard

Elpy 1.28 (elpy-django-runserver ARG) returns elpy-django-runserver: Wrong type argument: stringp, nil

Open lljr opened this issue 5 years ago • 4 comments

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

  1. activate virtual environment with django M-: (pyvenv-activate "venv")
  2. 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)))

lljr avatar Sep 09 '19 22:09 lljr

I wasn't able to reproduce this.

Could you use (toggle-debug-on-error) and post the backtrace ?

galaunay avatar Sep 10 '19 20:09 galaunay

@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.

lljr avatar Sep 21 '19 17:09 lljr

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 avatar Sep 24 '19 15:09 galaunay

@galaunay yes, I was about to comment back. I realized this right now while trying the command on a project with a git repo.

lljr avatar Sep 24 '19 17:09 lljr