Re: m4p: an implementation of GNU m4 in Python

Nikolaos Chatzikonstantinou <[email protected]> Sat, 10 May 2025 16:43:53 -0400
Newsgroups gmane.comp.gnu.m4.general,gmane.comp.sysutils.automake.general
Message-ID <CAAQmekfAHQ3H4CANOzsir_jEJyA1pP_OReaTvY=PJHp2HFBTHg@mail.gmail.com>
--000000000000c235450634ce24a9
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Sat, May 10, 2025, 4:35=E2=80=AFPM Eric Blake <[email protected]> wrote:

> On Fri, May 09, 2025 at 04:33:44PM -0400, Nikolaos Chatzikonstantinou
> wrote:
> > Hello lists,
> >
> > I rewrote GNU m4 in Python. Long story short, I wanted to learn m4 to
> > fix some issues I had with GNU Guile and Autotools, and after
> > realizing m4 1.4 is ~8000 lines of code and reading e.g.
> > <https://www.owlfolio.org/development/autoconf-swot/> which claims
> > "Feature gaps in GNU M4 hold back development of Autoconf." I thought
> > I'd rewrite it in Rust. (It turned out to be more beneficial to
> > rewrite in Python due to faster prototyping for the time being.)
> > Eventually I plan to get back to my original purpose of fixing the
> > integration of GNU Guile and Autotools.
> >
> > You can find the project home page here,
> > <https://codeberg.org/annoyingusername/m4p> and you can install with
> > pip via `pip install m4p`.
>
> I've checked out the repository, but the README.txt was very sparse at
> the command line I should use to build and install the binary into any
> place where I can quickly use it.  I'd rather run it from git than
> from a pip checkout (so that I can experiment with patching your code
> and instantly testing those results, rather than having to wait for
> the next release to land on pip).
>
> My initial attempt, 'python m4p', fails:
>
> $ python m4p
> /usr/bin/python: can't find '__main__' module in '/home/eblake/m4p/m4p'
>
> and this also fails:
>
> $ python m4p/main.py
> /home/eblake/m4p/m4p/main.py:18: DeprecationWarning: pkg_resources is
> deprecated as an API. See
> https://setuptools.pypa.io/en/latest/pkg_resources.html
>   import pkg_resources
> Traceback (most recent call last):
>   File "/home/eblake/m4p/m4p/main.py", line 20, in <module>
>     from m4p.stream import Stream
> ModuleNotFoundError: No module named 'm4p'
>
> Maybe it's my naivete with python, but unless I can figure out how to
> run your code, I can't compare it against the C version to spot out
> where you are still incomplete in your implementation.
>

Try this in the source dir (one time only):

python3 -m venv .venv
source .venv/bin/activate
pip install -U pip setuptools wheel
pip install -e .[tests]

Then anytime you want to try the software navigate to the source directory
and do:

source .venv/bin/activate

To activate the environment and use "m4p" directly as a command. Any
changes you make to the source code should be reflected in that m4p script.

I will add the instructions in the Readme too later today.

Regards,
Nikolaos Chatzikonstantinou

--000000000000c235450634ce24a9
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto"><div><div class=3D"gmail_quote gmail_quote_container"><di=
v dir=3D"ltr" class=3D"gmail_attr">On Sat, May 10, 2025, 4:35=E2=80=AFPM Er=
ic Blake &lt;<a href=3D"mailto:[email protected]">[email protected]</a>&gt;=
 wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8=
ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, May 09, 2025 at 04:=
33:44PM -0400, Nikolaos Chatzikonstantinou wrote:<br>
&gt; Hello lists,<br>
&gt; <br>
&gt; I rewrote GNU m4 in Python. Long story short, I wanted to learn m4 to<=
br>
&gt; fix some issues I had with GNU Guile and Autotools, and after<br>
&gt; realizing m4 1.4 is ~8000 lines of code and reading e.g.<br>
&gt; &lt;<a href=3D"https://www.owlfolio.org/development/autoconf-swot/" re=
l=3D"noreferrer noreferrer" target=3D"_blank">https://www.owlfolio.org/deve=
lopment/autoconf-swot/</a>&gt; which claims<br>
&gt; &quot;Feature gaps in GNU M4 hold back development of Autoconf.&quot; =
I thought<br>
&gt; I&#39;d rewrite it in Rust. (It turned out to be more beneficial to<br=
>
&gt; rewrite in Python due to faster prototyping for the time being.)<br>
&gt; Eventually I plan to get back to my original purpose of fixing the<br>
&gt; integration of GNU Guile and Autotools.<br>
&gt; <br>
&gt; You can find the project home page here,<br>
&gt; &lt;<a href=3D"https://codeberg.org/annoyingusername/m4p" rel=3D"noref=
errer noreferrer" target=3D"_blank">https://codeberg.org/annoyingusername/m=
4p</a>&gt; and you can install with<br>
&gt; pip via `pip install m4p`.<br>
<br>
I&#39;ve checked out the repository, but the README.txt was very sparse at<=
br>
the command line I should use to build and install the binary into any<br>
place where I can quickly use it.=C2=A0 I&#39;d rather run it from git than=
<br>
from a pip checkout (so that I can experiment with patching your code<br>
and instantly testing those results, rather than having to wait for<br>
the next release to land on pip).<br>
<br>
My initial attempt, &#39;python m4p&#39;, fails:<br>
<br>
$ python m4p<br>
/usr/bin/python: can&#39;t find &#39;__main__&#39; module in &#39;/home/ebl=
ake/m4p/m4p&#39;<br>
<br>
and this also fails:<br>
<br>
$ python m4p/main.py <br>
/home/eblake/m4p/m4p/main.py:18: DeprecationWarning: pkg_resources is depre=
cated as an API. See <a href=3D"https://setuptools.pypa.io/en/latest/pkg_re=
sources.html" rel=3D"noreferrer noreferrer" target=3D"_blank">https://setup=
tools.pypa.io/en/latest/pkg_resources.html</a><br>
=C2=A0 import pkg_resources<br>
Traceback (most recent call last):<br>
=C2=A0 File &quot;/home/eblake/m4p/m4p/main.py&quot;, line 20, in &lt;modul=
e&gt;<br>
=C2=A0 =C2=A0 from m4p.stream import Stream<br>
ModuleNotFoundError: No module named &#39;m4p&#39;<br>
<br>
Maybe it&#39;s my naivete with python, but unless I can figure out how to<b=
r>
run your code, I can&#39;t compare it against the C version to spot out<br>
where you are still incomplete in your implementation.<br></blockquote></di=
v></div><div dir=3D"auto"><br></div><div dir=3D"auto">Try this in the sourc=
e dir (one time only):</div><div dir=3D"auto"><br></div><div dir=3D"auto">p=
ython3 -m venv .venv</div><div dir=3D"auto">source .venv/bin/activate</div>=
<div dir=3D"auto">pip install -U pip setuptools wheel</div><div dir=3D"auto=
">pip install -e .[tests]</div><div dir=3D"auto"><br></div><div dir=3D"auto=
">Then anytime you want to try the software navigate to the source director=
y and do:</div><div dir=3D"auto"><br></div><div dir=3D"auto"><div dir=3D"au=
to">source .venv/bin/activate</div><br></div><div dir=3D"auto">To activate =
the environment and use &quot;m4p&quot; directly as a command. Any changes =
you make to the source code should be reflected in that m4p script.</div><d=
iv dir=3D"auto"><br></div><div dir=3D"auto">I will add the instructions in =
the Readme too later today.</div><div dir=3D"auto"><br></div><div dir=3D"au=
to">Regards,</div><div dir=3D"auto">Nikolaos Chatzikonstantinou=C2=A0</div>=
<div dir=3D"auto"><br></div><div dir=3D"auto"><div class=3D"gmail_quote gma=
il_quote_container"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0=
 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>

--000000000000c235450634ce24a9--