Sourcing python files in Mingw

Ralf Habacker ralf.habacker at freenet.de
Tue Aug 17 15:15:18 BST 2021


Am 17.08.21 um 14:51 schrieb Da Viper:
> My bad for not being explicit 
> 
> Gdb has a command called `source` 
> It can be use to load python files 
> 
> If you create a test.py file as show in the above example and source it
> using the source command it doesn't work,
> 
> Upon further inspection it crashes on Crlf \r\n and commas do not know why 


After running

(gdb) source test.py

did you get this error message ?

Traceback (most recent call last):
  File "i:\share\gdb/python\gdb\__init__.py", line 129, in _execute_file
    compiled = compile(file.read(), filepath, 'exec')
  File "test.py", line 1
    import sys
              ^
SyntaxError: invalid syntax

If so, it looks that the python function compile() has an issue with \r\n.

which was fixed in python 3.2
https://docs.python.org/3/library/functions.html#compile

> Changed in version 3.2: Allowed use of Windows and Mac newlines.

As workaround you can change line 129 of
i:\share\gdb/python\gdb\__init__.py" from

-            compiled = compile(file.read(), filepath, 'exec')

to

+            compiled = compile(file.read().replace('\r\n','\n'),
filepath, 'exec')

I have also applied this fix to the obs builds that should be available
soon at https://kmymoney.org/snapshots.php#gdb-snapshot. For 32bit
builds, look for the term "29.1" in the download URL and "16.1" for
64bit builds.

Regards
Ralf

> 
> 
> 
> On Tue, 17 Aug 2021, 07:54 Ralf Habacker via Kde-finance-apps,
> <kde-finance-apps at kde.org <mailto:kde-finance-apps at kde.org>> wrote:
> 
>     Am 16.08.21 um 21:54 schrieb Da Viper via Kde-finance-apps:
>     > I am currently using the Mingw from kmymoney, it's is version  10.2 
>     >
>     > If I try import a python file that has a new line it show syntax
>     error:
>     > invalid syntax
>     >
>     > For example
>     > In the file 
>     >
>     > ```
>     > import sys
>     >
>     > print(sys.version)
>     >
>     > ```
> 
>     I just downloaded a fresh 32bit version of the mentioned gdb from
>     https://kmymoney.org/snapshots.php#gdb-snapshot
>     <https://kmymoney.org/snapshots.php#gdb-snapshot> and unpackaged it.
> 
>     Then I created a file named gdbinit in a new subdirectory named
>     etc\gdbinit  below the unpackaged directory and entered
> 
>     python
>     import sys
>     print(sys.version)
> 
> 
>     After saving I started gdb and got the python version printed
> 
>     $ gdb -q
>     2.6.9 (unknown, Jul 17 2021, 12:00:00)
>     [GCC 9.2.0]
>     (gdb)
> 
>     Changing the end of line of the file gdbinit from dos to unix gave the
>     same results.
> 
>     Can you reproduce that ?
> 
>     Regards
>     Ralf
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 


More information about the Kde-finance-apps mailing list