Re: Memoizing macro values

2022-12-21 Thread Miro Hrončok

On 21. 12. 22 12:21, Miro Hrončok wrote:

On 21. 12. 22 12:10, Florian Weimer wrote:

Could you bring this to Fedora (rawhide in 37 preferably)?


Rawhide for sure, but there is another change in progress now and I'd like to 
ship that first. I have this on my TODO list and will eventually get to this.


Fedora RFE: https://bugzilla.redhat.com/2155505

--
Miro Hrončok
--
Phone: +420777974800
IRC: mhroncok

___
Rpm-list mailing list
Rpm-list@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-list


Re: Memoizing macro values

2022-12-21 Thread Florian Weimer
* Miro Hrončok:

> On 21. 12. 22 11:40, Miro Hrončok wrote:
>> On 21. 12. 22 11:17, Florian Weimer wrote:
>>> In Fedora, we have this:
>>>
>>> /usr/lib/rpm/macros.d/macros.python:%python_sitelib
>>> %(RPM_BUILD_ROOT= %{__python} -Esc "import sysconfig;
>>> print(sysconfig.get_path('purelib', vars={'platbase': '%{_prefix}',
>>> 'base': '%{_prefix}'}))")
>>> /usr/lib/rpm/macros.d/macros.python3:%python3_sitelib
>>> %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig;
>>> print(sysconfig.get_path('purelib', vars={'platbase': '%{_prefix}',
>>> 'base': '%{_prefix}'}))")
>>>
>>> This is a %define-style macro, so the macro gets re-evaluated for every
>>> expansion.  It can make spec file operations really, really slow.
>>>
>>> It's possible to work around this in spec files like this:
>>>
>>> %{?python3_sitearch: %global python3_sitearch %{python3_sitearch}}
>>>
>>> But this is quite ugly, and I wonder if there is a nice way to do it
>>> directly in the macros file instead.  I think I know how do it with Lua,
>>> but maybe there is a better way?
>> This works (using random to demonstarte the behavior:
>> %_python3_random %(RPM_BUILD_ROOT= %{__python3} -Ic "import random;
>> print(random.randint(0,100))")
>> %python3_random %{?!_python3_random_cached:%{global
>> _python3_random_cached %_python3_random}}%_python3_random_cached
>> $ rpm --eval '%python3_random %python3_random %python3_random
>> %python3_random %python3_random'
>> 42 42 42 42 42
>> Note that %python3_sitlib must be evaluated after Python is
>> installed so maybe there must be some "non-empty" conditional added
>> as well.

Yes, that's similar to what I'd have done with Lua.

> This should do:
>
> %_python3_random %(RPM_BUILD_ROOT= %{__python3} -Ic "import random;
>  print(i if (i := random.randint(0,100)) > 75 else '')")
> %python3_random %["%?_python3_random_cached" == "" ? "%{global
>  _python3_random_cached %_python3_random}" :
> ""]%_python3_random_cached
>
> $ rpm --eval '%python3_random %python3_random %python3_random
> %python3_random %python3_random'
>87 87

Could you bring this to Fedora (rawhide in 37 preferably)?  I think it
will really help package maintainers.  I did apply the workaround to
samba because it took a minute or so to process the spec file (they
follow the packaging guidelines to the letter and have hundreds of lines
with %python3_sitearch), but it would be nice to implement this
centrally.

Another package that benefits is python-pynn, and there I don't quite
see the source of the slowness.

Thanks,
Florian

___
Rpm-list mailing list
Rpm-list@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-list


Re: Memoizing macro values

2022-12-21 Thread Miro Hrončok

On 21. 12. 22 12:10, Florian Weimer wrote:

Could you bring this to Fedora (rawhide in 37 preferably)?


Rawhide for sure, but there is another change in progress now and I'd like to 
ship that first. I have this on my TODO list and will eventually get to this.


--
Miro Hrončok
--
Phone: +420777974800
IRC: mhroncok

___
Rpm-list mailing list
Rpm-list@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-list


Memoizing macro values

2022-12-21 Thread Florian Weimer
In Fedora, we have this:

/usr/lib/rpm/macros.d/macros.python:%python_sitelib %(RPM_BUILD_ROOT= 
%{__python} -Esc "import sysconfig; print(sysconfig.get_path('purelib', 
vars={'platbase': '%{_prefix}', 'base': '%{_prefix}'}))")
/usr/lib/rpm/macros.d/macros.python3:%python3_sitelib %(RPM_BUILD_ROOT= 
%{__python3} -Ic "import sysconfig; print(sysconfig.get_path('purelib', 
vars={'platbase': '%{_prefix}', 'base': '%{_prefix}'}))")

This is a %define-style macro, so the macro gets re-evaluated for every
expansion.  It can make spec file operations really, really slow.

It's possible to work around this in spec files like this:

%{?python3_sitearch: %global python3_sitearch %{python3_sitearch}}

But this is quite ugly, and I wonder if there is a nice way to do it
directly in the macros file instead.  I think I know how do it with Lua,
but maybe there is a better way?

Thanks,
Florian

___
Rpm-list mailing list
Rpm-list@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-list


Re: Memoizing macro values

2022-12-21 Thread Miro Hrončok

On 21. 12. 22 11:17, Florian Weimer wrote:

In Fedora, we have this:

/usr/lib/rpm/macros.d/macros.python:%python_sitelib %(RPM_BUILD_ROOT= %{__python} -Esc 
"import sysconfig; print(sysconfig.get_path('purelib', vars={'platbase': 
'%{_prefix}', 'base': '%{_prefix}'}))")
/usr/lib/rpm/macros.d/macros.python3:%python3_sitelib %(RPM_BUILD_ROOT= %{__python3} -Ic 
"import sysconfig; print(sysconfig.get_path('purelib', vars={'platbase': 
'%{_prefix}', 'base': '%{_prefix}'}))")

This is a %define-style macro, so the macro gets re-evaluated for every
expansion.  It can make spec file operations really, really slow.

It's possible to work around this in spec files like this:

%{?python3_sitearch: %global python3_sitearch %{python3_sitearch}}

But this is quite ugly, and I wonder if there is a nice way to do it
directly in the macros file instead.  I think I know how do it with Lua,
but maybe there is a better way?


This works (using random to demonstarte the behavior:

%_python3_random %(RPM_BUILD_ROOT= %{__python3} -Ic "import random; 
print(random.randint(0,100))")
%python3_random %{?!_python3_random_cached:%{global _python3_random_cached 
%_python3_random}}%_python3_random_cached


$ rpm --eval '%python3_random %python3_random %python3_random %python3_random 
%python3_random'

42 42 42 42 42

Note that %python3_sitlib must be evaluated after Python is installed so maybe 
there must be some "non-empty" conditional added as well.


--
Miro Hrončok
--
Phone: +420777974800
IRC: mhroncok

___
Rpm-list mailing list
Rpm-list@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-list


Re: Memoizing macro values

2022-12-21 Thread Miro Hrončok

On 21. 12. 22 11:40, Miro Hrončok wrote:

On 21. 12. 22 11:17, Florian Weimer wrote:

In Fedora, we have this:

/usr/lib/rpm/macros.d/macros.python:%python_sitelib %(RPM_BUILD_ROOT= 
%{__python} -Esc "import sysconfig; print(sysconfig.get_path('purelib', 
vars={'platbase': '%{_prefix}', 'base': '%{_prefix}'}))")
/usr/lib/rpm/macros.d/macros.python3:%python3_sitelib %(RPM_BUILD_ROOT= 
%{__python3} -Ic "import sysconfig; print(sysconfig.get_path('purelib', 
vars={'platbase': '%{_prefix}', 'base': '%{_prefix}'}))")


This is a %define-style macro, so the macro gets re-evaluated for every
expansion.  It can make spec file operations really, really slow.

It's possible to work around this in spec files like this:

%{?python3_sitearch: %global python3_sitearch %{python3_sitearch}}

But this is quite ugly, and I wonder if there is a nice way to do it
directly in the macros file instead.  I think I know how do it with Lua,
but maybe there is a better way?


This works (using random to demonstarte the behavior:

%_python3_random %(RPM_BUILD_ROOT= %{__python3} -Ic "import random; 
print(random.randint(0,100))")
%python3_random %{?!_python3_random_cached:%{global _python3_random_cached 
%_python3_random}}%_python3_random_cached


$ rpm --eval '%python3_random %python3_random %python3_random %python3_random 
%python3_random'

42 42 42 42 42

Note that %python3_sitlib must be evaluated after Python is installed so maybe 
there must be some "non-empty" conditional added as well.


This should do:

%_python3_random %(RPM_BUILD_ROOT= %{__python3} -Ic "import random; print(i if 
(i := random.randint(0,100)) > 75 else '')")
%python3_random %["%?_python3_random_cached" == "" ? "%{global 
_python3_random_cached %_python3_random}" : ""]%_python3_random_cached


$ rpm --eval '%python3_random %python3_random %python3_random %python3_random 
%python3_random'

   87 87


--
Miro Hrončok
--
Phone: +420777974800
IRC: mhroncok

___
Rpm-list mailing list
Rpm-list@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-list