cookiecutter / cookiecutter-django

Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.
https://cookiecutter-django.readthedocs.io
BSD 3-Clause "New" or "Revised" License
11.79k stars 2.84k forks source link

Fresh install results in bash $'\r': command not found error #4675

Open antsoftwaredev opened 8 months ago

antsoftwaredev commented 8 months ago

What happened?

Fresh install of a project using django cookiecutter (using VS Code and Docker) results in new bash terminals not being configured correctly.

What should've happened instead?

The entrypoint should be executed and a bash terminal that can properly execute manage.py commands should be created.

Additional details

Project generation options: The only ones that seem to matter are: windows: Y editor: VS Code use_docker: Y

Simply opening a new bash terminal results in the following output:

bash: $'\r': command not found
bash: $'\r': command not found
bash: $'\r': command not found
: No such file or directory
bash: $'\r': command not found
: invalid option name
: invalid option name
: invalid option name
bash: $'\r': command not found
Agent pid 411
bash: $'\r': command not found
bash: $'\r': command not found
dev-user@e1580576785b:/app$ 

In previous versions of the cookiecutter template that did not try to integrate VS Code, I had my own solution to creating valid bash terminals (simply passing in a start script to the bash command line, which called entrypoint and executed the bash shell)

browniebroke commented 7 months ago

Any idea what might cause this and how to fix it @masavini ?

alhuede-thncs commented 5 months ago

The issue seems to be if the bashrc.override.sh has CRLF line endings when the container is built. If you change the line endings to LF, rebuild the container, the bashrc.override.sh script runs correctly.

browniebroke commented 5 months ago

Thanks for the investigation, PR welcome

alhuede-thncs commented 5 months ago

Thanks for the investigation, PR welcome

I don't have the time to look into how to enforce LF line endings while generating the shell script. At the very least this thread can indicate to others what must be done if they have the same issue.

olddataduffer commented 1 month ago

Hi, I followed your advice and removed the CRs from bashrc.override.sh using Notepad++ as outlined here: https://stackoverflow.com/questions/17510688/single-script-to-run-in-both-windows-batch-and-linux-bash/48938482#48938482 I would love to know how to do this in VScode, but I can't brane anymore.

alhuede-thncs commented 1 month ago

Hi, I followed your advice and removed the CRs from bashrc.override.sh using Notepad++ as outlined here: https://stackoverflow.com/questions/17510688/single-script-to-run-in-both-windows-batch-and-linux-bash/48938482#48938482 I would love to know how to do this in VScode, but I can't brane anymore.

Sorry I'm not near my computer to post a screen shot, but in the bottom right of the screen you can see a little "CRLF". Click that and then choose LF.

olddataduffer commented 1 month ago

Hi, yeah, I tried that but it didn't work. VScode seems to pick up the CRLF from the override shell script file. Changing it to LF only only works when you stop and restart the shell. But that causes the override script to run so you're back to square one. But thank you for the suggestion. I really do appreciate it.

alx-uta commented 1 month ago

I had this exact issue in the last couple of days.

In order to fix it I had to do the following change in {{cookiecutter.project_slug}}\.devcontainer\devcontainer.json

-   "postCreateCommand": "cat .devcontainer/bashrc.override.sh >> ~/.bashrc"
+   "postCreateCommand": "cat .devcontainer/bashrc.override.sh >> ~/.bashrc; sed -i 's/\r$//' ~/.bashrc"