python-django's manage.py tries to use a hard-coded python executable

  • Open
  • quality assurance status badge
Details
2 participants
  • Gabriel Wicki
  • Simon Tournier
Owner
unassigned
Submitted by
Gabriel Wicki
Severity
normal
G
G
Gabriel Wicki wrote on 15 Oct 11:48 +0200
(address . bug-guix@gnu.org)
mjgot2cwzzfhicsyobhubmc3dsbviysha56nqt4c3epp3emdrc@4ovou422lxuv
The python-django package makes the admin utility create a manage.py
file with a hard-coded python interpreter.

$ guix shell python python-django -- django-admin startproject foobar
$ head -n 1 foobar/manage.py
#!/gnu/store/my2j5bzapayk59971z2ryzlajdz569f9-python-toolchain-3.10.7/bin/python

I think this is wrong. The interpreter line should be

#!/usr/bin/env python3

Or am I wrong?
S
S
Simon Tournier wrote on 10 Dec 16:59 +0100
877c87zfz4.fsf@gmail.com
Hi,

On Tue, 15 Oct 2024 at 11:48, Gabriel Wicki <gabriel@erlikon.ch> wrote:

Toggle quote (11 lines)
> The python-django package makes the admin utility create a manage.py
> file with a hard-coded python interpreter.
>
> $ guix shell python python-django -- django-admin startproject foobar
> $ head -n 1 foobar/manage.py
> #!/gnu/store/my2j5bzapayk59971z2ryzlajdz569f9-python-toolchain-3.10.7/bin/python
>
> I think this is wrong. The interpreter line should be
>
> #!/usr/bin/env python3

Well, I don’t know if there is a rationale for this choice. Somehow, my
understanding is: 1. python-django is byte-compiled using one specific
Python interpreter and 2. what is the guarantee that the whole code
byte-compiled with different Python interpreter will run?

Hence, that version of the specific Python interpreter is encoded.

Now, if the purpose of ’django-admin startproject foobar’ is to only
create generic configuration that does not depends on any Django or
Python version, then maybe it could be considered as wrong. :-)

Else I don’t know. I remember having a similar discussion about a
similar Python tool but I am not able to find it back.

Cheers,
simon
G
G
Gabriel Wicki wrote on 11 Dec 12:48 +0100
(name . Simon Tournier)(address . zimon.toutoune@gmail.com)(address . 73816@debbugs.gnu.org)
yb2zy4gw4qtgdi7rqqhy4ix52ljbspifh7l2mvstwcodfglfb4@fvmb24btljly
Hi!

Thanks for your input!

On Tue, Dec 10, 2024 at 04:59:27PM +0100, Simon Tournier wrote:
Toggle quote (3 lines)
> Now, if the purpose of ’django-admin startproject foobar’ is to only
> create generic configuration that does not depends on any Django or
> Python version, then maybe it could be considered as wrong. :-)
I think this is actually the case! The `startproject' script
initializes a more or less empty project including said `manage.py'
script. Now when starting and developing a Django project, all these
files will end up in VCS, might be packaged somewhat later on (if at
all) and executed on a different system, which may or may not have Guix
available. Apart from that, hard-coding that script without any
guarantee whatsoever that this path exists in the system that will run
the code will more likely result in a failure than any kind of success.

If you have any idea on how to patch that and could point me in that
direction, I'll gladly send in a patch or two!
S
S
Simon Tournier wrote on 13 Dec 12:57 +0100
(name . Gabriel Wicki)(address . gabriel@erlikon.ch)(address . 73816@debbugs.gnu.org)
87bjxf6bif.fsf@gmail.com
Hi,

On Wed, 11 Dec 2024 at 12:48, Gabriel Wicki <gabriel@erlikon.ch> wrote:

Toggle quote (3 lines)
> If you have any idea on how to patch that and could point me in that
> direction, I'll gladly send in a patch or two!

It needs to replace the phases something like:

Toggle snippet (29 lines)
1 file changed, 16 insertions(+)
gnu/packages/django.scm | 16 ++++++++++++++++

modified gnu/packages/django.scm
@@ -99,6 +99,22 @@ (define-public python-django-4.2
(setenv "PYTHONPATH" "..")
(apply invoke "python" "runtests.py" test-flags))
(format #t "test suite not run~%"))))
+ (replace 'patch-source-shebangs
+ (lambda _
+ (for-each patch-shebang
+ (find-files "."
+ (lambda (file stat)
+ (and (eq? 'regular (stat:type stat))
+ (not (string-suffix? "py-tpl" file))))
+ #:stat lstat))))
+ (replace 'patch-generated-file-shebangs
+ (lambda _
+ (for-each patch-shebang
+ (find-files "."
+ (lambda (file stat)
+ (and (eq? 'regular (stat:type stat))
+ (not (string-suffix? "py-tpl" file))))
+ #:stat lstat))))
;; XXX: The 'wrap' phase adds native inputs as runtime dependencies,
;; see <https://bugs.gnu.org/25235>. The django-admin script typically
;; runs in an environment that has Django and its dependencies on

Feel free to submit a patch. :-)

Cheers,
simon
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 73816@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 73816
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch