Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Writing a Perl extension framework for Inkscape

by fdesar (Beadle)
on Jan 22, 2019 at 13:49 UTC ( #1228810=perlquestion: print w/replies, xml ) Need Help??

fdesar has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Monks,

Sorry for this long first post, I just want to explain as clearly as possible what I'm attempting to do...

Preamble:

I'm a newbie at the monastery but not a perl newbie : I started using perl with version 4, beginning of the 90's...

Since a few years I started doing paper folding artwork also known as 'Origami' ((折り紙 or おりがみ) and I use a very popular OpenSource vector-drawing software called Inkscape for drawing Origami diagrams.

Diagramming Origami require somes very specific tools for drawing, to solve geometric problems to find where a crease will fall, following the axiomatic of Origami. It's sometimes tedious so, as Inkscape allows it, I decided to write a dedicated extension for it to do that. Of course, I wrote it in Perl as Inkscape allows using various scripting languages for it, but their preferences go clearly to Python : every docs and canevas for extensions are written for and in Python. So I decided to write my own tools to get my extension working with Perl and now it does work flawlessly.

As I've always been an OpenSource enthusiastic, I logically want to share my work with others. On Linux or other Unices, no problem : Perl is always available and just adding a few modules to the standard core installations is sufficient (XML::LibXML and Local::gettext as I also made support for I18n). But unfortunately, it exists a very widely used bloated thing called Windows on which many ordinary people get stuck. And here starts the problem: neither Perl nor Python are natively available on those environments.

I solved the problem by suggesting using Active Perl and it works quite well but... it is definitely *not* free software (as in free speech, not free bear) and I don't like that!

The Inkscape Team solved this issue by optionally integrating a Python2.7 chain to their Windows distribution as they already provide a lot of useful extensions written in Python. But for Perl, nothing, nada. Which I don't like neither and it makes me angry (but I keep zen).

So I had a very strange idea : building an integrated Perl framework for Inkscape on Windows that would install on top of standard Inkscape installation that would allow Perl extension to gracefully integrate with it. And if it works, maybe I'll be able to convince the Inkscape team to integrate it later on as an option within their main distribution, who knows...

For that, I need to do a number of things, all theoretically feasible I think :

1. Build a native Perl on Windows relative to the Inkscape installation directory (having an @INC pointing to (?)/Inkscape/lib/perl5)

2. Build the Lib::LibXML module for it (absolutely mandatory as Inkscape works upon SVG)

3. Build other few modules as Locale::gettext, for example, as gettext is their I18n implementation

4. Write a basic framework (in fact a module) for building extensions (mostly already done as I already wrote one for my own use but it needs to be more generalized/structured), as there is one for Python

5. Write an installer to setup things easily for dummy end-users (mainly copying the Perl executable and libraries into the installed Inkscape directory)

If all of this seems weird to you, just tell me and stop reading further...

Now, the problem:

I'm stuck on stage 1: building Perl on a windows system !

I tried many things, read a lot of threads, used a lot of configurations, from Straberry Perl, MingWin64 (MSYS2) to Visual Studio C++ Community 2017 and every thing failed:

- Strawberry Perl, no succes. I don't remember why I decided to give up, probably because using cygwin, it won't build a native Windows Perl...

- MingWin64 (MSYS2), no success, I get a fatal compiling error for a missing poll.h include file

- VS 2017 community is much better, as nmake completes the compilation correctly, but I get a fatal error running nmake test:

Test Summary Report ------------------- ../cpan/File-Temp/t/mktemp.t (Wsta +t: 6400 Tests: 5 Failed: 0) Non-zero exit status: 25 Parse errors: Bad plan. You planned 9 tests but ran 5. ../ext/File-Find/t/find.t (Wsta +t: 3328 Tests: 125 Failed: 0) Non-zero exit status: 13 Parse errors: Bad plan. You planned 137 tests but ran 125. ../ext/IPC-Open3/t/IPC-Open3.t (Wsta +t: 0 Tests: 45 Failed: 0) TODO passed: 25 ../ext/XS-APItest/t/locale.t (Wsta +t: 2304 Tests: 2 Failed: 0) Non-zero exit status: 9 Parse errors: No plan found in TAP output Files=2666, Tests=1088273, 1731 wallclock secs (66.19 usr + 6.66 sys += 72.84 CPU) Result: FAIL NMAKE : fatal error U1077: '.\perl.exe' : code retour '0x3' Stop.

and, of course, nmake install won't work.

And finally, the question:

What to try next ?

If anyone's interested in helping me mongering Perl on Inkscape, you're very welcome ;-)

PS : my extension is available to download and test at https://github.com/fdesar/Origami-Ext

Replies are listed 'Best First'.
Re: Writing a Perl extension framework for Inkscape
by Corion (Pope) on Jan 22, 2019 at 13:54 UTC

    How closely can you control when perl.exe is launched from Inkscape? If it is just a matter of setting up the correct @INC, you can just launch it by setting up the process environment with PERL5INC=(?)/Inkscape/lib/perl. Alternatively you can launch (whatever) Perl.exe with -Mlib=(?)/Inkscape/lib/perl.

    Of course, that Perl might be missing some modules, but at least Strawberry Perl comes with XML::LibXML included and you can easily distribute it with Inkscape or as a bundled package with your framework modules.

      Thanks. Be sure I though of that before.

      My own modules start to setup @INC with use dir at their very beginning: that's not the problem, it works pretty well. But each script must do that to load the initial common module: this is not clean.

      AFAIK, Inkscape calls an executable called perl.exe without any parameter. It IS possible to modify this under Unices via a preference.xml file, but this file does not exist in the windows version and I do not have access to the process environment to setup a variable at startup.

      But this is not the real part of the problem: it requires an external Perl installation and Straberry Perl is a fat thing that casual users of extensions definitely don't need (they don't need a Unix environment). This is why the Inkscape Team included Python in their distribution and why I'd like to do the same with Perl. And Active Perl is not, strictly speaking, free software and this I don't like.

      And last but not least, I've always hated this Python vs Perl discrimination ;)

        AFAIK, Inkscape calls an executable called perl.exe without any parameter. It IS possible to modify this under Unices via a preference.xml file, but this file does not exist in the windows version and I do not have access to the process environment to setup a variable at startup.

        The Inkscape documentation for extensions contains a procedure for setting up paths to interpreters which tells how to find where the file is:

        2.Open your perferences.xml file with a text editor (find the exact location of the file by going to Edit -> Preferences -> System: User Preferences)

        The procedure mentions Windows so it leads me to believe this will work on Windows:

        4.Insert a key for the interpreter, for example 'python-interpreter' for setting the program that should be used to run python extensions, and set the string to the absolute path to the python binary which is compatible with Inkscape's current extension scripts (in the example below, the path is "/usr/bin/python2.7". It will look different on Windows systems.):

        In case there is already a version of Perl on the system you could follow the approach that the portable version of Strawberry Perl uses with the portableshell.bat file. Instead of calling a Perl executable file directly you can call the bat file and it sets up a temporary environment with the Strawberry Perl folders at the beginning of the path and then runs perl.exe. This means the modules that are installed with Portable Perl are used instead of the ones installed in the system Perl.

Re: Writing a Perl extension framework for Inkscape
by pryrt (Monsignor) on Jan 22, 2019 at 14:49 UTC

    I've never tried to build my own Strawberry Perl distribution. But I'm not sure you really would need to build it yourself: You might want to take a page from Berrybrew, and have your install script download the appropriate portable zipfile (32bit or 64bit) from Strawberry Perl and unzip it into the appropriate subdirectory of Inkscape.

    (And I am bookmarking this, because I will definitely want to look at Origami-Ext, since my son is a fan of paper folding.)

      Interesting... I'll have a look at Berrybrew. But I definitely prefer building things myself whenever it's possible.

      In fact, I just finished compiling Perl on my VirtualBox Windows 10 just by skipping 4 tests... which seem for 2 of them to be simple coding errors in tests (missing test files). Only two of them should be investigated further with P5P...

      If your son draws Origami diagrams, I'm sure he'll appreciate this extension...

        Glad that you managed to successfully build Perl on Windows.

        Don't know what you did, but, FYI, the release notes for Strawberry Perl include all the compile settings and a list of the tools versions used (gcc, make, etc). Also, perldist_strawberry is the script used by Strawberry Perl to build new versions of Strawberry Perl.

Re: Writing a Perl extension framework for Inkscape
by Laurent_R (Canon) on Jan 22, 2019 at 17:12 UTC
    Hi fdesar,

    first, welcome to the Monastery.

    Second, I'm using Perl much more on various kinds of Unix and Linux than on Windows; in addition, when working under Windows, I usually prefer to use Cygwin when possible (mainly because of the bash environment, which is so much nicer to use than a cmd console -- although I know it is now possible and pretty easy to run a bash under pure Windows without Cygwin). So I am really not an expert on Perl on Windows, but, in my experience with Windows (i.e. when not using Cygwin), Strawberry is really good and I would think that you should have much less problems with Strawberry than with Active Perl.

    Contrary to what you seem to think, Strawberry does not need Cygwin to run and works well with pure native Windows. In addition, Strawberry provides a portable version (no installation required) which is likely to fit well into your project of bundling it with Inkscape and your own Origami modules. I really think that you should give Strawberry another try and tell us if you encounter any difficulties.

    Finally, kudos for being an Open Source enthusiast, I can only fully support you on this point. I haven't studied that issue in detail, but I believe that Strawberry is free software and will fit your outlook better than Active State. I really hope that you'll be able to release your project for Windows.

      But my extension is already available at https://github.com/fdesar/Origami-Ext and I wrote a command line installer. It only requires you have Active Perl installed first on your system. It even automatically download the missing Lib::LibXML module using ppm and I rewrote a mini-gettext specially for Windows (as Active State does't supply Locale::gettext) to have I18n working (Windows is a nightmare for that: they don't have AFAIK any libintl.dll available...)!

      As I'm not at all (luckily) of the Windows world, I've never been interested by Perl tools on it. Could you tell me more about Strawberry Perl? Is it really easy to extract just the binaries, dlls and libs and copy them to another system without having it installed? Have you already done that?

      As I use VirtualBox, it's not a problem to check it all again (I'm just running out of disk space now, but that should be ok by tomorrow) but it's just soooooo time consuming (but I have a freshly installed Windows 10 virtual box ready to speed up the process).

      I just wonder if compiling the sources is not as easy finally : when I have compiled them, it's just a game to build up the extra modules via CPAN and package the whole thing... It _should_ be easy : I finally got the thing (5.28.3) compiled and installed in my Virtual box with MS-VC compiler (with just a few details about (only) 4 test failures I have to discuss further with P5P... and next step is to get Locale::gettext working on it and thats all).

      But I will try again Strawberry, sure, especially if they have Locale::gettext out of the box... I was just convinced that it was not a native build and that it would require cygwin libraries to run.

        The strawberry portable-zip is a self-contained entity that can be unzipped wherever you want it, with the binaries all precompiled (you can download either the 32bit or the 64bit); you can look at the release notes for a given release to find out which modules come pre-bundled (for example, 5.28.1 64bit). It even includes the gcc toolchain necessary for building XS-based modules, or modules that come bundled with c-type libraries. I personally grab the PDL versions of the portable zipfiles: I don't much use PDL, but I like that it comes with a bunch of mathy libraries in places where it can easily find them, like GSL.

        To have it run, you just need the PATH to either temporarily or permanently include a few main directories: either use portableshell.bat (as Lotus1 recommended), which sets up a few environment variables for you; or you can temporarily set the PATH to include the appropriate bin-directories (as seen in portableshell.bat); or if you're launching from another application, it could change the **env argument to add those variables; or if you want your machine to always use that version of perl, permanently set your PATH variable to include those directories.

Re: Writing a Perl extension framework for Inkscape
by Lotus1 (Vicar) on Jan 22, 2019 at 15:12 UTC

    I'm very happy to see you working on improving the Perl support in Inkscape. It is a very useful tool for creating vector graphics. I have access to a laser cutter and have used Inkscape to create tool paths for projects. I've used mostly Python extensions so far, the included ones and ones I've found on Thingiverse. Although there aren't many Perl plugins I've always been impressed that the Inkscape team supports languages other than Python. I'm looking forward to trying out your extensions.

      You said: "...I've always been impressed that the Inkscape team supports languages other than Python."

      Maybe I'm just a little bit paranoid. I remember a kind of "war" ten or twenty years ago between pro-Python and pro-Perl camps... In fact, I don't know at all how it is today, but I saw recent threads of someone showing Python code and saying "You see : it's much more clearer without all those $ and % everywhere!"

        but I saw recent threads of someone showing Python code and saying "You see : it's much more clearer without all those $ and % everywhere!"

        As is often the case, perceptions and preferences are influenced by what you already know.

        My first (high level) programming language was a dialect of BASIC that uses $ as a sigil for variables. Also, many Linux/Unix/POSIX command shells, such as bash, ash, csh, sh and more, use $ the same way. I also learned C.

        So, given Perl syntax is very similar to C syntax and I was already used to using sigils in shell scripts, learning Perl was comfortable and easy for me.

        Python, however, uses whitespace as punctuation. While some would argue that forcing programmers to correctly indent their is s good thing, BUT, whitespace is a minefield of trouble (what you see is not necessarily what it appears to be). Hopefully, Python's parser now includes detection of "mixed whitespace" and will issue a warning when detected.

        Aside from "whitespace as syntax", Python syntax differs in other subtle ways that make it less comfortable for me than Perl.

Re: Writing a Perl extension framework for Inkscape
by bliako (Prior) on Jan 22, 2019 at 18:11 UTC
    AFAIK, Inkscape calls an executable called perl.exe without any parameter.

    regarding this, maybe you can cheat a little by writing a C-program (the only reason for this is that you compile it to an exe) which itself reads a configuration XML and passes whatever argv to the real perl interpreter (which you would have renamed realperl.exe or place your perl.exe first in the PATH) using whatever INC params specified in the XML.

    If you can write a perl script to do that but make it "perl.exe" that's even better though they may do exe-file-format checks for exe file.

    I can only sympathise with you as after years of using exclusively a Linux environment, a friend got me to setup her new PC and all I seemed to be spending my time on was to turn off privacy defaults exposing me to the world, unpin junk apps from menus and uninstall noisy (that's a new one) spyware showing off bog-standard aesthetics. On top of that she had to shell out about the equivalent of 4GB RAM for the pleasure of owning one of these, and pain me. It felt like I was in Shangri La for 10 years doing my origami and someone drag me back to the metropolis for an interview with the urination-district supermarket execs for a role of a night-shifter shelf-stacker, and I couldn't get a tie. If it was like I was going to school on my pants I would have known it was a bad dream. Alas... Top company in the world - that says it all.

    Edit: now that I am ranting: what impressed me most and in the most negative way was when I tried to change the default internet browser. The message was to the line of "Hey Edge is really cool, can you perhaps stick a bit longer with it?"

    bw, bliako

        if only I listened...

      I agree totally with your vision of Windows: they are more closed than opened!

      In the 80's we had a cartoon in France called "Les Shadoks" which was a caricature of our thinking mode, and their main motto was: "Pourquoi faire simple quand on peut faire compliqué ?" which would translate as something like "Why do it simple when you can do it complicated?". And that's absolutely what Windows® is: a gigantic nonsense.

        Just FYI, it is significantly older than the 1980s. I watched the first season of Les Shadoks as a teen back in 1968.
Re: Writing a Perl extension framework for Inkscape
by xiaoyafeng (Deacon) on Jan 23, 2019 at 04:25 UTC
    suggest you take a look Oracle. All Oracle database (on various platforms)shipped with a perl for doing some dirty work.




    I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

Re: Writing a Perl extension framework for Inkscape
by Anonymous Monk on Jan 23, 2019 at 10:18 UTC
    Nmake install doesnt work? Get detailed/exact.. If you want to work through any perl build its the only way. Also All Windows perls are portable. There is even a Portable module on cpan. See citrusperl and cavapackager for making installers and minimal distros (like ppsimple/PAR and scandeps on cpan

      Thanks for the links: I'll have a look...

      I finally got it install just by skipping 4 spurious test errors. Here is the result of "nmake test":

      nmake test ... Test Summary Report ------------------- ../cpan/File-Temp/t/mktemp.t (Wsta +t: 6400 Tests: 5 Failed: 0) Non-zero exit status: 25 Parse errors: Bad plan. You planned 9 tests but ran 5. ../ext/File-Find/t/find.t (Wsta +t: 3328 Tests: 125 Failed: 0) Non-zero exit status: 13 Parse errors: Bad plan. You planned 137 tests but ran 125. ../ext/IPC-Open3/t/IPC-Open3.t (Wsta +t: 0 Tests: 45 Failed: 0) TODO passed: 25 ../ext/XS-APItest/t/locale.t (Wsta +t: 2304 Tests: 2 Failed: 0) Non-zero exit status: 9 Parse errors: No plan found in TAP output Files=2666, Tests=1088273, 1731 wallclock secs (66.19 usr + 6.66 sys += 72.84 CPU) Result: FAIL NMAKE : fatal error U1077: '.\perl.exe' : code retour '0x3' Stop.

      And the detail of each failed test:

      ---------------------------------------------------------------- C:\Users\Moi\Perl5\perl5-5.28.1>perl cpan/File-Temp/t/mktemp.t 1..9 ok 1 # MKSTEMP: FH is GLOB(0x1d056f5d218) File is C:\Users\Moi\AppData\Loca +l\Temp\wowserdDJw fileno=3 ok 2 ok 3 ok 4 - woohoo # ok 5 # skip Skip test failed probably due to $TMPDIR being on NFS Label not found for "last SKIP" at C:/Users/Moi/Perl5/perl5-5.28.1/lib +/Test/More.pm line 1370, <$fh> line 1. # Looks like your test exited with 25 just after 5. ---------------------------------------------------------------- C:\Users\Moi\Perl5\perl5-5.28.1>perl ext/File-Find/t/find.t Can't locate Testing.pm in @INC (you may need to install the Testing m +odule) (@INC contains: ./t/lib C:/Users/Moi/Perl5/perl5-5.28.1/lib) a +t ext/File-Find/t/find.t line 41. BEGIN failed--compilation aborted at ext/File-Find/t/find.t line 41. ---------------------------------------------------------------- C:\Users\Moi\Perl5\perl5-5.28.1>perl ext/IPC-Open3/t/IPC-Open3.t ... not ok 24 - open3 of a non existent program fails with an exception in + the parent # TODO MSWin32 returns a pid and doesn't throw an excepti +on # Failed (TODO) test 'open3 of a non existent program fails with an +exception in the parent' # at ext/IPC-Open3/t/IPC-Open3.t line 157. # got: '' # expected: anything else ... ---------------------------------------------------------------- C:\Users\Moi\Perl5\perl5-5.28.1>perl ext/XS-APItest/t/locale.t Can't locate ../../t/test.pl at ext/XS-APItest/t/locale.t line 2. BEGIN failed--compilation aborted at ext/XS-APItest/t/locale.t line 4.

      It seems I can simply ignore those errors as two of them are related to missing test files (not in MANIFEST), one is about a coding error in a test and the last about some coding that should have been been done for Win32 but haven't been yet.

      But the infamous DLL hell starts as soon as I want to add some XS modules to it as Windows knowns nothing about standard libs like libxml, libintl, libzlib, libiconv and so on...

        But the infamous DLL hell starts as soon as I want to add some XS modules to it as Windows knowns nothing about standard libs like libxml, libintl, libzlib, libiconv and so on...

        ... which is why strawberry's portable zip comes so highly recommended: it includes the gcc toolchain appropriate for that version of perl, which does know about standard libs, and has those libraries in appropriate locations, so most XS modules "just install" without difficulty. Save yourself some pain: bundling portable strawberry, or having your install script just download the portable strawberry zip and unzipping it to the appropriate location, will be much simpler for you. :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1228810]
Approved by marto
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2021-02-26 06:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?