unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / Atom feed
* python-build-system does not wrap script correctly
@ 2021-11-25  8:50 Foo Chuan Wei
  2021-11-27  5:00 ` Maxim Cournoyer
  0 siblings, 1 reply; 2+ messages in thread
From: Foo Chuan Wei @ 2021-11-25  8:50 UTC (permalink / raw)
  To: guix-devel

I am trying to package "Speedometer" [1]. This is the package
definition:

--8<---------------cut here---------------start------------->8---
(define-public speedometer
  (package
    (name "speedometer")
    (version "2.8")
    (source
     (origin
       (method url-fetch)
       (uri (pypi-uri "Speedometer" version))
       (sha256
        (base32 "0qgpjmahy0wlfszqxg0067ck2xab5k6j42d0ifxg1j281yqnm9bx"))))
    (build-system python-build-system)
    (arguments
     `(#:python ,python-2))
    (propagated-inputs
     `(("python2-urwid" ,python2-urwid)))
    (home-page "https://excess.org/speedometer/")
    (synopsis "Measure and display the rate of data across a network connection")
    (description
     "Console monitor of the rate of data across a network connection or data
being stored in a file.")
    (license license:lgpl2.1+)))
--8<---------------cut here---------------end--------------->8---

It builds and installs successfully. However, when the wrapper script is
run, this error appears:

--8<---------------cut here---------------start------------->8---
Traceback (most recent call last):
  File "/gnu/store/chr1cx6ia0is8s9d07s1nzdla30r6vs1-speedometer-2.8/bin/.speedometer-real", line 11, in <module>
    load_entry_point('Speedometer==2.8', 'console_scripts', 'speedometer')()
  File "/gnu/store/d3jwdk2v7xck82z3y3hs99033m9nkkw0-python2-2.7.17/lib/python2.7/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/gnu/store/d3jwdk2v7xck82z3y3hs99033m9nkkw0-python2-2.7.17/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2852, in load_entry_point
    return ep.load()
  File "/gnu/store/d3jwdk2v7xck82z3y3hs99033m9nkkw0-python2-2.7.17/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2443, in load
    return self.resolve()
  File "/gnu/store/d3jwdk2v7xck82z3y3hs99033m9nkkw0-python2-2.7.17/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2449, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/gnu/store/chr1cx6ia0is8s9d07s1nzdla30r6vs1-speedometer-2.8/bin/speedometer.py", line 2
    export PYTHONPATH="/gnu/store/chr1cx6ia0is8s9d07s1nzdla30r6vs1-speedometer-2.8/lib/python2.7/site-packages:/gnu/store/d3jwdk2v7xck82z3y3hs99033m9nkkw0-python2-2.7.17/lib/python2.7/site-packages:/gnu/store/1iszjcyvb537m6cif7fqrrh95r0sg9wp-python2-urwid-2.1.0/lib/python2.7/site-packages${PYTHONPATH:+:}$PYTHONPATH"
                    ^
SyntaxError: invalid syntax
--8<---------------cut here---------------end--------------->8---

There is apparently something wrong with the wrapper script. What is it?

I worked around the problem by adding this phase:

--8<---------------cut here---------------start------------->8---
(add-after 'unpack 'fix-script
  (lambda _
    (substitute* "setup.py"
      (("'scripts': \\['speedometer.py'\\],")
       "'packages': ['.'],"))))
--8<---------------cut here---------------end--------------->8---

[1]: https://github.com/wardi/speedometer/tree/release-2.8


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: python-build-system does not wrap script correctly
  2021-11-25  8:50 python-build-system does not wrap script correctly Foo Chuan Wei
@ 2021-11-27  5:00 ` Maxim Cournoyer
  0 siblings, 0 replies; 2+ messages in thread
From: Maxim Cournoyer @ 2021-11-27  5:00 UTC (permalink / raw)
  To: chuanwei.foo; +Cc: guix-devel

Hello Foo,

Foo Chuan Wei <chuanwei.foo@hotmail.com> writes:

> I am trying to package "Speedometer" [1]. This is the package
> definition:
>
> (define-public speedometer
>   (package
>     (name "speedometer")
>     (version "2.8")

[...]

This package is 10 years old and uses Python 2.  I hope it is for the
Guix Past channel :-).

> It builds and installs successfully. However, when the wrapper script is
> run, this error appears:
>
> Traceback (most recent call last):
>   File "/gnu/store/chr1cx6ia0is8s9d07s1nzdla30r6vs1-speedometer-2.8/bin/.speedometer-real", line 11, in <module>
>     load_entry_point('Speedometer==2.8', 'console_scripts', 'speedometer')()
>   File "/gnu/store/d3jwdk2v7xck82z3y3hs99033m9nkkw0-python2-2.7.17/lib/python2.7/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
>     return get_distribution(dist).load_entry_point(group, name)
>   File "/gnu/store/d3jwdk2v7xck82z3y3hs99033m9nkkw0-python2-2.7.17/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2852, in load_entry_point
>     return ep.load()
>   File "/gnu/store/d3jwdk2v7xck82z3y3hs99033m9nkkw0-python2-2.7.17/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2443, in load
>     return self.resolve()
>   File "/gnu/store/d3jwdk2v7xck82z3y3hs99033m9nkkw0-python2-2.7.17/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2449, in resolve
>     module = __import__(self.module_name, fromlist=['__name__'], level=0)
>   File "/gnu/store/chr1cx6ia0is8s9d07s1nzdla30r6vs1-speedometer-2.8/bin/speedometer.py", line 2
>     export PYTHONPATH="/gnu/store/chr1cx6ia0is8s9d07s1nzdla30r6vs1-speedometer-2.8/lib/python2.7/site-packages:/gnu/store/d3jwdk2v7xck82z3y3hs99033m9nkkw0-python2-2.7.17/lib/python2.7/site-packages:/gnu/store/1iszjcyvb537m6cif7fqrrh95r0sg9wp-python2-urwid-2.1.0/lib/python2.7/site-packages${PYTHONPATH:+:}$PYTHONPATH"
>                     ^
> SyntaxError: invalid syntax

For the record, I used this to reproduce the problem:

--8<---------------cut here---------------start------------->8---
(use-modules (gnu packages python)
             (gnu packages python-xyz)
             (guix licenses)
             (guix packages)
             (guix download)
             (guix build-system python))

(define speedometer
  (package
    (name "speedometer")
    (version "2.8")
    (source
     (origin
       (method url-fetch)
       (uri (pypi-uri "Speedometer" version))
       (sha256
        (base32 "0qgpjmahy0wlfszqxg0067ck2xab5k6j42d0ifxg1j281yqnm9bx"))))
    (build-system python-build-system)
    (arguments
     `(#:python ,python-2))
    (propagated-inputs
     `(("python2-urwid" ,python2-urwid)))
    (home-page "https://excess.org/speedometer/")
    (synopsis "Measure and display the rate of data across a network connection")
    (description
     "Console monitor of the rate of data across a network connection or data
being stored in a file.")
    (license lgpl2.1+)))

speedometer
--8<---------------cut here---------------end--------------->8---

> There is apparently something wrong with the wrapper script. What is it?

It's because the speedometer script hacks the arg0 path to resolve the
speedometer.py script, which it proceeds to invoke as a python script:
--8<---------------cut here---------------start------------->8---
# EASY-INSTALL-ENTRY-SCRIPT: 'Speedometer==2.8','console_scripts','speedometer'
__requires__ = 'Speedometer==2.8'
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(
        load_entry_point('Speedometer==2.8', 'console_scripts', 'speedometer')()
    )
--8<---------------cut here---------------end--------------->8---

but the 'wrap' phase of the python-build-system has wrapped it (that is,
speedometer.py is now a shell script that wraps speedometer.py):

Perhaps the wrap phase could have known this wasn't a good idea by
looking at the file extension, but in general executables put under bin/
do not have file extensions anyway.

So it's a special case which is not handled by the wrap phase.

I hope that helps!

Maxim


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-27  5:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-25  8:50 python-build-system does not wrap script correctly Foo Chuan Wei
2021-11-27  5:00 ` Maxim Cournoyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).