GNU bug report logs - #73816
python-django's manage.py tries to use a hard-coded python executable

Previous Next

Package: guix;

Reported by: Gabriel Wicki <gabriel <at> erlikon.ch>

Date: Tue, 15 Oct 2024 09:50:02 UTC

Severity: normal

To reply to this bug, email your comments to 73816 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guix <at> gnu.org:
bug#73816; Package guix. (Tue, 15 Oct 2024 09:50:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Gabriel Wicki <gabriel <at> erlikon.ch>:
New bug report received and forwarded. Copy sent to bug-guix <at> gnu.org. (Tue, 15 Oct 2024 09:50:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Gabriel Wicki <gabriel <at> erlikon.ch>
To: bug-guix <at> gnu.org
Subject: python-django's manage.py tries to use a hard-coded python executable
Date: Tue, 15 Oct 2024 11:48:44 +0200
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?




Information forwarded to bug-guix <at> gnu.org:
bug#73816; Package guix. (Tue, 10 Dec 2024 16:51:04 GMT) Full text and rfc822 format available.

Message #8 received at 73816 <at> debbugs.gnu.org (full text, mbox):

From: Simon Tournier <zimon.toutoune <at> gmail.com>
To: Gabriel Wicki <gabriel <at> erlikon.ch>, 73816 <at> debbugs.gnu.org
Subject: Re: bug#73816: python-django's manage.py tries to use a hard-coded
 python executable
Date: Tue, 10 Dec 2024 16:59:27 +0100
Hi,

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

> 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




Information forwarded to bug-guix <at> gnu.org:
bug#73816; Package guix. (Wed, 11 Dec 2024 11:49:01 GMT) Full text and rfc822 format available.

Message #11 received at 73816 <at> debbugs.gnu.org (full text, mbox):

From: Gabriel Wicki <gabriel <at> erlikon.ch>
To: Simon Tournier <zimon.toutoune <at> gmail.com>
Cc: 73816 <at> debbugs.gnu.org
Subject: Re: bug#73816: python-django's manage.py tries to use a hard-coded
 python executable
Date: Wed, 11 Dec 2024 12:48:31 +0100
Hi!

Thanks for your input!

On Tue, Dec 10, 2024 at 04:59:27PM +0100, Simon Tournier wrote:
> 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!




Information forwarded to bug-guix <at> gnu.org:
bug#73816; Package guix. (Fri, 13 Dec 2024 11:59:02 GMT) Full text and rfc822 format available.

Message #14 received at 73816 <at> debbugs.gnu.org (full text, mbox):

From: Simon Tournier <zimon.toutoune <at> gmail.com>
To: Gabriel Wicki <gabriel <at> erlikon.ch>
Cc: 73816 <at> debbugs.gnu.org
Subject: Re: bug#73816: python-django's manage.py tries to use a hard-coded
 python executable
Date: Fri, 13 Dec 2024 12:57:44 +0100
Hi,

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

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

--8<---------------cut here---------------start------------->8---
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
--8<---------------cut here---------------end--------------->8---

Feel free to submit a patch. :-)

Cheers,
simon




This bug report was last modified 189 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.