diff mbox series

[bug#68241] gnu: python: Fix sitecustomize.py

Message ID m1sf3djmjg.fsf@fastmail.net
State New
Headers show
Series [bug#68241] gnu: python: Fix sitecustomize.py | expand

Commit Message

Konrad Hinsen Jan. 4, 2024, 12:44 p.m. UTC
* gnu/packages/aux-files/python/sitecustomize.py: normalize sys.prefix
  to deal with situations where it contains "../"

This happens in particular when running Python from a Singularity image
created by Guix. See https://issues.guix.gnu.org/53258.

Change-Id: Ibfe13d7c2a14beaa199f599e64bc0b7bfb500fe8
---
 gnu/packages/aux-files/python/sitecustomize.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


base-commit: 7b0863f07a113caef26fea13909bd97d250b629e

Comments

Konrad Hinsen Jan. 6, 2024, 9:32 a.m. UTC | #1
Konrad Hinsen <konrad.hinsen@fastmail.net> writes:

> * gnu/packages/aux-files/python/sitecustomize.py: normalize sys.prefix
>   to deal with situations where it contains "../"

This patch leads to massive rebuilds for non-trivial environments. I
will submit an alternative that patches Python via a graft.

Cheers,
  Konrad.
Ludovic Courtès Jan. 8, 2024, 8:57 a.m. UTC | #2
Hi Konrad!

Konrad Hinsen <konrad.hinsen@fastmail.net> skribis:

> * gnu/packages/aux-files/python/sitecustomize.py: normalize sys.prefix
>   to deal with situations where it contains "../"
>
> This happens in particular when running Python from a Singularity image
> created by Guix. See https://issues.guix.gnu.org/53258.
>
> Change-Id: Ibfe13d7c2a14beaa199f599e64bc0b7bfb500fe8
> ---
>  gnu/packages/aux-files/python/sitecustomize.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gnu/packages/aux-files/python/sitecustomize.py b/gnu/packages/aux-files/python/sitecustomize.py
> index e2348e0356..82ea91104d 100644
> --- a/gnu/packages/aux-files/python/sitecustomize.py
> +++ b/gnu/packages/aux-files/python/sitecustomize.py
> @@ -37,7 +37,7 @@ import sys
>  major_minor = '{}.{}'.format(*sys.version_info)
>  site_packages_prefix = os.path.join(
>      'lib', 'python' + major_minor, 'site-packages')
> -python_site = os.path.join(sys.prefix, site_packages_prefix)
> +python_site = os.path.normpath(os.path.join(sys.prefix, site_packages_prefix))

IIRC Josselin had a patch for <https://issues.guix.gnu.org/53258>, but I
can’t find it.  Josselin?

Also, do I get it right that the patch you sent fixes more than #53258?

Thanks!

Ludo’.
Konrad Hinsen Jan. 8, 2024, 9:14 a.m. UTC | #3
Hi Ludo,

> Also, do I get it right that the patch you sent fixes more than #53258?

#53258 is two things: a weird error message, and a failure to run valid
Python code, the two being possibly related.

My patch fixes the error message. The Python example that Marek gave
already works fine in today's Guix, so it was probably fixed by
something else as a side effect.

Could the bug that causes the error message also mess up valid Python
code? In theory, yes, but I don't have an example at hand.

Cheers,
  Konrad.
Maxim Cournoyer Jan. 21, 2024, 4:22 a.m. UTC | #4
Hi Konrad,

Konrad Hinsen <konrad.hinsen@fastmail.net> writes:

> Hi Ludo,
>
>> Also, do I get it right that the patch you sent fixes more than #53258?
>
> #53258 is two things: a weird error message, and a failure to run valid
> Python code, the two being possibly related.
>
> My patch fixes the error message. The Python example that Marek gave
> already works fine in today's Guix, so it was probably fixed by
> something else as a side effect.

Oh?  And you tested using the exact same reproducer, using a relocatable
pack?
Konrad Hinsen Jan. 21, 2024, 11:11 a.m. UTC | #5
Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

>> My patch fixes the error message. The Python example that Marek gave
>> already works fine in today's Guix, so it was probably fixed by
>> something else as a side effect.
>
> Oh?  And you tested using the exact same reproducer, using a relocatable
> pack?

Yes, I tested it in a Singularity container.

Cheers,
  konrad.
Maxim Cournoyer Jan. 21, 2024, 6:29 p.m. UTC | #6
Hi Konrad,

Konrad Hinsen <konrad.hinsen@fastmail.net> writes:

> Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:
>
>>> My patch fixes the error message. The Python example that Marek gave
>>> already works fine in today's Guix, so it was probably fixed by
>>> something else as a side effect.
>>
>> Oh?  And you tested using the exact same reproducer, using a relocatable
>> pack?
>
> Yes, I tested it in a Singularity container.

Great, it's now on core-updates.
Konrad Hinsen Jan. 22, 2024, 7:15 a.m. UTC | #7
Maxim Cournoyer <maxim.cournoyer@gmail.com> writes:

> Great, it's now on core-updates.

Thanks!

Konrad.
diff mbox series

Patch

diff --git a/gnu/packages/aux-files/python/sitecustomize.py b/gnu/packages/aux-files/python/sitecustomize.py
index e2348e0356..82ea91104d 100644
--- a/gnu/packages/aux-files/python/sitecustomize.py
+++ b/gnu/packages/aux-files/python/sitecustomize.py
@@ -37,7 +37,7 @@  import sys
 major_minor = '{}.{}'.format(*sys.version_info)
 site_packages_prefix = os.path.join(
     'lib', 'python' + major_minor, 'site-packages')
-python_site = os.path.join(sys.prefix, site_packages_prefix)
+python_site = os.path.normpath(os.path.join(sys.prefix, site_packages_prefix))
 
 try:
     all_sites_raw = os.environ['GUIX_PYTHONPATH'].split(os.path.pathsep)