django icon indicating copy to clipboard operation
django copied to clipboard

Tab completion when executing as `./manage.py`

Open yankyhoffman opened this issue 2 years ago • 1 comments

Considering that the manage.py file has its executable bit set users will be able to execute the script from the project root directory and they will need to prepend ./ to the script name.

yankyhoffman avatar Aug 20 '21 18:08 yankyhoffman

Hello @yankyhoffman! Thank you for your contribution 💪

As it's your first contribution be sure to check out the patch review checklist.

If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!

If you have any design or process questions then you can ask in the Django forum.

Welcome aboard ⛵️!

github-actions[bot] avatar Aug 20 '21 18:08 github-actions[bot]

Hello @yankyhoffman ! I'm doing some PR cleanup and I would be happy to review this one but I'm not sure what's the goal. Could you please comment on what is exactly that this change is providing? An example could go a long way!

Thank you.

nessita avatar May 05 '23 12:05 nessita

Sure @nessita,

The extras/django_bash_completion file adds tab completion to bash, i.e. when you type

$ python manage.py run<TAB>

it'll complete to

$ python manage.py runserver

However the completion activates if the words django-admin or manage.py are typed which is the case when running these commands prefixed with the python executable.

However considering that the file manage.py has is executable bit set and can be executed via the command line as such

$ ./manage.py runserver

There is a need to tell the completion to look for the word ./manage.py (verbatim along with the . and /).

I hope that clarifies the point of this PR.

yankyhoffman avatar May 05 '23 13:05 yankyhoffman

Thank you @yankyhoffman. I'm +1 to this change, though I can't succeed in testing it locally. In all fairness, I can't test it even with using the Django main repo. What I get when doing:

python manage.py run<TAB>

is the following (I pressed <TAB> 3 times here, each time manage.py: command not found was printed, and then I pressed <enter>, getting the final error message):

$ python manage.py runmanage.py: command not found
manage.py: command not found
manage.py: command not found

Unknown command: 'run'
Type 'manage.py help' for usage.

So, while this is not strictly related to your change, would you have any further advice to help us test this with and without your patch? Perhaps what I'm experiencing is a bug I should report separately?

nessita avatar May 08 '23 12:05 nessita

@nessita this file is made to aid with consumers of the django library, did you try in a new faux project where django is one of its dependencies?

I would try it as follows:

  • $ cd newdir
  • $ python -m venv .venv
  • $ . .venv/bin/activate
  • $ pip install django
  • $ django-admin startproject webapp .

And from there you can try running manage.py commands

yankyhoffman avatar May 08 '23 13:05 yankyhoffman

@nessita this file is made to aid with consumers of the django library, did you try in a new faux project where django is one of its dependencies?

Thanks for your detailed answer but of course I was running the test within an venv with Django installed. I tried again in a clean venv, using latest Django (main from repo), and the autocompletion still does not work. As mentioned, this is not an issue with your PR since I'm running the django_bash_completion from main.

I'll try to debug further!

nessita avatar May 08 '23 18:05 nessita

I found out what the issue is. As the script says, the autocompletion does not work for python manage.py <TAB TAB>, only works for ./manage.py <TAB TAB>. So the issue I had was that, since I've always invoked the manage command prefixing python, the script would not work.

Without prefixing python, the code in main does offer autocompletion of django-admin and ./manage.py. So, on the one hand, I'm not sure how python manage.py run<TAB-TAB> is working for you (I'm using linux/ubuntu, what OS/distro are you using?). On the other hand, given my test this change would not be needed for ./manage.py to autocomplete.

What do you think?

nessita avatar May 08 '23 19:05 nessita

Closing due to inactivity and because from my IRL testing, the current autocompletion already works for ./manage.py. Feel free to re-open if that's not the case for you, if so please add instructions to reproduce. Thanks!

nessita avatar May 26 '23 12:05 nessita