tkluck / pyperler

Use perl scripts and libraries from Python
GNU General Public License v3.0
19 stars 2 forks source link

Does not build because the perl XS macros don't work anymore #1

Closed tkluck closed 4 years ago

tkluck commented 4 years ago

A change (in the perl macros?) means that the generated C code does not compile anymore:

In file included from /usr/lib/x86_64-linux-gnu/perl/5.28/CORE/perl.h:5251,
                 from pyperler.h:21,
                 from pyperler.c:616:
pyperler.c: In function ‘__pyx_f_8pyperler_call_object’:
/usr/lib/x86_64-linux-gnu/perl/5.28/CORE/pp.h:81:19: error: expected ‘)’ before ‘sp’
   81 | #define dSP  SV **sp = PL_stack_sp
alexman128 commented 4 years ago

Hi Timo, Let me give you more details,

I ran into that issue using the below setup:

Ubuntu 16.04 LTS perl 5.16 python3.6

And I got:

$ python3 setup.py build && sudo python3 setup.py install running build running build_ext skipping 'pyperler.c' Cython extension (up-to-date) building 'pyperler' extension gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python3.6m -c pyperler.c -o build/temp.linux-x86_64-3.6/pyperler.o -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib64/perl5/CORE Assembler messages: Fatal error: can't create build/temp.linux-x86_64-3.6/pyperler.o: Permission denied In file included from /usr/lib64/perl5/CORE/perl.h:5012:0, from pyperler.h:21, from pyperler.c:601: pyperler.c: In function \u2018__pyx_f_8pyperler_call_object\u2019: /usr/lib64/perl5/CORE/pp.h:68:19: error: expected \u2018)\u2019 before \u2018sp\u2019

define dSP SV **sp = PL_stack_sp

               ^

pyperler.c:3028:10: note: in expansion of macro \u2018dSP\u2019 (void)(dSP);

And following the installation instructions posted here, on a parallels virtual machine on mac, but I also tried on virtualbox on a windows machine and centos 7 and same result

tkluck commented 4 years ago

@alexman128 I just pushed something that I think might be a fix. Could you let me know your findings with the latest master?

alexman128 commented 4 years ago

Hi Timo,

Thanks for the prompt reply! :) It seems to have improved, but the compilation is still failing, let me paste the output.

`parallels@parallels-vm:~/Downloads/pyperler/pyperler-master$ python3 setup.py build && sudo python3 setup.py install Unable to find pgen, not compiling formal grammar. /usr/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'python_requires' warnings.warn(msg) Compiling /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Plex/Scanners.py because it changed. Compiling /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Plex/Actions.py because it changed. Compiling /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Compiler/Scanning.py because it changed. Compiling /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Compiler/Visitor.py because it changed. Compiling /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Compiler/FlowControl.py because it changed. Compiling /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Runtime/refnanny.pyx because it changed. Compiling /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Compiler/FusedNode.py because it changed. Compiling /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Tempita/_tempita.py because it changed. [1/8] Cythonizing /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Compiler/FlowControl.py [2/8] Cythonizing /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Compiler/FusedNode.py [3/8] Cythonizing /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Compiler/Scanning.py [4/8] Cythonizing /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Compiler/Visitor.py [5/8] Cythonizing /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Plex/Actions.py [6/8] Cythonizing /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Plex/Scanners.py [7/8] Cythonizing /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Runtime/refnanny.pyx [8/8] Cythonizing /tmp/easy_install-qgn8o16e/Cython-0.29.14/Cython/Tempita/_tempita.py warning: no files found matching 'Doc/' warning: no files found matching '.pyx' under directory 'Cython/Debugger/Tests' warning: no files found matching '.pxd' under directory 'Cython/Debugger/Tests' warning: no files found matching '.pxd' under directory 'Cython/Utility' warning: no files found matching 'pyximport/README'

Installed /home/parallels/Downloads/pyperler/pyperler-master/.eggs/Cython-0.29.14-py3.5-linux-x86_64.egg running build running build_ext cythoning pyperler.pyx to pyperler.c /home/parallels/Downloads/pyperler/pyperler-master/.eggs/Cython-0.29.14-py3.5-linux-x86_64.egg/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/parallels/Downloads/pyperler/pyperler-master/pyperler.pyx tree = Parsing.p_module(s, pxd, full_module_name) warning: pyperler.pyx:787:12: Unreachable code building 'pyperler' extension creating build creating build/temp.linux-x86_64-3.5 x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c pyperler.c -o build/temp.linux-x86_64-3.5/pyperler.o -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib/x86_64-linux-gnu/perl/5.22/CORE In file included from /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/perl.h:5546:0, from pyperler.h:21, from pyperler.c:601: pyperler.c: In function ‘__pyx_f_8pyperler_xs_init’: pyperler.c:6494:50: warning: passing argument 3 of ‘Perl_newXS’ from incompatible pointer type [-Wincompatible-pointer-types] newXS(((char *)"DynaLoader::boot_DynaLoader"), (&boot_DynaLoader), __pyx_v_file); ^ /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/embed.h:419:42: note: in definition of macro ‘newXS’

define newXS(a,b,c) PerlnewXS(aTHX a,b,c)

                                      ^

In file included from /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/perl.h:5511:0, from pyperler.h:21, from pyperler.c:601: /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/proto.h:3156:19: note: expected ‘XSUBADDR_t {aka void ()(struct interpreter , struct cv )}’ but argument is of type ‘void ()(CV ) {aka void ()(struct cv )}’ PERL_CALLCONV CV PerlnewXS(pTHX const char name, XSUBADDR_t subaddr, const char filename) ^ In file included from /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/perl.h:5546:0, from pyperler.h:21, from pyperler.c:601: pyperler.c:6503:40: warning: passing argument 3 of ‘Perl_newXS’ from incompatible pointer type [-Wincompatible-pointer-types] newXS(((char *)"Python::bootstrap"), (&__pyx_f_8pyperler_dummy), __pyx_v_file); ^ /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/embed.h:419:42: note: in definition of macro ‘newXS’

define newXS(a,b,c) PerlnewXS(aTHX a,b,c)

                                      ^

In file included from /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/perl.h:5511:0, from pyperler.h:21, from pyperler.c:601: /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/proto.h:3156:19: note: expected ‘XSUBADDR_t {aka void ()(struct interpreter , struct cv )}’ but argument is of type ‘void ()(CV , CV ) {aka void ()(struct cv , struct cv )}’ PERL_CALLCONV CV PerlnewXS(pTHX const char name, XSUBADDR_t subaddr, const char filename) ^ In file included from /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/perl.h:5546:0, from pyperler.h:21, from pyperler.c:601: pyperler.c:6512:48: warning: passing argument 3 of ‘Perl_newXS’ from incompatible pointer type [-Wincompatible-pointer-types] newXS(((char *)"Python::Object::bootstrap"), (&__pyx_f_8pyperler_dummy), __pyx_v_file); ^ /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/embed.h:419:42: note: in definition of macro ‘newXS’

define newXS(a,b,c) PerlnewXS(aTHX a,b,c)

                                      ^

In file included from /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/perl.h:5511:0, from pyperler.h:21, from pyperler.c:601: /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/proto.h:3156:19: note: expected ‘XSUBADDR_t {aka void ()(struct interpreter , struct cv )}’ but argument is of type ‘void ()(CV , CV ) {aka void ()(struct cv , struct cv )}’ PERL_CALLCONV CV PerlnewXS(pTHX const char name, XSUBADDR_t subaddr, const char filename) ^ In file included from /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/perl.h:5546:0, from pyperler.h:21, from pyperler.c:601: pyperler.c:6530:43: warning: passing argument 3 of ‘Perl_newXS’ from incompatible pointer type [-Wincompatible-pointer-types] newXS(((char *)"Python::PyObject_Str"), (&__pyx_f_8pyperler_object_to_str), __pyx_v_file); ^ /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/embed.h:419:42: note: in definition of macro ‘newXS’

define newXS(a,b,c) PerlnewXS(aTHX a,b,c)

                                      ^

In file included from /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/perl.h:5511:0, from pyperler.h:21, from pyperler.c:601: /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/proto.h:3156:19: note: expected ‘XSUBADDR_t {aka void ()(struct interpreter , struct cv )}’ but argument is of type ‘void ()(CV , CV ) {aka void ()(struct cv , struct cv )}’ PERL_CALLCONV CV PerlnewXS(pTHX const char name, XSUBADDR_t subaddr, const char filename) ^ In file included from /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/perl.h:5546:0, from pyperler.h:21, from pyperler.c:601: pyperler.c:6539:46: warning: passing argument 3 of ‘Perl_newXS’ from incompatible pointer type [-Wincompatible-pointer-types] newXS(((char *)"Python::PyObject_IsTrue"), (&__pyx_f_8pyperler_object_to_bool), __pyx_v_file); ^ /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/embed.h:419:42: note: in definition of macro ‘newXS’

define newXS(a,b,c) PerlnewXS(aTHX a,b,c)

                                      ^

In file included from /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/perl.h:5511:0, from pyperler.h:21, from pyperler.c:601: /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/proto.h:3156:19: note: expected ‘XSUBADDR_t {aka void ()(struct interpreter , struct cv )}’ but argument is of type ‘void ()(CV , CV ) {aka void ()(struct cv , struct cv )}’ PERL_CALLCONV CV PerlnewXS(pTHX const char name, XSUBADDR_t subaddr, const char filename) ^ In file included from /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/perl.h:5546:0, from pyperler.h:21, from pyperler.c:601: pyperler.c:6548:47: warning: passing argument 3 of ‘Perl_newXS’ from incompatible pointer type [-Wincompatible-pointer-types] newXS(((char *)"Python::PyObject_GetItem"), (&__pyx_f_8pyperler_object_get_item), __pyx_v_file); ^ /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/embed.h:419:42: note: in definition of macro ‘newXS’

define newXS(a,b,c) PerlnewXS(aTHX a,b,c)

                                      ^

In file included from /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/perl.h:5511:0, from pyperler.h:21, from pyperler.c:601: . . . .

In file included from /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/perl.h:3733:0, from pyperler.h:21, from pyperler.c:601: pyperler.c: In function ‘pyx_f_8pyperlernew_sv_from_object’: /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/sv.h:1279:34: warning: assignment makes integer from pointer without a cast [-Wint-conversion] (((XPVIV) SvANY(sv))->xiv_iv = (val)); } STMT_END ^ pyperler.c:13819:16: note: in expansion of macro ‘SvIV_set’ (void)(SvIV_set(__pyx_v_scalar_value, ((void )__pyx_v_value))); ^ /usr/lib/x86_64-linux-gnu/perl/5.22/CORE/sv.h:1085:25: warning: statement with no effect [-Wunused-value]

define SvREADONLY(sv) (SvFLAGS(sv) & (SVf_READONLY|SVf_PROTECT))

                     ^

pyperler.c:13855:9: note: in expansion of macro ‘SvREADONLY’ SvREADONLY(__pyx_v_scalar_value); ^ x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c pyperler_extra.c -o build/temp.linux-x86_64-3.5/pyperler_extra.o -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib/x86_64-linux-gnu/perl/5.22/CORE creating build/lib.linux-x86_64-3.5 x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.5/pyperler.o build/temp.linux-x86_64-3.5/pyperler_extra.o -o build/lib.linux-x86_64-3.5/pyperler.cpython-35m-x86_64-linux-gnu.so -Wl,-E -fstack-protector-strong -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu/perl/5.22/CORE -lperl -ldl -lm -lpthread -lc -lcrypt /usr/bin/ld: cannot find -lperl collect2: error: ld returned 1 exit status error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

`

tkluck commented 4 years ago

This one is just a dependency issue: /usr/bin/ld: cannot find -lperl . You need to install libperl-dev (debian/ubuntu, or your distribution's equivalent) for this. Could you let me know whether that works?

alexman128 commented 4 years ago

Hi Tim,

Sorry, I didn't see the reply until now, I finished the compilation and even though it shows some warnings, it finished the installation , I will test if it actually works in an actual python program later, thanks a lot Tim :)

`Processing pyperler-0.2-py3.5-linux-x86_64.egg creating /usr/local/lib/python3.5/dist-packages/pyperler-0.2-py3.5-linux-x86_64.egg Extracting pyperler-0.2-py3.5-linux-x86_64.egg to /usr/local/lib/python3.5/dist-packages Adding pyperler 0.2 to easy-install.pth file

Installed /usr/local/lib/python3.5/dist-packages/pyperler-0.2-py3.5-linux-x86_64.egg Processing dependencies for pyperler==0.2 Finished processing dependencies for pyperler==0.2 `

alexman128 commented 4 years ago

Hi Tim,

I tried running the example program, but I get the below error, I guess this is a problem with my version of cython that is installed:

python3 test.py Traceback (most recent call last): File "test.py", line 1, in <module> import pyperler ImportError: /usr/local/lib64/python3.6/site-packages/pyperler-0.2-py3.6-linux-x86_64.egg/pyperler.cpython-36m-x86_64-linux-gnu.so: undefined symbol: av_top_index

tkluck commented 4 years ago

@alexman128 thanks for following up.

That error is a linking error related to a symbol that should be defined in libperl.so. It seems like it's not finding that.

After building, could you run

find -name pyperler.so -exec ldd {} \;

and paste the output here?

alexman128 commented 4 years ago

Hi Tim, I am not able to find that file pyperler.so, maybe that is the issue? Was it supposed to be generated during the install?

alexman128 commented 4 years ago

Hi Tim, Just to let you know, in an ubuntu box, it works without issues :), But in the Centos one I still have that error, but I guess it´s only a configuration issue, not related to pyperler itself, thanks a lot Tim :D

alexman128 commented 4 years ago

Hi Tim,

I was able to install pyperler on a oracle linux system, however when importing it it gets imported without any functions, so I tried to compile it again, the build part runs ok, but the install part complains because it tries to install it in a filesystem which is read only, is there a way to tell the setup.py script another directory where it can be installed ?

El 29 nov 2019, a las 8:28, Timo Kluck notifications@github.com<mailto:notifications@github.com> escribió:

@alexman128https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Falexman128&data=02%7C01%7C%7Ca71b41a2977640300be408d774d864a2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637106345058590874&sdata=%2F28Aa6REGczsTwSfNT%2FDtQHjOPc2hzMBD%2Bii76EQjis%3D&reserved=0 thanks for following up.

That error is a linking error related to a symbol that should be defined in libperl.so. It seems like it's not finding that.

After building, could you run

find -name pyperler.so -exec ldd {} \;

and paste the output here?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftkluck%2Fpyperler%2Fissues%2F1%3Femail_source%3Dnotifications%26email_token%3DAAXVDPETLHNP66CL6VGD6QLQWERIPA5CNFSM4JKXSV3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFO7V7Y%23issuecomment-559807231&data=02%7C01%7C%7Ca71b41a2977640300be408d774d864a2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637106345058600879&sdata=DO9P7Q%2BY4UKZR10o5cF3UopBjVo1uBDxanUFB8%2BI7E0%3D&reserved=0, or unsubscribehttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAXVDPFEKXFUBUSROZURG3TQWERIPANCNFSM4JKXSV3A&data=02%7C01%7C%7Ca71b41a2977640300be408d774d864a2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637106345058620901&sdata=swlEEt7ptz8BgwXIGpu3UOaLbaEHTP5sG%2FupAHURHYY%3D&reserved=0.

tkluck commented 4 years ago

Is there a way to tell the setup.py script another directory where it can be installed ?

Does python3 setup.py install --use do what you want? Have a look at python3 setup.py install --help for other prefix options.

I'm going to close this issue as the conversation has drifted a bit from the original issue. Feel free to open new issues if you encounter any bugs!

HalMorris commented 4 years ago

I'm been using pyperler, but don't see how to make it work on cases unlike the one you gave as an example -- specifically ones like Date::Parse which just provide a couple of utility functions but no object. The function in the module is getting what I suppose is a 'self' or 'this' type argument. See below for an example of a small program and small module with a modification I had to make for the module to work. The modification is simply to add "shift if $_[0] =~ /PACKAGE/. Is there a better way of doing this, or do you consider it a bug in pyperler worth fixing? I'm going to be doing some extensive perl -> python conversion, and also writing some documentation on a blog, including a more extensive documentation of pyperler if you don't mind. Thanks, Hal

import pyperler

i = pyperler.Interpreter()

ab = i.use('AbbrevAbbrev')

d = ab.ReadDictionary('Publishers') print(d)

Module:package ERB::Abbreviations;

use strict; use vars qw(@EXPORT @ISA);

require Exporter; @ISA = qw(Exporter);

my $BD = "/home/hal/BD";

@EXPORT = qw( ReadDictionary);

---------------------------------------------------------------

ReadDictionary {NAME}. Read something of the following form:

a Anchor Books

ab Allyn and Bacon

aw Addison-Wesley

...

#

Return { a => 'Anchor Books', ab => 'Allyn and Bacon', ...}

---------------------------------------------------------------

sub ReadDictionary { shift if $_[0] =~ m{PACKAGE}; my $name = shift; my $pathname = "$BD/Abbrev/$name.txt"; -e $pathname or die "No such file: '$pathname'"; open DICT, $pathname or die "Can't open '$pathname' for reading"; my %Ret; while ( ) { /(\S+)\t(.*)/ and $Ret{$1} = $2; } close DICT; return \%Ret; }

1;

Also, do you have any recommendations for debugging the perl module when used via pyperler? At some point I may also want to know if there is any integrated method of debugging the python and perl parts, and also pyperler itself via gdb. I've very behind the times when it comes to tools like PyCharm.

tkluck commented 4 years ago

Is this what you are looking for?

>>> import pyperler
>>> perl = pyperler.Interpreter()
>>> perl.use("Date::Parse")
<pyperler.PerlPackage object at 0x7fb18abd50d0>
>>> perl.Fstr2time("2020-01-01")
1577836800

As for debugging, I don't think I have a really good answer there that combines debugging in python with debugging in perl. If you find anything useful there, I'd love to add it to the docs!

HalMorris commented 4 years ago

Thanks. Looks like this will help. It wasn't clear to me how to generalize from the example given to this sort of non-OO grab-bag of utilities module. BTW, I'd also like to know of there's any kind of smooth integration with either Perl or Python and C, in the event they're being interfaced as you're doing. And good resources for understanding those interfaces would also help.

Thanks, and Best Wishes, Hal

Is this what you are looking for?

>>> import pyperler
>>> perl = pyperler.Interpreter()
>>> perl.use("Date::Parse")
<pyperler.PerlPackage object at 0x7fb18abd50d0>
>>> perl.Fstr2time("2020-01-01")
1577836800

As for debugging, I don't think I have a really good answer there that combines debugging in python with debugging in perl. If you find anything useful there, I'd love to add it to the docs!

-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/tkluck/pyperler/issues/1#issuecomment-662065856

HalMorris commented 4 years ago

Actually on 2nd thought your example is very peculiar. When I do "man Date::Parser", I see:

SYNOPSIS use Date::Parse;

            $time = str2time($date);

            ($ss,$mm,$hh,$day,$month,$year,$zone) = strptime($date);

so NO Fstr2time(), and when I google 'perl Fstr2time' it "corrects" it to 'perl str2time', and tells me there are no matches for 'perl Fstr2time'.

Yet is seems to work. So is the trick to prefix 'F' to the exported function I want to call? At best unintuitive and undocumented, as far as I can tell, but:

Trying that: where t.Abbreviations: import pyperler perl = pyperler.Interpreter() perl.use('ERB::Abbreviations') d = perl.FReadDictionary('Publishers')

print(d)  # I expect this to be a python dictionary, which
      # should be printable.
print()
print(dir(perl))
print()
print(dir(perl.FReadDictionary))

python3 t.Abb*

HASH(0xf61818) <--- "print(d)" Expected d to be a dictionary; hence print(d) should work ['A', 'D', 'F', 'H', 'P', 'S', 'use']

['call', 'class', 'delattr', 'dir', 'doc', 'eq', 'format', 'ge', 'getattribute', 'gt', 'hash', 'init', 'init_subclass', 'le', 'lt', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'setstate', 'sizeof', 'str', 'subclasshook', 'list_context', 'scalar_context', 'void_context']

Note the strangeness of dir(perl) and the fact that dir(perl.FReadDictionary) looks kind of reasonable, while (see below) dir(perl.ReadDictionary) produces an exception.

Just checking that my perl module really does work:

$ perl -d -e 0

Loading DB routines from perl5db.pl version 1.55 Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(-e:1): 0 DB<1> use ERB::Abbreviations

DB<2> x ReadDictionary('Publishers') 0 HASH(0x55968e9fb310) 'a' => 'Anchor Books' 'aak' => 'Alfred A. Knopf' 'ab' => 'Allyn and Bacon' 'acc' => 'Appleton-Century-Crofts' 'amp' => 'Atlantic Monthly Press' ... [looks as expected]

ALSO, for good measure, removing the 'F's from ReadDictionary in t.Abbreviations,

$ python3 t.Abb* Traceback (most recent call last): File "t.Abbreviation", line 5, in d = perl.ReadDictionary('Publishers') File "pyperler.pyx", line 671, in pyperler.Interpreter.getattribute AttributeError: 'pyperler.Interpreter' object has no attribute 'ReadDictionary'

A 2nd demonstration of how dir(perl.FReadDictionary) is at least something while dir(perl.ReadDictionary) ==> exception:

t.Abb*: import pyperler perl = pyperler.Interpreter() perl.use('ERB::Abbreviations')

print(dir(perl.FReadDictionary))
print ('=========================================')
print(dir(perl.ReadDictionary))

$ python3 t.Abb* ['call', 'class', 'delattr', 'dir', 'doc', 'eq', 'format', 'ge', 'getattribute', 'gt', 'hash', 'init', 'init_subclass', 'le', 'lt', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'setstate', 'sizeof', 'str', 'subclasshook', 'list_context', 'scalar_context', 'void_context']

Traceback (most recent call last): File "t.Abbreviation", line 8, in print(dir(perl.ReadDictionary)) File "pyperler.pyx", line 671, in pyperler.Interpreter.getattribute AttributeError: 'pyperler.Interpreter' object has no attribute 'ReadDictionary'

On Wed, 22 Jul 2020, Hal Morris wrote:

Thanks. Looks like this will help. It wasn't clear to me how to generalize from the example given to this sort of non-OO grab-bag of utilities module. BTW, I'd also like to know of there's any kind of smooth integration with either Perl or Python and C, in the event they're being interfaced as you're doing. And good resources for understanding those interfaces would also help.

Thanks, and Best Wishes, Hal

Is this what you are looking for?

>>> import pyperler
>>> perl = pyperler.Interpreter()
>>> perl.use("Date::Parse")
<pyperler.PerlPackage object at 0x7fb18abd50d0>
>>> perl.Fstr2time("2020-01-01")
1577836800

As for debugging, I don't think I have a really good answer there that combines debugging in python with debugging in perl. If you find anything useful there, I'd love to add it to the docs!

-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/tkluck/pyperler/issues/1#issuecomment-662065856

HalMorris commented 4 years ago

I've been looking to the README.md that comes with the package, but now I think if I work through all the comments in pyperler.pyx I'll understand it much better.

Also if there could be any option to pyperler.Interpreter() to start up perl with debugging turned on, that could be extremely helpful. If possible, I'd like to be able to insert $DB::single = 1 in places.

Thanks, and Best Wishes, Hal

tkluck commented 4 years ago

Also if there could be any option to pyperler.Interpreter() to start up perl with debugging turned on, that could be extremely helpful.

This is where command-line flags are being passed to perl: https://github.com/tkluck/pyperler/blob/6e87dfb/pyperler.pyx#L563 . This is currently not exposed to the user but I'd gladly merge a PR that exposes it, if that's useful for you.