buildroot.busybox.net archive mirror
 help / color / mirror / Atom feed
From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
To: Thomas De Schampheleire <patrickdepinguin@gmail.com>
Cc: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>,
	buildroot@buildroot.org
Subject: Re: [Buildroot] [PATCH 1/2] utils/scanpypi: add setup.py script directory as sys.path[0]
Date: Sun, 25 Jul 2021 23:44:12 +0200	[thread overview]
Message-ID: <20210725234412.4871d645@windsurf> (raw)
In-Reply-To: <20210308134542.22324-1-patrickdepinguin@gmail.com>

On Mon,  8 Mar 2021 14:45:39 +0100
Thomas De Schampheleire <patrickdepinguin@gmail.com> wrote:

> From: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
> 
> Even though the directory containing a package's setup.py was added to
> sys.path, some setup.py implementations rely on the fact that it is placed
> in sys.path[0].
> 
> An example package is 'cram' which failed to be added with scanpypi:
> 
>     Traceback (most recent call last):
>       File "utils/scanpypi", line 756, in <module>
>         main()
>       File "utils/scanpypi", line 703, in main
>         package.load_setup()
>       File "utils/scanpypi", line 303, in load_setup
>         setup = imp.load_module('setup', s_file, s_path, s_desc)
>       File "/usr/lib/python3.8/imp.py", line 234, in load_module
>         return load_source(name, filename, file)
>       File "/usr/lib/python3.8/imp.py", line 171, in load_source
>         module = _load(spec)
>       File "<frozen importlib._bootstrap>", line 702, in _load
>       File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
>       File "<frozen importlib._bootstrap_external>", line 783, in exec_module
>       File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
>       File "/tmp/scanpypi-2pzc5wb_/python-cram/cram-0.7/setup.py", line 44, in <module>
>         long_description=long_description(),
>       File "/tmp/scanpypi-2pzc5wb_/python-cram/cram-0.7/setup.py", line 20, in long_description
>         return open(os.path.join(sys.path[0], 'README.rst')).read()
>     FileNotFoundError: [Errno 2] No such file or directory: '.../buildroot/utils/README.rst'
> 
> The corresponding code from cram's setup.py is:
> 
>     def long_description():
>         """Get the long description from the README"""
>         return open(os.path.join(sys.path[0], 'README.rst')).read()
> 
> Indeed, the Python documentation says:
> 
> https://docs.python.org/3.8/library/sys.html#sys.path
>     "...
>     As initialized upon program startup, the first item of this list,
>     path[0], is the directory containing the script that was used to invoke
>     the Python interpreter.
>     ..."
> 
> Fix this by inserting explicitly at index 0 instead of appending to
> sys.path.
> 
> Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
> ---
>  utils/scanpypi | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Thanks a lot, I've applied both patches. I don't know exactly how that
will behave with PyPi modules in general, but nobody complained, so the
only way to know is to merge those patches, and see if they cause
problems :-)

Thanks!

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

  parent reply	other threads:[~2021-07-25 21:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-08 13:45 [Buildroot] [PATCH 1/2] utils/scanpypi: add setup.py script directory as sys.path[0] Thomas De Schampheleire
2021-03-08 13:45 ` [Buildroot] [PATCH 2/2] utils/scanpypi: allow installation of commands without 'main' method Thomas De Schampheleire
2021-08-05 20:07   ` Peter Korsgaard
2021-07-25 21:44 ` Thomas Petazzoni [this message]
2021-08-05 20:07 ` [Buildroot] [PATCH 1/2] utils/scanpypi: add setup.py script directory as sys.path[0] Peter Korsgaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210725234412.4871d645@windsurf \
    --to=thomas.petazzoni@bootlin.com \
    --cc=buildroot@buildroot.org \
    --cc=patrickdepinguin@gmail.com \
    --cc=thomas.de_schampheleire@nokia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).