question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

runscript: working directory is manage.py location, not script location

See original GitHub issue

As 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:closed
  • Created 7 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
trbscommented, Oct 29, 2016

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 scripts
  • each — perform chdir before each script invocation
  • root — perform chdir to the directory manage.py
  • custom — perform chdir to the directory specified by RUNSCRIPT_CHDIR or --chdir
0reactions
trbscommented, Oct 24, 2017

Thanks !

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found