Opened 4 years ago

Closed 4 years ago

#32669 closed New feature (fixed)

Allow autoreloading of `python -m custom_module runserver`

Reported by: Moriyoshi Koizumi Owned by: Moriyoshi Koizumi
Component: Utilities Version: 4.0
Severity: Normal Keywords: autoreload runserver
Cc: William Schwartz Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mariusz Felisiak)

The original fix [1] only attempted to deal with -m foo.bar where bar is a package and __main__.py exists under foo/bar.

When a dotted name for a module (for example, foo.bar.baz where baz.py resides under foo/bar) is specified like -m foo.bar.baz, the resulting arguments end up being -m foo.bar, which is uncalled for.

[1] https://github.com/django/django/commit/ec6d2531c59466924b645f314ac33f54470d7ac3

Fixed detection when started non-django modules with "python -m" in autoreloader.

Attachments (1)

32669-autoreload-fix.patch.diff (2.3 KB ) - added by Moriyoshi Koizumi 4 years ago.
Patch

Download all attachments as: .zip

Change History (10)

by Moriyoshi Koizumi, 4 years ago

Patch

comment:1 by Moriyoshi Koizumi, 4 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 4 years ago

Cc: William Schwartz added
Description: modified (diff)
Owner: changed from nobody to Moriyoshi Koizumi
Status: newassigned
Summary: Fix for #32314 causing problems with non-package dotted name specified to -mAllow autoreloading of `python -m custom_module runserver`
Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature
Version: 3.24.0

It doesn't work in Django 3.1 so I would not call it a regression.

Can you send PR via GitHub?

comment:3 by William Schwartz, 4 years ago

Looks fine. The one change I'd make is that I'd change

modspec.name.split(".")[-1] == "__main__"

to

modspec.name == "__main__" or modspec.name.endswith(".__main__")

to avoid dumb corner cases like a module named foo.my__main__ (which is how runpy.py itself deals with it).

comment:4 by Moriyoshi Koizumi, 4 years ago

It doesn't work in Django 3.1 so I would not call it a regression.
Can you send PR via GitHub?

I put manage.py under some package like foo/bar/manage.py and run it like -m foo.bar.manage runserver .... This used to run perfectly on 3.1.

in reply to:  4 comment:6 by Mariusz Felisiak, 4 years ago

Replying to Moriyoshi Koizumi:

I put manage.py under some package like foo/bar/manage.py and run it like -m foo.bar.manage runserver .... This used to run perfectly on 3.1.

Can you attach a sample project? It raises ModuleNotFoundError for me.

comment:7 by Mariusz Felisiak, 4 years ago

Has patch: set
Patch needs improvement: set

comment:8 by Mariusz Felisiak, 4 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 9e4780de:

Fixed #32669 -- Fixed detection when started non-django modules which aren't packages with "python -m" in autoreloader.

Note: See TracTickets for help on using tickets.
Back to Top