runscript: working directory is manage.py location, not script location
See original GitHub issueAs per title, when I use runscript
to run a script in e.g. projectroot/app/scripts
, the working directory of this is projectroot
, while it should be projectroot/app/scripts
.
I run the script while being in the projectroot
using a command like:
python manage.py runscript my_script
To replicate:
my_script.py
placed in any app under scripts
:
#imports
import os
#the script
def run(*args):
print(os.getcwd())
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
python: Change the scripts working directory ... - Stack Overflow
I would fancy a solution that would work for any script location, rather than explicitly telling the script where it is. EDIT: os.chdir(os.path....
Read more >RunScript — django-extensions 3.2.1 documentation
We will create a script that deletes all of the questions from the database. To get started create a scripts directory in your...
Read more >django-admin and manage.py
The django-admin script should be on your system path if you installed Django via pip . If it's not in your path, ensure...
Read more >Python does not recognize the path of the folder to run script
Python does not recognize the path of the folder to run script · 1. Click on File > Options & settings > Options....
Read more >Run a Script With a Different Working Directory - Baeldung
In order to meet the dependencies correctly, we need to keep track of the current directory for the context. We'll check how we...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have no strong preference. As an Unix user
chdir
is intuitive for me, but I agree for lots of other people it might not be. (We could also call it--dir-policy
, thinking that--working-directory-policy
is too long 😃 )Also like the
policy
idea, I would add 1 more:none
— use current directory for all scriptseach
— perform chdir before each script invocationroot
— perform chdir to the directory manage.pycustom
— perform chdir to the directory specified byRUNSCRIPT_CHDIR
or--chdir
Thanks !