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
--
Ticket URL: <https://code.djangoproject.com/ticket/32669>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "32669-autoreload-fix.patch.diff" added.
Patch
Old description:
> 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
New description:
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
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32669#comment:1>
* status: new => assigned
* cc: William Schwartz (added)
* version: 3.2 => 4.0
* owner: nobody => Moriyoshi Koizumi
* type: Uncategorized => New feature
* stage: Unreviewed => Accepted
Old description:
> 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
New description:
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.
--
Comment:
It doesn't work in Django 3.1 so I would not call it a regression.
Can you send PR via GitHub?
--
Ticket URL: <https://code.djangoproject.com/ticket/32669#comment:2>
Comment (by William Schwartz):
Looks fine. The one change I'd make is that I'd change
{{{#!python
modspec.name.split(".")[-1] == "__main__"
}}}
to
{{{#!python
modspec.name == "__main__" or modspec.name.endswith(".__main__")
}}}
to avoid dumb corner cases like a module named `foo.my__main__` (which is
how
[https://github.com/python/cpython/blob/fa03efda3dc6ad118788bebc61079cd481c0b24c/Lib/runpy.py#L143
runpy.py] itself deals with it).
--
Ticket URL: <https://code.djangoproject.com/ticket/32669#comment:3>
Comment (by Moriyoshi Koizumi):
> 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/32669#comment:4>
Comment (by Moriyoshi Koizumi):
https://github.com/django/django/pull/14311
--
Ticket URL: <https://code.djangoproject.com/ticket/32669#comment:5>
Comment (by Mariusz Felisiak):
Replying to [comment:4 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/32669#comment:6>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/32669#comment:7>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32669#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"9e4780dedac15adcc04309d0198f4ae34e04cc2a" 9e4780de]:
{{{
#!CommitTicketReference repository=""
revision="9e4780dedac15adcc04309d0198f4ae34e04cc2a"
Fixed #32669 -- Fixed detection when started non-django modules which
aren't packages with "python -m" in autoreloader.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32669#comment:9>