summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2021-03-27 15:15:25 +0100
committerMarcel Hellkamp <marc@gsites.de>2021-03-27 15:15:25 +0100
commita1e603a7b34d4016050bcfb6a8248a04e752f120 (patch)
treedb2dc79c69ce12d12e8975c5f42bbf69464ec7bf
parentf9b1849db4dd724e36a93a1032be592193fba581 (diff)
downloadbottle-a1e603a7b34d4016050bcfb6a8248a04e752f120.tar.gz
fix #1226: Reloading fails for packages started with `python -m`
-rwxr-xr-xbottle.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/bottle.py b/bottle.py
index 23fff76..c32c7f3 100755
--- a/bottle.py
+++ b/bottle.py
@@ -3669,6 +3669,10 @@ def run(app=None,
os.close(fd) # We only need this file to exist. We never write to it
while os.path.exists(lockfile):
args = [sys.executable] + sys.argv
+ if getattr(sys.modules.get('__main__'), '__package__', None):
+ # If a package was loaded with `python -m`, then `sys.argv`
+ # is wrong and needs fixing in some cases. See #1336
+ args[1:1] = ["-m", sys.modules['__main__'].__package__]
environ = os.environ.copy()
environ['BOTTLE_CHILD'] = 'true'
environ['BOTTLE_LOCKFILE'] = lockfile